-
Notifications
You must be signed in to change notification settings - Fork 727
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 Aqara FP1E presence sensor v2 quirk #3521
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #3521 +/- ##
==========================================
+ Coverage 89.67% 89.71% +0.04%
==========================================
Files 316 317 +1
Lines 10281 10324 +43
==========================================
+ Hits 9219 9262 +43
Misses 1062 1062 ☔ View full report in Codecov by Sentry. |
Hi @dmulcahey, do you have any feedback on the current implementation with regards to quirk v2 conventions? |
.adds(DeviceTemperature) | ||
.adds(OccupancySensing) | ||
.adds( | ||
IasZone, | ||
constant_attributes={ | ||
IasZone.AttributeDefs.zone_type: IasZone.ZoneType.Motion_Sensor | ||
}, | ||
) |
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.
If these clusters are completely virtual/fake (not present on the device), we'd probably want them to be a LocalDataCluster
. E.g.:
class IasZoneLocal(LocalDataCluster, IasZone):
"""Virtual cluster for IasZone."""
# required to make sure ZHA creates sensors when initially pairing
_VALID_ATTRIBUTES = {IasZone.AttributeDefs.zone_status.id}
_VALID_ATTRIBUTES
is probably required to make sure that ZHA creates the sensors when the device is initially paired (so completely removed from ZHA before pairing again), even when there's no initial data in the zigpy DB (which there is not, as the attribute cannot be read on pairing).
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.
It might be a good idea for us to provide a shorthand v2 quirk method for this. But that does't exist yet..
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.
It might be a good idea for us to provide a shorthand v2 quirk method for this. But that does't exist yet..
Yes I think that would be a great addition, in the meantime I've updated the quirk to use Local clusters for motion and occupancy.
Move attribute IDs into the AttributeDefs and ensure that OccupancySensing and IasZone are correctly handled as local virtual clusters.
UnitOfLength.METERS for distance entities (zigpy/zha#307) EntityType.DIAGNOSTIC for restart device button (zigpy/zha#308)
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 looks very good.
I'll make a small change regarding the constant_attributes
. There's more info in the two comments. Otherwise, this should be good to go.
I've also added a small test to cover the |
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 be good to go IMO. Thanks, @jeverley!
Thanks for adding these, I was still wrapping my head around how best to introduce a v2 quirk amongst the other xiaomi motion devices.
Therefore the parameters should be (if I'm understanding the test syntax correctly):
Will add a commit reflecting this shortly. Edit: I see you already corrected the flipped occupied/unoccupied values in 45c49fc, still good to capture the 3rd scenario of occupied with no movement. |
class IasZoneLocal(LocalDataCluster, IasZone): | ||
"""Virtual cluster for IasZone.""" | ||
|
||
_CONSTANT_ATTRIBUTES = { | ||
IasZone.AttributeDefs.zone_type.id: IasZone.ZoneType.Motion_Sensor | ||
} | ||
_VALID_ATTRIBUTES = {IasZone.AttributeDefs.zone_status.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.
Note for other reviewers: We need a virtual cluster for IasZone
here, as we need a virtual attribute for "motion". The Xiaomi motion
attribute needs to be parsed in a way that we can't yet do with quirks v2.
Also, for motion/occupancy, it makes sense to use the integrated entities in ZHA IMO. We'd have to duplicate "motion" and "occupancy" quirk entities with all properties everywhere otherwise.
We already use virtual clusters in a lot of quirks and they'll always be needed for some (especially for Tuya and some Xiaomi devices), unless we have some kind of other structure we can map attributes to (like Z2M does).
Looks like Codecov is broken across all repos again. This PR is fully covered. |
Proposed change
This quirk adds support for the Aqara FP1E presence sensor, exposing its motion and occupancy sensors in addition to its configuration parameters.
Fixes #3294 and is written using the quirks v2 format.
Additional information
There are two issues that we'd ideally want to fix before merging this PR.
Checklist
pre-commit
checks pass / the code has been formatted using Black