-
Notifications
You must be signed in to change notification settings - Fork 675
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 device support for TS110E Model QS-Zigbee-D02-TRIAC-LN #1422
Conversation
This device uses a non-default set level command. Tested in local docker environment. Thanks to @javicalle this was possible. Fix zigpy#1415
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.
A little fix for the checks
zhaquirks/tuya/ts110e.py
Outdated
Scenes.cluster_id, | ||
OnOff.cluster_id, | ||
F000LevelControlCluster, | ||
TuyaZBExternalSwitchTypeCluster.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.
remove the '.cluster_id' part:
TuyaZBExternalSwitchTypeCluster,
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 first testing if the cluster / attribute is working on the device or not and is its not working then deleting it in the replacement (its always possible adding it later if its needed) but its very likely not working on this device.
The implementation is here:
zha-device-handlers/zhaquirks/tuya/__init__.py
Lines 887 to 902 in 8ae597d
# Tuya Zigbee Cluster 0xE001 Implementation | |
class ExternalSwitchType(t.enum8): | |
"""Tuya external switch type enum.""" | |
Toggle = 0x00 | |
State = 0x01 | |
Momentary = 0x02 | |
class TuyaZBExternalSwitchTypeCluster(CustomCluster): | |
"""Tuya External Switch Type Cluster.""" | |
name = "Tuya External Switch Type Cluster" | |
cluster_id = TUYA_CLUSTER_E001_ID | |
ep_attribute = "tuya_external_switch_type" | |
attributes = {0xD030: ("external_switch_type", ExternalSwitchType)} |
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 actually noticed that I had to leave in the .cluster_id
part, otherwise the quirk wouldn't show up on the device anymore.
class TuyaLevelPayload(t.Struct): | ||
"""Tuya Level payload.""" | ||
|
||
level: t.uint16_t | ||
transtime: t.uint16_t |
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 should probably move to tuya.__init__.py
, but let's keep it here for now.
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.
Or first do the implementation in the quirk and getting it merged and its working OK and then making one more PR for moving it to tuya INIT then tuya INIT is little tricky with many addings and can needing rebasing many times and its PITA (i have one PR waiting for being merged to it).
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.
Yes, that's the idea.
Keep here and merge. When required, move to Tuya INIT. 👍🏻
zhaquirks/tuya/ts110e.py
Outdated
HALOGEN = 0x02 | ||
|
||
|
||
class F000LevelControlCluster(LevelControl): |
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 LevelControl
part is actually making issues. Because it applies to all dimmers in my house now, even the non-Tuya ones. And those obviously don't need this quirk. I think I somehow need to incorporate CustomCluster
somewhere. But just adding class F000LevelControlCluster(CustomCluster, LevelControl):
doesn't work.
@javicalle do you know how I can change this quirk to only work with the Custom device DimmerSwitchWithNeutral1Gang
below?
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 what you mean. The F000LevelControlCluster
cluster definition is only used in the DimmerSwitchWithNeutral1Gang
quirk. An this quirk only applies to _TZ3210_ngqk6jia
device.
What is exactly the problem? When they started? Have you updated HA?
If you believe that there's a problem with your quirk, try to remove it an check if the problem persist, but I don't know how that quirk can affect other devices than the _TZ3210_ngqk6jia
.
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 zhaquirks.tuya.ts110e.DimmerSwitchWithNeutral1Gang
quirk didn't show up on the new dimmer (non tuya) I bought, but the F000LevelControlCluster
showed up on the new dimmer I bought. I found that that is because we just used class F000LevelControlCluster(LevelControl):
, without implementing a CustomCluster
.
I have experimented some more and found that adding CustomCluster
as mentioned in my last comment didn't work, because that sent the manufacturer ID to the device and the device didn't recognize that. I found out by continuously comparing the logs between the setting that worked and the one that didn't work.
Long story short, I had to add NoManufacturerCluster
to make it work. That is only in the later versions of zha-device-handlers
, so I had to update my entire home-assistance instance. I have done that now and updated my quirk to use class F000LevelControlCluster(NoManufacturerCluster, LevelControl):
. And that ended up doing what I wanted which is that the F000LevelControlCluster
only applies to the tuya dimmer and not to others.
I will update this PR accordingly as there are some other changes with the latest updates on the dev branch.
Codecov Report
@@ Coverage Diff @@
## dev #1422 +/- ##
==========================================
- Coverage 80.52% 80.29% -0.24%
==========================================
Files 222 233 +11
Lines 6414 7018 +604
==========================================
+ Hits 5165 5635 +470
- Misses 1249 1383 +134
Continue to review full report at Codecov.
|
Pull Request Test Coverage Report for Build 2489301802
💛 - Coveralls |
After lots of testing I'm pretty confident this is working code now. All the checks are succeeding too. I've also updated it to work with the new |
} | ||
) | ||
|
||
# 0xF000 reported values are 10-1000, convert to 0-254 |
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.
The conversion is 1-255 (which I think is the range that HA handles).
And the values 10 & 1000 I think correspond to the manufacturer_min_level
and manufacturer_max_level
values.
If someone modifies the values that conversion can do strange things.
The truth is that I don't know what could be the best way to handle this situation, but it is probably something quite common in dimmers that would be addressed in a generic way.
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 experimented with this quite a while and this is what worked best for me. Would you agree to merging this as is (because it seems to work with the default manufacturer_min_level
and manufacturer_max_level
) and if someone in the future comes in and finds a better approach to calculate the values we just update the formula? At least this PR supports the device in the first place 😊
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 agree. We can go ahead with the version as is.
return await super().command( | ||
TUYA_CUSTOM_LEVEL_COMMAND, | ||
TuyaLevelPayload(level=brightness, transtime=0), | ||
manufacturer=manufacturer, | ||
expect_reply=expect_reply, | ||
tsn=tsn, | ||
) |
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 fine to me, but probably you can get the same result without extending the NoManufacturerCluster
and putting here:
manufacturer=foundation.ZCLHeader.NO_MANUFACTURER_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.
Hmm that doesn't work because then this Class would also show up as cluster in the dimmers of other devices. F000LevelControlCluster
has to inherit in some way from CustomCluster
and NoManufacturerCluster
does that for us (including setting manufacturer=foundation.ZCLHeader.NO_MANUFACTURER_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 Class would also show up as cluster in the dimmers of other devices
That sentence not make sense to me. A quirk shouldn't modify other devices that don't use the quirk.
Trying to figure out how can be done I believe that some code like this could make the described behaviour:
# attributes = LevelControl.attributes.copy()
attributes.update(
{
# 0xF000
TUYA_LEVEL_ATTRIBUTE: ("manufacturer_current_level", t.uint16_t),
}
)
If not making a copy of parent class attributes, maybe the code is modifying the parent attributes and changes for any device that uses the parent class 🤔
In any case, your proposed code is fine to me.
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.
Hmm yeah I don’t know, but it did show up as level control cluster on this new dimmer I bought…
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.
LGTM
This device uses a non-default set level command.
This device looks exactly the same as TS110F but seems to have different zigbee command IDs. This is TS110F on blakadder: https://zigbee.blakadder.com/Lonsonho_QS-Zigbee-D02-TRIAC-LN.html
Tested in local docker environment.
Thanks to @javicalle this was possible.
Fix #1415