refactor(devices): store hardware identity as hw_family / hw_revision

The firmware moved its NVS identity keys from hw_type / hw_version to
hw_family / hw_revision (NvsMigration.cpp), and the NVS generator, cloudflash
and the device models already used the new names. Firestore device docs and
the manufacturing code still wrote and read hw_type / hw_version, so the
device API's hw_family / hw_revision were always "" (0 of 14 docs had them)
and the console used two names for one value.

Device docs now use the firmware's names (schema v1.1.0, decision D2 in the
bellsystems-schema repo). The apps don't read these fields, so no app change.

- Manufacturing batch-create writes hw_family / hw_revision; the inventory
  API exposes hw_family / hw_revision (filters: ?hw_family= / ?hw_families=).
  Reads fall back to hw_type / hw_version so docs not yet migrated still work.
- devices/firestore_v1.py renames hw_type / hw_version on read and write and
  rejects a hw_family that isn't a code (e.g. "Bell Plus"): when the console
  generates NVS from it, the firmware builds its OTA URL from that value.
- Inventory, provisioning, onboarding and overview pages use the new names.

Unchanged on purpose: the firmware catalog and flash assets
(/api/firmware/{hw_type}/..., hw_type_override) — a separate store and the
URL devices call; same values, only the variable name differs. The public
cloudflash response keeps its hw_type field (public contract).

Data migration (rename + fix 3 display-label values) runs from the
bellsystems-schema repo AFTER this is deployed: the currently deployed
console still reads hw_type.

Verified: 118 backend tests pass; frontend builds; ESLint errors in
ProvisioningWizard.jsx (7) are pre-existing and unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 21:02:20 +02:00
co-authored by Claude Opus 5.5
parent 5ab87fa9f0
commit 2e3d7ba062
11 changed files with 79 additions and 57 deletions
+3 -3
View File
@@ -89,8 +89,8 @@ class DeviceUserSummary(BaseModel):
class DeviceInventoryItem(BaseModel):
id: str
serial_number: str
hw_type: str
hw_version: str
hw_family: str # board family code (BoardType value or bespoke UID) = firmware NVS "hw_family"
hw_revision: str # hardware revision, e.g. "1.0" = firmware NVS "hw_revision"
mfg_status: str
mfg_batch_id: Optional[str] = None
created_at: Optional[str] = None
@@ -134,7 +134,7 @@ class CustomerSearchResult(BaseModel):
class RecentActivityItem(BaseModel):
serial_number: str
hw_type: str
hw_family: str
mfg_status: str
owner: Optional[str] = None
updated_at: Optional[str] = None
+6 -6
View File
@@ -71,8 +71,8 @@ async def create_batch(
@router.get("/devices", response_model=DeviceInventoryListResponse)
def list_devices(
status: Optional[str] = Query(None),
hw_type: Optional[str] = Query(None),
hw_types: Optional[list[str]] = Query(None, description="Multi-select board type filter — repeat param, e.g. ?hw_types=vesper&hw_types=chronos"),
hw_family: Optional[str] = Query(None),
hw_families: Optional[list[str]] = Query(None, description="Multi-select board family filter — repeat param, e.g. ?hw_families=vesper&hw_families=chronos"),
has_users: Optional[bool] = Query(None, description="Filter by whether the device has any app users assigned"),
search: Optional[str] = Query(None),
limit: int = Query(100, ge=1, le=500),
@@ -81,8 +81,8 @@ def list_devices(
):
items = service.list_devices(
status=status,
hw_type=hw_type,
hw_types=hw_types,
hw_family=hw_family,
hw_families=hw_families,
has_users=has_users,
search=search,
limit=limit,
@@ -605,7 +605,7 @@ def download_bootloader(
):
"""Return the bootloader.bin for this device's hw_type (flashed at 0x1000)."""
item = service.get_device_by_sn(sn)
hw_type = hw_type_override or item.hw_type
hw_type = hw_type_override or item.hw_family
try:
data = service.get_flash_asset(hw_type, "bootloader.bin")
except NotFoundError as e:
@@ -625,7 +625,7 @@ def download_partitions(
):
"""Return the partitions.bin for this device's hw_type (flashed at 0x8000)."""
item = service.get_device_by_sn(sn)
hw_type = hw_type_override or item.hw_type
hw_type = hw_type_override or item.hw_family
try:
data = service.get_flash_asset(hw_type, "partitions.bin")
except NotFoundError as e:
+18 -17
View File
@@ -66,8 +66,9 @@ def _doc_to_inventory_item(doc, customer_names: dict | None = None, user_infos:
return DeviceInventoryItem(
id=doc.id,
serial_number=data.get("serial_number", ""),
hw_type=data.get("hw_type", ""),
hw_version=data.get("hw_version", ""),
# hw_type / hw_version: names used before 2026-11-08 (kept as read fallback)
hw_family=data.get("hw_family") or data.get("hw_type", ""),
hw_revision=data.get("hw_revision") or data.get("hw_version", ""),
mfg_status=data.get("mfg_status", "manufactured"),
mfg_batch_id=data.get("mfg_batch_id"),
created_at=created_str,
@@ -136,8 +137,9 @@ def create_batch(data: BatchCreate) -> BatchResponse:
"serial_number": sn,
"device_id": sn, # schema v1 / D1: both apps connect over MQTT with device_id
"hw_type": data.board_type.value,
"hw_version": data.board_version,
# Same names as the firmware NVS keys.
"hw_family": data.board_type.value,
"hw_revision": data.board_version,
"mfg_status": "manufactured",
"mfg_batch_id": batch_id,
"created_at": now,
@@ -170,8 +172,8 @@ def create_batch(data: BatchCreate) -> BatchResponse:
def list_devices(
status: str | None = None,
hw_type: str | None = None,
hw_types: list[str] | None = None,
hw_family: str | None = None,
hw_families: list[str] | None = None,
has_users: bool | None = None,
search: str | None = None,
limit: int = 100,
@@ -182,15 +184,15 @@ def list_devices(
if status:
query = query.where("mfg_status", "==", status)
if hw_type:
query = query.where("hw_type", "==", hw_type)
if hw_family:
query = query.where("hw_family", "==", hw_family)
docs = list(query.stream())
docs_data = [doc.to_dict() or {} for doc in docs]
if hw_types:
hw_type_set = set(hw_types)
keep = [i for i, d in enumerate(docs_data) if d.get("hw_type") in hw_type_set]
if hw_families:
family_set = set(hw_families)
keep = [i for i, d in enumerate(docs_data) if d.get("hw_family") in family_set]
docs = [docs[i] for i in keep]
docs_data = [docs_data[i] for i in keep]
@@ -274,8 +276,8 @@ def get_nvs_binary(sn: str, hw_type_override: str | None = None, hw_revision_ove
item = get_device_by_sn(sn)
return generate_nvs_binary(
serial_number=item.serial_number,
hw_family=hw_type_override if hw_type_override else item.hw_type,
hw_revision=hw_revision_override if hw_revision_override else item.hw_version,
hw_family=hw_type_override if hw_type_override else item.hw_family,
hw_revision=hw_revision_override if hw_revision_override else item.hw_revision,
legacy=legacy,
)
@@ -333,7 +335,7 @@ def assign_device(sn: str, data: DeviceAssign) -> DeviceInventoryItem:
for item in owned_items
)
if not already_assigned:
device_name = doc_data.get("device_name") or BOARD_TYPE_LABELS.get(doc_data.get("hw_type", ""), sn)
device_name = doc_data.get("device_name") or BOARD_TYPE_LABELS.get(doc_data.get("hw_family") or doc_data.get("hw_type", ""), sn)
owned_items.append({
"type": "console_device",
"console_device": {
@@ -403,7 +405,7 @@ def get_stats() -> ManufacturingStats:
activity_candidates.append(RecentActivityItem(
serial_number=data.get("serial_number", ""),
hw_type=data.get("hw_type", ""),
hw_family=data.get("hw_family") or data.get("hw_type", ""),
mfg_status=status,
owner=data.get("owner"),
updated_at=ts_str,
@@ -563,7 +565,6 @@ def get_firmware_url(sn: str) -> str:
"""Return the FastAPI download URL for the latest stable firmware for this device's hw_type."""
from firmware.service import get_latest
item = get_device_by_sn(sn)
hw_type = item.hw_type.lower()
latest = get_latest(hw_type, "stable")
latest = get_latest(item.hw_family.lower(), "stable")
# download_url is a relative path like /api/firmware/vs/stable/1.4.2/firmware.bin
return latest.download_url