-
Notifications
You must be signed in to change notification settings - Fork 716
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 quirk for the TS0207 rain solar sensor #3475
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #3475 +/- ##
==========================================
- Coverage 89.44% 89.43% -0.02%
==========================================
Files 311 312 +1
Lines 10033 10080 +47
==========================================
+ Hits 8974 9015 +41
- Misses 1059 1065 +6 ☔ View full report in Codecov by Sentry. |
Adds a quirk that fixes this device by changing the "moving" and "closed" sensors to the rain and illuminance sensors that the device actually has. Most of the credit for this code goes to @hadeshimself from [this](zigpy#3249 (comment)) comment. Fixes zigpy#3249.
57eac57
to
a940591
Compare
FWIW I did briefly look at adding a test at least for the illuminance measurement getting copied in to a new cluster but I couldn't really get my head around how the existing tests are working. |
would be great is someone with the knowledeg, how the test should look like, could chip into this pr, currently my sensor is useless in homeassitant/zah until this quirk is live |
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 to give you something to start with, a v2 version might look something like this. Untested, I don't have the device. """Quirk for TS0207 rain sensors."""
from zigpy.quirks.v2.homeassistant import LIGHT_LUX, EntityType
from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
import zigpy.types as t
from zigpy.zcl.clusters.measurement import IlluminanceMeasurement
from zigpy.zcl.clusters.security import IasZone
from zhaquirks.tuya import TuyaLocalCluster
from zhaquirks.tuya.builder import TuyaQuirkBuilder
class TuyaIasZone(IasZone, TuyaLocalCluster):
"""IAS Zone for rain sensors."""
_CONSTANT_ATTRIBUTES = {
IasZone.AttributeDefs.zone_type.id: IasZone.ZoneType.Water_Sensor
}
class TuyaIlluminanceCluster(IlluminanceMeasurement, TuyaLocalCluster):
"""Tuya Illuminance cluster."""
(
TuyaQuirkBuilder("_TZ3210_tgvtvdoc", "TS0207")
.tuya_dp(
dp_id=101,
ep_attribute=TuyaIlluminanceCluster.ep_attribute,
attribute_name=TuyaIlluminanceCluster.AttributeDefs.measured_value.name,
converter=lambda x: x * 7,
)
.adds(TuyaIlluminanceCluster)
.tuya_sensor(
dp_id=102,
attribute_name="average_light_intensity_20mins",
type=t.uint32_t,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.DURATION,
unit=LIGHT_LUX,
entity_type=EntityType.DIAGNOSTIC,
translation_key="average_light_intensity_20mins",
fallback_name="Average light intensity last 20 min",
)
.tuya_sensor(
dp_id=103,
attribute_name="todays_max_light_intensity",
type=t.uint32_t,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.DURATION,
unit=LIGHT_LUX,
entity_type=EntityType.DIAGNOSTIC,
translation_key="todays_max_light_intensity",
fallback_name="Todays max light intensity",
)
.tuya_binary_sensor(
dp_id=104,
attribute_name="cleaning_reminder",
translation_key="cleaning_reminder",
fallback_name="Cleaning reminder",
)
.tuya_dp(
dp_id=105,
ep_attribute=TuyaIasZone.ep_attribute,
attribute_name=TuyaIasZone.AttributeDefs.zone_status.name,
)
.adds(TuyaIasZone)
.skip_configuration()
.add_to_registry()
) |
Any updates with the merge of this pull request? |
Hi, just bought this sensor and found this thread. So why not test the latest quirck code. In the log I get:: As double check installed the "v1" code from: #3249 (comment) And get the sensors came back (these are my first steps with ZHA, moving from Phoscon, and wanted to try first this rainsensor) |
Sorry about that, made a correction above, please test again if able. |
Test have to wait a little. Rechargeable battery of the sensor is empty due to cloudy weather past week. No external charging possible. |
A couple questions, did the illuminance sensor work, looks like several other Tuya sensors need Did the moisture binary actually show rain? I didn't realize that was in mv. Thinking this should be something like |
Proposed change
Adds a quirk that fixes this device by changing the "moving" and "closed" sensors to the rain and illuminance sensors that the device actually has.
Additional information
Most of the credit for this code goes to @hadeshimself from this comment.
Fixes #3249.
Checklist
pre-commit
checks pass / the code has been formatted using Black