Skip to content

Ignore "non-value" attribute values for sensors #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 16, 2025

Conversation

puddly
Copy link
Contributor

@puddly puddly commented Apr 10, 2025

Zigpy currently provides a way to determine if a value is a "non-value" for a type. This is easily supported for numeric types but not so much for more complex ones, like arrays and such. This PR will globally fix invalid sensor readings showing up in the frontend.

home-assistant/core#96894

Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.70%. Comparing base (9620f59) to head (7a5cad5).
Report is 2 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #414   +/-   ##
=======================================
  Coverage   96.70%   96.70%           
=======================================
  Files          61       61           
  Lines        9863     9874   +11     
=======================================
+ Hits         9538     9549   +11     
  Misses        325      325           

☔ 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.

@oddlama
Copy link

oddlama commented Apr 13, 2025

Since this is a draft, can I use this to patch my local instance and test it, or do you consider it work in progress?

@puddly
Copy link
Contributor Author

puddly commented Apr 13, 2025

Sure! I haven't written unit tests for it but have tested it at runtime with a device.

@oddlama
Copy link

oddlama commented Apr 14, 2025

I just tested this with my own custom zigbee device, and I can confirm that this fixes the issue completely! Thank you very much @puddly ! And the sensor correctly reports as "Unknown" while we send the unknown value :D

This is how the mock sensor values look like (it cycles between two modes, first stepdown from 20° -> -20°, then an unknown value for the same time):

image

@puddly
Copy link
Contributor Author

puddly commented Apr 14, 2025

Thanks for the confirmation!

@puddly puddly marked this pull request as ready for review April 15, 2025 22:25
@puddly puddly force-pushed the puddly/ignore-non-values branch from 4d9b897 to 610923f Compare April 15, 2025 22:25
@@ -173,6 +174,13 @@ def __init__(
) -> None:
"""Init this sensor."""
self._cluster_handler: ClusterHandler = cluster_handlers[0]
self._attr_def: foundation.ZCLAttributeDef | None = None

if self._attribute_name is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wanted to, could use if (attr := self._attribute_name) is not None: to just access attr for the name below, but this is obviously also fine.

@puddly puddly merged commit 5ed0dbf into zigpy:dev Apr 16, 2025
9 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.

None yet

3 participants