Skip to content
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

Add flow volume sensor entity for the FlowMeasurement cluster #187

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

benbancroft
Copy link

Proposed change

Adds a new "volume flow rate" sensor for discovered FlowMeasurement clusters. This is required for the Sonoff SWV-BSP Smart Water Valve, but likely other devices with FlowMeasurement being a standardised Zigbee cluster.

Raw value of "measured_value" is 10 * flow_rate, as per Zigbee cluster specification for FlowMeasurement.

This feature was requested as part of zigpy/zha-device-handlers#3298

Testing

I have tested this with my Sonoff SWV-BSP Smart Water Valve and the sensor is appearing and being exported to Home Assistant no issues with a sane value that matches the flow of water. I have not tested this with any other device that implements FlowMeasurement cluster, but I assume it should work fine.
Screenshot 2024-08-30 151759

@@ -69,6 +69,7 @@
CLUSTER_HANDLER_PRESSURE,
CLUSTER_HANDLER_SMARTENERGY_METERING,
CLUSTER_HANDLER_SOIL_MOISTURE,
CLUSTER_HANDLER_FLOW_MEASUREMENT,
Copy link

Choose a reason for hiding this comment

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

these appear to be otherwise alphabetized

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. Hopefully resolved in latest commit (plus other places I'd not stuck to alphabetical order). I also dropped _MEASUREMENT for consistency with other clusters/sensors (e.g. TemperatureMeasurement is called CLUSTER_HANDLER_TEMPERATURE).

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 96.39%. Comparing base (57cc44b) to head (ec3d7bc).
Report is 20 commits behind head on dev.

Files with missing lines Patch % Lines
zha/application/platforms/sensor/__init__.py 72.72% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #187      +/-   ##
==========================================
+ Coverage   95.89%   96.39%   +0.49%     
==========================================
  Files          61       61              
  Lines        9404     9402       -2     
==========================================
+ Hits         9018     9063      +45     
+ Misses        386      339      -47     

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

@fgsch
Copy link

fgsch commented Sep 2, 2024

This is great!

Is there anything we can do to get this reviewed and merged?

@dmulcahey
Copy link
Contributor

dmulcahey commented Sep 2, 2024

image

image

If we are going to implement this we should add the other 3 attributes to the ZCL init attrs on the cluster handler. Also, take note that a measured value of 0xffff means the measurement is unknown and the note from 4.1.3 about how the min and max affect the readings of measured value.

@dmulcahey
Copy link
Contributor

@benbancroft bumping this... can you make the small tweaks from my comment above?

@benbancroft
Copy link
Author

Hi @dmulcahey

I've not had the time to address this yet unfortunately - had family over this weekend.
Agree with your comment regarding implementation of cluster constraints. I plan to have a go at addressing this soon (hopefully later this week).

Question: where would you recommend implementing these checks? Are there other examples of where other clusters do similar I can reference?

@dmulcahey
Copy link
Contributor

dmulcahey commented Sep 10, 2024

Hi @dmulcahey

I've not had the time to address this yet unfortunately - had family over this weekend. Agree with your comment regarding implementation of cluster constraints. I plan to have a go at addressing this soon (hopefully later this week).

Question: where would you recommend implementing these checks? Are there other examples of where other clusters do similar I can reference?

I know illuminance does something like this in the formatter:

def formatter(self, value: int) -> int | None:
"""Convert illumination data."""
if value == 0:
return 0
if value == 0xFFFF:
return None
return round(pow(10, ((value - 1) / 10000)))

@benbancroft
Copy link
Author

Hi @dmulcahey

Thanks! I've gone ahead and implemented the 0xffff unknown state in the same way via a formatter.

Regarding MinMeasuredValue and MaxMeasuredValue - I've left this as is for now as this looks like a wider issue throughout most other sensors within ZHA (e.g. Temperature Measurement cluster).

I guess strictly speaking, we can largely place trust in the server that it is implementing these constraints for the measured values it reports. The only real use on the client side is enforcing this relationship, or utilising min/max for display of data (e.g. rendering a sliding display). For the latter, as this sensor is exported as a numerical to Home Assistant, it doesn't apply here.

Please let me know your thoughts/suggestions here.

@TheJulianJES TheJulianJES added the entities Issue or PR about (custom) entities label Sep 24, 2024
@fgsch
Copy link

fgsch commented Oct 9, 2024

Can someone review and merge this if it looks OK? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
entities Issue or PR about (custom) entities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants