-
Notifications
You must be signed in to change notification settings - Fork 788
Refactor Aqara Roller Driver E1 as v2 quirk for more entities #3686
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
Refactor Aqara Roller Driver E1 as v2 quirk for more entities #3686
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #3686 +/- ##
==========================================
+ Coverage 91.13% 91.17% +0.03%
==========================================
Files 334 334
Lines 10796 10856 +60
==========================================
+ Hits 9839 9898 +59
- Misses 957 958 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Have identified an issue with the cover state not reliably changing to open/closed. Investigating this currently. |
Edit: zigpy/zha#376 now raised to address the below. @TheJulianJES, @dmulcahey looking at the code in https://github.com/zigpy/zha/blob/dev/zha/application/platforms/cover/__init__.py
There was a PR against the old core ZHA repo to try and address this but that looks abandoned home-assistant/core#105467 I've tested the following scenarios: 1. go_to_lift_percentage has never been called, down_close is called, then the device reports position_or_tilt of 0 2. go_to_lift_percentage has never been called, up_open is called, then the device reports position_or_tilt of 100 3. go_to_lift_percentage is called (go to 0), then the device reports position_or_tilt of 0 4. go_to_lift_percentage is called (go to 100), then the device reports position_or_tilt of 100 5. go_to_lift_percentage is called (go to 50), then the device reports position_or_tilt of 50 6. go_to_lift_percentage has previously been called (stored value is 50), down_close is called, then the device reports position_or_tilt of 0 7. go_to_lift_percentage has previously been called (stored value is 50), up_open is called, then the device reports position_or_tilt of 100 8. go_to_lift_percentage has previously been called (stored value is 50) and current position is 100, stop is called I'd suggest we can handle this in one of 3 ways:
Below is the current function for reference:
|
I've been working on changes to the ZHA cover entity hander to address the underlying status issue outlined above (it also affects the existing v1 quirk code for this and other devices). I'll raise a bug and PR to address these over the weekend, current WIP code here: |
6e88fde
to
fb55985
Compare
@TheJulianJES if I'm reading zigpy/zigpy#1540 I believe I should be able to use the proposed If so I'll remove the custom converter I've implemented in this quirk once your PR is merged. |
@TheJulianJES the Right now ZHA exposes this as a separate number entity in addition to the cover entity. When adding custom entities in a v2 quirk we're able to mark them as disabled by default, do you think it would be beneficial to extend this to regular cluster attributes? Critically this would be different to entirely removing the cluster/marking an attribute as unsupported in the cluster, since we'd still want to remap attribute updates/writes from the cover commands to the cluster. |
With zigpy/zigpy#1535, that should be allowed in the future. Do note that the ZHA part wasn't PR'd yet, so it won't do anything for now. |
defc02d
to
c4135cd
Compare
- Refactor into v2 quirk - Refactor clusters to use AttributeDefs format - Represent the device as a Rollershade rather than Drapery - Refresh current position after a stop command is issued - Expose attributes as entities: - Motor speed (select) - Charging status (binary sensor) - Calibration status (binary sensor) - Reads to current_position_lift_percentage are redirected to AnalogOutput present_value - Writes to AnalogOutput present_value from go_to_lift_percentage commands do not prematurely update the current_position_lift_percentage
The AnalogOutput cluster is used to write target position to the device. The present_value reported/read provides the current position/starting position when the device is in motion. Both of these functions are re-mapped into the ZCL WindowCovering cluster, so the number entity created is redundant. This also pre-emptively hides the MultistateOutput cluster, though there is currently no cluster handler implemented for this. Apply pre-commit auto fixes
Depends on the following PRs: - zigpy/zigpy#1540 - zigpy/zha#360
The `MultistateOutput: present value` only ever reports the last written command (even if the device has since stopped/changed direction).
35d2776
to
7ac94ef
Compare
@TheJulianJES I think this should be ready for merging, I'll raise a PR for the zha cover status issue outlined in #3686 (comment) separately (it's not a pre-req for this change). |
.prevent_default_entity_creation( | ||
endpoint_id=1, cluster_id=MultistateOutput.cluster_id | ||
) | ||
.removes(OnOff.cluster_id) |
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.
For this use case, why remove the cluster entirely? I'm hoping to replace uses of removes
with prevent_default_entity_creation
.
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.
As far as I can tell this cluster is non-functional.
Interacting with the switch results in an error, so there would be no benefit exposing it.
If it's an optional entity a user might be tempted to enable it and raise a bug report that the switch doesn't work.
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 removes(OnOff.cluster_id)
can be replaced with prevent_default_entity_creation(cluster_id=OnOff.cluster_id)
. Removing the cluster prevent prevents automatic entity discovery, which is more explicit with prevent_default_entity_creation
and would allow you to still interact with the OnOff
cluster via cluster commands if necessary.
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'd usually agree, but the device itself is responding with the below error to any command to OnOff:
Failed to perform the action zha/issue_zigbee_cluster_command. Failed to issue cluster command with status: <Status.UNSUPPORTED_CLUSTER: 195>
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.
@puddly if we're planning to deprecate removes
then happy to change this to use prevent_default_entity_creation
.
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've updated the PR to use prevent_default_entity_creation
872442a
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.
Hi @puddly, did you have any other feedback on these changes?
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.
Not at the moment, sorry. The above method depends on zigpy/zha#365 to be finished and there were a few hiccups getting it merged.
…tion_lift_percentage updates
I've now raised zigpy/zha#376 to address the ZHA logic issues I outlined in #3686 (comment). |
Per @puddly 's recommendation in zigpy#3686 (comment)
b6909c5
to
9e5b67a
Compare
The current_position_lift_percentage now is read prior to returning command responses to ensure that ZHA has the correct position during changes in direction/stopping. Apply pre-commit auto fixes and fix tests.
1138ed4
to
d342b64
Compare
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.
Not sure if I'm a huge fan of the is_write
/WriteAwareUpdateAttribute
stuff and RedirectAttributes
(we do need a good way of doing this in general), but it seems to look fine. Since the ZHA PR is in, we should probably get this in as well.
I'm assuming that you have tested it quite a bit. Unfortunately, I don't have any cover devices, so unable to test anything. Again, looks fine, so I'll quickly correct the two small things I noted and get it in for the beta tomorrow. If there are any huge issues, we can always fix them during the beta or revert if necessary.
attribute_converter=lambda x: True | ||
if x == AqaraRollerDriverCharging.true | ||
else 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.
attribute_converter=lambda x: True | |
if x == AqaraRollerDriverCharging.true | |
else False, | |
attribute_converter=lambda x: x == AqaraRollerDriverCharging.true, |
true = 0x01 | ||
false = 0x02 |
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.
This should really be (upper-case) True
and False
, but that would conflict.
Maybe something like Charging
and Unplugged
? (assuming "not charging" => "unplugged").
Technically, we don't even need this at all, as we could just parse x == 1
for the charging binary sensor and have no enum.
Proposed change
This PR refactors the existing Aqara Roller Driver E1 quirk into the new v2 structure to expose the configuration and status attributes, below is a summary of changes:
AnalogOutput: present_value
(current position) are replicated intoWindowCovering: current_position_lift_percentage
AnalogOutput: present_value
(go to position) do not update theWindowCovering: current_position_lift_percentage
WindowCovering: current_position_lift_percentage
are redirected toAnalogOutput: present_value
up_open
,down_close
,stop
are handled byMultistateOutput: present_value
go_to_lift_percentage
value is written toAnalogOutput: present_value
current_position_lift_percentage
is read prior to returning command response, this ensures the correct state is shown following a change in directionFunctional enhancements
Additional information
Depends on the following PRs for binary_sensor value conversion:
attribute_converter
to quirks v2 sensors zigpy#1540attribute_converter
zha#360Depends on the following PR for disabling the redundant entities:
Associated PRs:
Whilst I've validated that is works with my own E1 roller shade devices, I'd like to ensure other users do not encounter any regressions with this refactor.
@dmulcahey / @schwickster / @javicalle / @badrpc / @TheJulianJES I can see in the past you've previously contributed for this device, if you still use it would you mind checking if this updated quirk works as expected without introducing regressions?
Checklist
pre-commit
checks pass / the code has been formatted using Black