Skip to content

Import device diagnostics with a firmware version filename suffix#799

Merged
puddly merged 14 commits into
zigpy:devfrom
puddly:puddly/diagnostics-fw-version
Jun 25, 2026
Merged

Import device diagnostics with a firmware version filename suffix#799
puddly merged 14 commits into
zigpy:devfrom
puddly:puddly/diagnostics-fw-version

Conversation

@puddly

@puddly puddly commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

This PR appends the firmware version string to the diagnostics filename, allowing us to test version-gated quirks.

I built this PR in a specific way to ensure that the recent ZHA rewrite doesn't have any entity-level regressions:

  • All existing diagnostics have been re-imported from scratch with ZHA 1.4.1
  • All new (and old) diagnostics were imported with ZHA 1.4.1
  • dev was merged
  • Diagnostics were regenerated

The last step succeeded with just quirk_class renames.

Copilot AI review requested due to automatic review settings June 24, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.29%. Comparing base (063f18f) to head (66620ab).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #799   +/-   ##
=======================================
  Coverage   97.29%   97.29%           
=======================================
  Files          55       55           
  Lines       10934    10934           
=======================================
  Hits        10638    10638           
  Misses        296      296           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TheJulianJES TheJulianJES left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement!

Comment on lines +224 to +228
if attr_id_int in real_cluster.attributes:
real_cluster._attr_cache[attr_id_int] = parsed
else:
real_cluster._attr_cache.set_legacy_value(attr_id_int, parsed)
real_cluster.PLUGGED_ATTR_READS[attr_id_int] = parsed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log when we set legacy values? I think they should almost never be used these days (except for maybe the Aqara P1 quirk).

(In some future PR, maybe we can even have regeneration + diagnostics import print file name + what warnings occurred as a summary, but idk.)
(Also related issue of attr ID collisions: #798. I fear that we may deviate from real devices too much at some point)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few hundred 😓 66620ab (this PR)

@TheJulianJES TheJulianJES Jun 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... I guess we should look into what those unmapped attributes are 😅 (zigpy/zha-device-handlers#5120)

Comment on lines +354 to +358
if (
ha_data.get("last_seen") == "2026-03-04T18:21:39.038488+00:00"
) and (ha_data.get("model") == "J1 (5502)"):
_LOGGER.debug("Skipping known-bad DIY device")
continue

@TheJulianJES TheJulianJES Jun 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have some constant(s) for bad imports? But I guess we hopefully don't need to expand this list ever 😅

@zigpy-review-bot zigpy-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — test-infrastructure + test-data only.

No runtime zha/ code is touched (changes are confined to tools/ and tests/), so there's no entity-discovery or unique_id risk for existing users. I verified the snapshot diff matches the methodology in the description: 454 byte-identical renames (just the -0x… firmware-version suffix), 43 new fixtures, 0 deletions, and 12 content-modified files. The 12 modified ones are the devices that report no firmware version (so they keep their old filename); their unique_id churn is the deterministic faked IEEE (ieee_from_manufacturer_model) changing on re-import, not a discovery regression. CI is green across 3.12/3.13/3.14 and the affected test_discover/test_alarm_control_panel/test_select/test_switch suites pass locally (890 tests).

Two optional notes on the import tool inline — neither blocks.

Non-blocking, and out of scope here: tests/test_inovelli.py.bak is tracked and carries stale references, but it's pre-existing (from #762) and .bak isn't collected by pytest, so it's inert. Might be worth a git rm in a separate cleanup.

Comment thread tools/import_diagnostics.py Outdated
app=zha_gateway.application_controller,
device_data=data,
)
except Exception:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: this except Exception: makes the loader-dispatch swallow real failures. Since native device fixtures have no home_assistant key, a native-format input that fails to parse for a genuine reason hits this branch, matches "home_assistant" not in data, and is skipped with the misleading "Skipping, missing 'home_assistant' key" debug line — the original error is lost.

Cleaner would be to dispatch on the input shape up front (home_assistant key present → HA-diagnostics loader; absent → native loader) so there's no broad except at all. At minimum, log the caught exception (_LOGGER.debug("modern parse failed for %s", path, exc_info=True)) before falling back.

continue
ha_data = data["home_assistant"].get("data", {})
if (
ha_data.get("last_seen") == "2026-03-04T18:21:39.038488+00:00"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: skipping the known-bad device by a hardcoded last_seen timestamp + "J1 (5502)" model is brittle. A one-line comment on why this device fails to import would help whoever trips over it next.

@puddly puddly force-pushed the puddly/diagnostics-fw-version branch from 66620ab to 8bda80b Compare June 25, 2026 20:46
@puddly puddly enabled auto-merge (squash) June 25, 2026 20:46
@puddly puddly merged commit ad33982 into zigpy:dev Jun 25, 2026
8 checks passed
@puddly puddly deleted the puddly/diagnostics-fw-version branch June 25, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants