Skip to content

Add OTA last query cmd to diagnostics#727

Merged
TheJulianJES merged 3 commits intozigpy:devfrom
TheJulianJES:tjj/diagnostics_last_query_cmd
Mar 25, 2026
Merged

Add OTA last query cmd to diagnostics#727
TheJulianJES merged 3 commits intozigpy:devfrom
TheJulianJES:tjj/diagnostics_last_query_cmd

Conversation

@TheJulianJES
Copy link
Copy Markdown
Contributor

Proposed change

This adds the last cached OTA query command to JSON diagnostics, so we know the image_type of a device.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.63%. Comparing base (f721c73) to head (ded4911).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #727   +/-   ##
=======================================
  Coverage   97.63%   97.63%           
=======================================
  Files          62       62           
  Lines       10814    10814           
=======================================
  Hits        10558    10558           
  Misses        256      256           

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds OTA cluster “last cached query” details to the ZHA device diagnostics JSON so diagnostics can reveal a device’s OTA image_type (and related fields) when available.

Changes:

  • Extend Device.get_diagnostics_json() to include last_query_cmd for OTA out clusters when present.
  • Add tests verifying diagnostics includes last_query_cmd for OTA clusters and omits it when unset.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
zha/zigbee/device.py Emits OTA last_query_cmd details in per-endpoint out_clusters diagnostics output when cached.
tests/test_discover.py Adds coverage for presence/absence of last_query_cmd in diagnostics for the OTA cluster.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1632 to +1634
if isinstance(cluster, Ota)
and getattr(cluster, "last_query_cmd", None) is not None
else {}
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.

The getattr guard is for someone messing up a (quirked) OTA cluster badly, but I think we can just remove it. If someone manages this, congrats.

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.

Eh, actually. We need a is not None check anyway, so I guess we can just keep this. It's one line either way.

Comment on lines +810 to +816
ota_cluster = zigpy_device.endpoints[1].out_clusters[Ota.cluster_id]
ota_cluster.last_query_cmd = QueryNextImageCommand(
field_control=0,
manufacturer_code=0x117C,
image_type=0x1234,
current_file_version=0x00AABBCC,
)
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.

Side note: In the future, we may wanna consider if we can also restore from diagnostics files to our device object generated from it, so the last_query_cmd is available on it then.

@TheJulianJES TheJulianJES marked this pull request as ready for review March 25, 2026 03:39
@TheJulianJES TheJulianJES merged commit 34b471d into zigpy:dev Mar 25, 2026
7 checks passed
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.

2 participants