-
Notifications
You must be signed in to change notification settings - Fork 726
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 support for _TZE200_yi4jtqq1 illuminance sensor. #1795
Conversation
Pull Request Test Coverage Report for Build 3291717546
💛 - Coveralls |
Codecov ReportBase: 80.00% // Head: 80.50% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## dev #1795 +/- ##
==========================================
+ Coverage 80.00% 80.50% +0.50%
==========================================
Files 239 241 +2
Lines 7430 7506 +76
==========================================
+ Hits 5944 6043 +99
+ Misses 1486 1463 -23
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. |
Please rebase this and install / run the precommit checks |
@javicalle lmk what you think when you have a moment please. Thanks! |
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.
These would be the minimum requirements to review.
zhaquirks/tuya/ts0601_illuminance.py
Outdated
TUYA_BRIGHTNESS_LEVEL_ATTR = 0x01 # 0-2 "Low, Medium, High" | ||
TUYA_ILLUMINANCE_ATTR = 0x02 # [0, 0, 3, 232] illuminance |
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.
No problem with setting as constants, but I would prefer not to use the _ATTR
sufix because it can be confusing (they are not clusters attributes).
Replace all around with a DataPoint nomenclature:
TUYA_BRIGHTNESS_LEVEL_DP = 0x01 # 0-2 "Low, Medium, High"
TUYA_ILLUMINANCE_DP = 0x02 # [0, 0, 3, 232] illuminance
zhaquirks/tuya/ts0601_illuminance.py
Outdated
attributes = IlluminanceMeasurement.attributes.copy() | ||
attributes.update( | ||
{ | ||
0xFF00: ("brightness_level", t.CharacterString, 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.
The illuminanceMeasurement cluster don't have any reference to brightness_level
so not sure if that could be the correct attribute name 🤔
We can keep the reference for now but I would replace for manufacturer_brightness_level
or manufacturer_measured_value
.
zhaquirks/tuya/ts0601_illuminance.py
Outdated
TUYA_BRIGHTNESS_LEVEL_ATTR = 0x01 # 0-2 "Low, Medium, High" | ||
TUYA_ILLUMINANCE_ATTR = 0x02 # [0, 0, 3, 232] illuminance | ||
|
||
TUYA_BRIGHTNESS_LEVEL_STR = ["Low", "Medium", "High"] |
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.
What about if we use:
class BrightnessLevel(t.enum8):
"""Brightness level enum."""
LOW = 0x00
MEDIUM = 0x01
HIGH = 0x02
That way you can define the attribute as:
0xFF00: ("brightness_level", BrightnessLevel, True),
And convert as:
dp_to_attribute: Dict[int, DPToAttributeMapping] = {
TUYA_BRIGHTNESS_LEVEL_ATTR: DPToAttributeMapping(
TuyaIlluminanceMeasurement.ep_attribute,
"brightness_level",
lambda x: BrightnessLevel(x),
),
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 intend to migrate the class hierarchy for these types of devices, so I am going to ask you to make the following changes.
These changes are not a prerequisite, but they will help us with future maintenance.
If you're going to tackle the changes, I'd suggest making the other changes first, then attacking these changes.
zhaquirks/tuya/ts0601_illuminance.py
Outdated
class TuyaIlluminanceCluster(TuyaNewManufCluster): | ||
"""Tuya Illuminance cluster.""" | ||
|
||
dp_to_attribute: Dict[int, DPToAttributeMapping] = { | ||
TUYA_BRIGHTNESS_LEVEL_ATTR: DPToAttributeMapping( | ||
TuyaIlluminanceMeasurement.ep_attribute, | ||
"brightness_level", | ||
lambda x: TUYA_BRIGHTNESS_LEVEL_STR[x], | ||
), | ||
TUYA_ILLUMINANCE_ATTR: DPToAttributeMapping( | ||
TuyaIlluminanceMeasurement.ep_attribute, | ||
"measured_value", | ||
lambda x: (10000.0 * math.log10(x) + 1.0 if x != 0 else 0), | ||
), | ||
} | ||
|
||
data_point_handlers = { | ||
TUYA_BRIGHTNESS_LEVEL_ATTR: "_dp_2_attr_update", | ||
TUYA_ILLUMINANCE_ATTR: "_dp_2_attr_update", | ||
} |
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.
You will need to change the imports statements to the new ones:
from zhaquirks.tuya import TuyaLocalCluster
from zhaquirks.tuya.mcu import (
DPToAttributeMapping,
TuyaDPType,
TuyaMCUCluster,
)
Change your TuyaIlluminanceCluster
class declaration to something like:
class TuyaIlluminanceCluster(TuyaMCUCluster):
"""Tuya Illuminance cluster."""
dp_to_attribute: Dict[int, DPToAttributeMapping] = {
TUYA_BRIGHTNESS_LEVEL_ATTR: DPToAttributeMapping(
TuyaIlluminanceMeasurement.ep_attribute,
"brightness_level", # or the new name for attribute
dp_type=TuyaDPType.ENUM,
converter=lambda x: BrightnessLevel(x),
),
TUYA_ILLUMINANCE_ATTR: DPToAttributeMapping(
TuyaIlluminanceMeasurement.ep_attribute,
"measured_value",
dp_type=TuyaDPType.VALUE,
converter=lambda x: (10000.0 * math.log10(x) + 1.0 if x != 0 else 0),
),
}
data_point_handlers = {
TUYA_BRIGHTNESS_LEVEL_ATTR: "_dp_2_attr_update",
TUYA_ILLUMINANCE_ATTR: "_dp_2_attr_update",
}
Thats all.
Not happy with another The The device doesn't have a battery report? |
I've made all the changes. This device doesn't have a battery sensor as it's USB powered. |
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.
Just one left.
zhaquirks/tuya/ts0601_illuminance.py
Outdated
attributes = IlluminanceMeasurement.attributes.copy() | ||
attributes.update( | ||
{ | ||
0xFF00: ("brightness_level", BrightnessLevel, 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.
Maybe manufacturer_brightness_level
here?
Must be the same value as in dp_to_attribute
mapping.
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
Thanks for your work and patience.
This is a simple illuminance sensort with a maximum of 1000 lumen. So it's only really suited for inside, not outside.
The quirk provide both the raw lumen value as well as the low/medium/high brightness level.