-
Notifications
You must be signed in to change notification settings - Fork 672
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 quirk for Sonoff SWV Smart Water Valve #3340
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #3340 +/- ##
==========================================
+ Coverage 88.48% 88.50% +0.01%
==========================================
Files 305 306 +1
Lines 9623 9646 +23
==========================================
+ Hits 8515 8537 +22
- Misses 1108 1109 +1 ☔ View full report in Codecov by Sentry. |
4be7627
to
79bfbfe
Compare
for more information, see https://pre-commit.ci
|
||
Water_Shortage = 0x1 | ||
Water_Leakage = 0x2 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want Normal (0) and probably Leakage and Shortage (3).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the absence of Normal (0) and Leakage and Shortage (3) was intentional - if you look at class you will see that this is a bitfield not an enum. Leakage and Shortage (3) would just be Water_Shortage (1) & Water_Leakage (2)
If you look what I've done in ZHR PR (zigpy/zha#189), I'm actually exporting two binary sensors, one for each bit. I personally think this is a lot nicer than how they did it in Zigbee2MQTT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, I missed the bitmap8.
Two related comments:
- The docstrings say enum :)
- While this is fine for the sensor, the other part is the response when reading the attribute directly via Manage Zigbee Device interface. This is not a big issue, but it'd be nice to have the full range of values IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, is there any reason you cannot use an enum here and check for the specific values on the other PR?
|
||
cluster_id = SONOFF_CLUSTER_FC11_ID | ||
ep_attribute = "sonoff_manufacturer" | ||
attributes = {ATTR_SONOFF_VALVE_STATUS: ("valve_status", ValveStatusBitmap, False)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe attributes are deprecated. It might be better to use ZCLAttributeDef
to define this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - I based this off the other Sonoff quirk, with no prior experience writing quirks. Let me look into ZCLAttributeDef
and see how easy it is to convert over.
Nice! I was testing a similar change using the Quirks Builder v2 and exposing the state as a sensor. I'll probably open a PR on Monday, as I wrote most of the code already, but I've left some comments in this PR. |
Hi @fgsch Thanks for your review comments, much appreciated! Given you've gone to the work of writing yours, I would definetly push it up. I wasn't aware of Quirks Builder v2 (with this being my first quirk), but looking at API it looks very nice and I guess it allows you to avoid a ZHA change also? What might be a pain is exporting two not one sensors like I have (which in my personal opinion makes more sense for these sensors). |
My original plan was to expose the valve status as a sensor, but I've been struggling to do so as I envisioned. As for my PR, I sort of ran out of time today. I will try to do it tomorrow. |
And finally, here's my PR: #3346 I managed to get the sensor working as I wanted with help from some devs in discord. Unfortunately, it is not yet possible to do the same with binary sensors. |
Proposed change
Adds support for Sonoff SWV Smart Water Valve custom cluster, which exposes a new attribute called valve_status for querying if the valve is leaking or if the water supply to the valve has stopped.
Code should hopefully should be self explanatory, the only complication is the overridden
_is_manuf_specific()
property inSonoffFC11Cluster
class. This is required, as if the device receives an attribute read or notify zigbee command which has manufacturer_specific = True set (default if cluster's ID is within manufacturer specific range which this is), it will returnUNSUPPORTED_ATTRIBUTE
.This feature was requested as part of #3298
Additional information
Checklist
pre-commit
checks pass / the code has been formatted using Black