-
Notifications
You must be signed in to change notification settings - Fork 908
Add support for Aqara external temperature sensor #3974
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
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #3974 +/- ##
==========================================
+ Coverage 91.04% 91.33% +0.28%
==========================================
Files 331 339 +8
Lines 10698 11029 +331
==========================================
+ Hits 9740 10073 +333
+ Misses 958 956 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…r' into aqara_external_temperature_sensor
TheJulianJES
left a comment
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 for adding the tests. I think this looks pretty good already.
| SENSOR_TEMP: ("sensor_temp", t.uint32_t, True), | ||
| SENSOR_ATTR: (SENSOR_ATTR_NAME, t.LVBytes, True), |
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.
All these attributes should really be converted to the new zigpy AttributeDefs style. Search AttributeDefs in this repo or the zigpy repo for examples.
You don't have to do it in this PR, but it would be nice.
We can also access the name and id then: AqaraThermostatSpecificCluster.AttributeDefs.sensor_temp.name or .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.
I hear you but I honestly don't have much time to spend on this PR atm and multiple people have been emailing me to track progress on this change since it's a highly requested feature for the quirk.
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 is quite some time ago. I would like to help in this case.
I found that this PR is not up to date with the upstream.
In the upstream I see that the AttributeDefs are already defined.
So it is, I believe, straight forward to do this change.
Unfortunately, I don't know how I can collaborate on this PR.
@Antoninj - I believe you can do that quite easily by doing the following:
- Sync the fork (dev branch) with your the upstream (on GitHub you can do that easily)
- Pull the updated dev branch to your local machine (e.g.
git checkout devand thengit pull) - Now you can rebase the branch
aqara_external_temperature_sensoronto dev branch (or merge dev branch into your branch) - You will have merge conflicts, which are easily resolved:
- The test file is new and is not affected
- The file
thermostat_agl001.pyis already in the new style and you should keep the code of your branch, except the changes of the attributes. These are already in the new style and you need to add those two lines I believe:
sensor_temp: Final = ZCLAttributeDef(
id=SENSOR_TEMP, type=t.uint32_t, is_manufacturer_specific=True
)
sensor_attr: Final = ZCLAttributeDef(
id=SENSOR_ATTR, type=t.LVBytes, is_manufacturer_specific=True
)
The tests run fine when I tried it.
However, there is the comment of NJLangley, which needs to be addressed. I am trying to look into that. As I am still quite "new" I try to learn und understand what is meant by the comment.
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 you feel that you do not have time, I could replicate this PR and do the changes.
Let me know if that is ok for you.
| attrs1 = {} | ||
| attrs1[SENSOR_ATTR_NAME] = ( | ||
| self.aqaraHeader(0x12, params1, 0x04) + params1 | ||
| ) | ||
| attrs[SENSOR_ATTR_NAME] = ( | ||
| self.aqaraHeader(0x13, params2, 0x04) + params2 | ||
| ) | ||
|
|
||
| await super().write_attributes(attrs1, manufacturer) |
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 these need to be written in separate calls?
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 honestly have no idea, I bootstrapped this PR from existing work from someone else and mostly focused on addding unit tests tbh
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.
They need to be in separate calls otherwise its starts to misbehave
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.
My guess is that two separate calls is necessary, otherwise it would not work correctly.
I conclude that there is nothing to do then.
…nsor - Move SENSOR_ID constant outside write_attributes method for efficiency - Use bytes(12) instead of long lists of zeros for cleaner code - Improve attribute handling with find_attribute for better robustness - Add proper type annotations for better code clarity - Update README.md to reference requirements_test_all.txt - Run ruff formatting
…e review suggestion)
|
@TheJulianJES thanks for the detailed code review, I've addressed most of the remarks. |
| self._float_to_hex(round(float(value)))[2:] | ||
| ) | ||
|
|
||
| params = SENSOR_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.
This seems to break the quirk for me. I can set the TRV into external sensor mode once and set the temp, but all subsequent calls fail and it seems that the max size of the constructed message is exceeded.
It's because the SENSOR_ID variable is not copied, so appending more bytes to the params variable is modifying SENSOR_ID, which means it's then bigger to start with the next time it's run. Changing the line to
params = bytearray(SENSOR_ID)
seems to fix it for me. Might want the tests to check the length of the message args for two subsequent calls to verify 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.
I tried the suggestion you mentioned and wrote a test for this to avoid regression.
I hope to revceive an answer from @Antoninj in regard to collaborate on this PR or if I re-create the PR with the changes.
|
I was having some issues with this, as it worked for the first call to set the mode to external sensor and then set the temp, but for all subsequent calls until the ZHA integrations was reloaded then failed. Digging through the stack trace for the error suggests the message exceeded the size of the window used for Zigbee comms. The original quirk from #2802 does work, and I've left a comment on the line that needs fixing. Looks like it's not copying the byte array before building the message from it, so it's them broken when it builds the next message |
|
I created a new PR that continues Antonin's work with the review comments taken into account. I added two test cases and did little refactoring, which I believe helps read the code better. |
Proposed change
Support for external temperature sensor.
Additional information
This is a copy of #2802 + the missing unit tests
Checklist
pre-commitchecks pass / the code has been formatted using Black