-
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
299c9d8
Add support for _TZE200_yi4jtqq1 illuminance sensor.
gmsoft-tuxicoman 1aae28e
Merge branch 'zigpy:dev' into _TZE200_yi4jtqq1
gmsoft-tuxicoman a5ef626
Fix linting.
gmsoft-tuxicoman 4dbb5f5
Some more fixes.
gmsoft-tuxicoman e768d8f
Update code according to PR comments part 1.
gmsoft-tuxicoman c148fcf
Convert to TuyaMCUCluster.
gmsoft-tuxicoman 2d6a958
Linting fixes.
gmsoft-tuxicoman 69aec27
Make attribute names match.
gmsoft-tuxicoman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
"""Tuya HOME-LUX illuminance sensor.""" | ||
|
||
import math | ||
from typing import Dict | ||
|
||
from zigpy.profiles import zha | ||
from zigpy.quirks import CustomDevice | ||
import zigpy.types as t | ||
from zigpy.zcl.clusters.general import Basic, GreenPowerProxy, Groups, Ota, Scenes, Time | ||
from zigpy.zcl.clusters.measurement import IlluminanceMeasurement | ||
|
||
from zhaquirks.const import ( | ||
DEVICE_TYPE, | ||
ENDPOINTS, | ||
INPUT_CLUSTERS, | ||
MODELS_INFO, | ||
OUTPUT_CLUSTERS, | ||
PROFILE_ID, | ||
) | ||
from zhaquirks.tuya import TuyaLocalCluster | ||
from zhaquirks.tuya.mcu import DPToAttributeMapping, TuyaDPType, TuyaMCUCluster | ||
|
||
TUYA_BRIGHTNESS_LEVEL_DP = 0x01 # 0-2 "Low, Medium, High" | ||
TUYA_ILLUMINANCE_DP = 0x02 # [0, 0, 3, 232] illuminance | ||
|
||
|
||
class BrightnessLevel(t.enum8): | ||
"""Brightness level enum.""" | ||
|
||
LOW = 0x00 | ||
MEDIUM = 0x01 | ||
HIGH = 0x02 | ||
|
||
|
||
class TuyaIlluminanceMeasurement(IlluminanceMeasurement, TuyaLocalCluster): | ||
"""Tuya local IlluminanceMeasurement cluster.""" | ||
|
||
attributes = IlluminanceMeasurement.attributes.copy() | ||
attributes.update( | ||
{ | ||
0xFF00: ("brightness_level", BrightnessLevel, True), | ||
} | ||
) | ||
|
||
|
||
class TuyaIlluminanceCluster(TuyaMCUCluster): | ||
"""Tuya Illuminance cluster.""" | ||
|
||
dp_to_attribute: Dict[int, DPToAttributeMapping] = { | ||
TUYA_BRIGHTNESS_LEVEL_DP: DPToAttributeMapping( | ||
TuyaIlluminanceMeasurement.ep_attribute, | ||
"manufacturer_brightness_level", | ||
dp_type=TuyaDPType.ENUM, | ||
converter=lambda x: BrightnessLevel(x), | ||
), | ||
TUYA_ILLUMINANCE_DP: 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_DP: "_dp_2_attr_update", | ||
TUYA_ILLUMINANCE_DP: "_dp_2_attr_update", | ||
} | ||
|
||
|
||
class TuyaIlluminance(CustomDevice): | ||
"""HOME-LUX illuminance sensor. Sense maximum 1000 lumen.""" | ||
|
||
signature = { | ||
# endpoint=1, profile=260, device_type=81, device_version=1, | ||
# input_clusters=[4, 5, 61184, 0], output_clusters=[25, 10]) | ||
MODELS_INFO: [ | ||
("_TZE200_yi4jtqq1", "TS0601"), | ||
], | ||
ENDPOINTS: { | ||
1: { | ||
PROFILE_ID: zha.PROFILE_ID, | ||
DEVICE_TYPE: zha.DeviceType.SMART_PLUG, | ||
INPUT_CLUSTERS: [ | ||
Basic.cluster_id, | ||
Groups.cluster_id, | ||
Scenes.cluster_id, | ||
TuyaMCUCluster.cluster_id, | ||
], | ||
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id], | ||
}, | ||
242: { | ||
# <SimpleDescriptor endpoint=242 profile=41440 device_type=97 | ||
# input_clusters=[] | ||
# output_clusters=[33] | ||
PROFILE_ID: 41440, | ||
DEVICE_TYPE: 97, | ||
INPUT_CLUSTERS: [], | ||
OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id], | ||
}, | ||
}, | ||
} | ||
|
||
replacement = { | ||
ENDPOINTS: { | ||
1: { | ||
PROFILE_ID: zha.PROFILE_ID, | ||
DEVICE_TYPE: zha.DeviceType.OCCUPANCY_SENSOR, | ||
INPUT_CLUSTERS: [ | ||
Basic.cluster_id, | ||
Groups.cluster_id, | ||
Scenes.cluster_id, | ||
TuyaIlluminanceCluster, | ||
TuyaIlluminanceMeasurement, | ||
], | ||
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id], | ||
}, | ||
242: { | ||
PROFILE_ID: 41440, | ||
DEVICE_TYPE: 97, | ||
INPUT_CLUSTERS: [], | ||
OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id], | ||
}, | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.