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
+10 -1
View File
@@ -39,7 +39,8 @@ IP_KEYS = {"ipAddress", "gateway", "subnet", "dns1", "dns2"}
# Misspelled key -> v1 key, per nested map. A value of None means "drop".
LEGACY_KEYS: dict[str, dict[str, str | None]] = {
"": {"users_list": None},
# hw_type / hw_version: pre-2026-11-08 names; the firmware NVS uses hw_family / hw_revision.
"": {"users_list": None, "hw_type": "hw_family", "hw_version": "hw_revision"},
"device_attributes": {"bellGuardSafetyOn": "bellguardSafetyOn"},
"device_attributes.networkSettings": {"useStaticIP": "usesStaticIP"},
}
@@ -51,6 +52,10 @@ _MELODY_ITEM_FORBIDDEN = {"information", "default_settings", "url"}
# Still accepted on write so a browser tab opened before the deploy can't corrupt data.
_LEGACY_DISPLAY_FMT = "%d %B %Y at %H:%M:%S UTC%z"
# Board family code: a BoardType value ("vesper_plus") or a bespoke UID. Never a display
# label like "Bell Plus" — the firmware builds its OTA URL from this value.
_HW_FAMILY = re.compile(r"^[a-z0-9][a-z0-9_-]*$")
_IPV4 = re.compile(r"^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$")
@@ -163,6 +168,10 @@ def to_firestore(data: dict, db=None) -> dict:
if sn or did:
out["serial_number"] = out["device_id"] = sn or did
fam = out.get("hw_family")
if fam not in (None, "") and not (isinstance(fam, str) and _HW_FAMILY.match(fam)):
raise ValidationError(f"hw_family: expected a board family code like \"vesper_plus\", got {fam!r}")
if "user_list" in out and db is not None:
refs, seen = [], set()
for e in out["user_list"] or []: