-
Notifications
You must be signed in to change notification settings - Fork 679
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
Set TuyaData.dp_type automatically #2043
Conversation
Codecov ReportBase: 83.69% // Head: 83.69% // Increases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## dev #2043 +/- ##
=======================================
Coverage 83.69% 83.69%
=======================================
Files 257 257
Lines 8225 8238 +13
=======================================
+ Hits 6884 6895 +11
- Misses 1341 1343 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Pull Request Test Coverage Report for Build 4091436317
💛 - Coveralls |
I like the idea very much, but I'm not sure if will work. My concern is that the implementation is based on the type of the data: isinstance(value, whatever) And the instances of
Upper in code, the method will be called from here:
And data will come in a
Do you see my point? ( I'm pretty sure that must be a way to avoid the type instantiation as you want but I haven't found it. |
Fixed annotation for The type is set when we assign the attribute, here is an example for bool:
|
Hm, that fails for python 3.8 and 3.9, checking. |
Ok, I see...
The method is invoked when you update one cluster attribute from the 'manage cluster' view (and maybe other places). 🤔 |
In this case we are using the type of the cluster attribute. |
06ed754
to
507edfc
Compare
Ok, I removed the annotation fix because I couldn't easily make it work for python below 3.10. Regardless, it looks like TuyaClusterData.attr_value can have types other than int, I don't know if it is a zigpy bug or not. |
Are we good with this? |
@Shulyaka @javicalle please let me know when this is mergable |
From my perspective, it is ready. @javicalle just needs to decide if the idea worth it. |
@javicalle thoughts? |
I meant to do some testing and validate this change but all my installation is broken and I'm having trouble spending time to fix it. |
First of all, I apologize to @Shulyaka for not having been able to review the topic before 🙇🏻♂️ Apart from a minor comment, let's go for it! |
zhaquirks/tuya/__init__.py
Outdated
if value is None: | ||
return | ||
elif isinstance(value, (t.bitmap8, t.bitmap16, t.bitmap32)): | ||
self.dp_type = TuyaDPType.BITMAP | ||
elif isinstance(value, (bool, t.Bool)): | ||
self.dp_type = TuyaDPType.BOOL | ||
elif isinstance(value, enum.Enum): | ||
self.dp_type = TuyaDPType.ENUM | ||
elif isinstance(value, int): | ||
self.dp_type = TuyaDPType.VALUE | ||
elif isinstance(value, str): | ||
self.dp_type = TuyaDPType.STRING | ||
elif isinstance(value, t.Struct): | ||
self.dp_type = TuyaDPType.RAW | ||
|
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.
Maybe a safe check here to be sure to assign the dp_type
?
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 have a different idea, to set it default to RAW
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.
Done
@Shulyaka can you rebase this and see if any of the recently merged tuya quirks need changes? Once that’s done I’ll merge this and get a release produced for the beta. |
507edfc
to
03d7de6
Compare
03d7de6
to
151e331
Compare
Done. |
151e331
to
943d8c7
Compare
This is also a part separated from #2017
This PR adds the
tuya.TuyaData.__init__()
constructor that automatically maps TuyaData.dp_type from zigpy type. That allows to remove thedp_type
field from thetuya.mcu.DPToAttributeMapping
mapping which may simplify the things.This is up to the developers to decide whether this is needed or not.