22
33import datetime
44
5- from zigpy .quirks .v2 import EntityPlatform , EntityType
5+ from zigpy .quirks .v2 import BinarySensorDeviceClass , EntityPlatform , EntityType
66from zigpy .quirks .v2 .homeassistant import PERCENTAGE , UnitOfTemperature , UnitOfTime
7- from zigpy .quirks .v2 .homeassistant .sensor import SensorDeviceClass
7+ from zigpy .quirks .v2 .homeassistant .sensor import SensorDeviceClass , SensorStateClass
88import zigpy .types as t
99from zigpy .zcl import foundation
1010
@@ -32,6 +32,21 @@ class TuyaNousTempHumiAlarm(t.enum8):
3232 Canceled = 0x02
3333
3434
35+ class TuyaBatteryState (t .enum8 ):
36+ """Tuya battery state enum."""
37+
38+ Low = 0x00
39+ Medium = 0x01
40+ Full = 0x02
41+
42+
43+ class TuyaTimeFormat (t .enum8 ):
44+ """Tuya time format enum."""
45+
46+ Format24h = 0x00
47+ Format12h = 0x01
48+
49+
3550class NoManufTimeTuyaMCUCluster (TuyaMCUCluster ):
3651 """Tuya Manufacturer Cluster with set_time mod."""
3752
@@ -47,6 +62,13 @@ class ServerCommandDefs(TuyaMCUCluster.ServerCommandDefs):
4762 is_manufacturer_specific = False ,
4863 )
4964
65+ class ClientCommandDefs (TuyaMCUCluster .ClientCommandDefs ):
66+ """Client command definitions."""
67+
68+ set_time_request = foundation .ZCLCommandDef (
69+ id = TUYA_SET_TIME , schema = {"data" : t .data16 }, is_manufacturer_specific = False
70+ )
71+
5072
5173(
5274 TuyaQuirkBuilder ("_TZE200_bjawzodf" , "TS0601" )
@@ -333,3 +355,34 @@ class ServerCommandDefs(TuyaMCUCluster.ServerCommandDefs):
333355 .skip_configuration ()
334356 .add_to_registry ()
335357)
358+
359+ # Sensor with clock, internal/external temperature and humidity
360+ (
361+ TuyaQuirkBuilder ("_TZE284_hodyryli" , "TS0601" )
362+ # Internal temperature (DP 1, scale=10)
363+ .tuya_temperature (dp_id = 1 , scale = 10 )
364+ # Internal humidity (DP 2)
365+ .tuya_humidity (dp_id = 2 )
366+ # Battery from battery_state (DP 3: 0=10%, 1=50%, 2=100%)
367+ .tuya_dp (
368+ dp_id = 3 ,
369+ ep_attribute = TuyaPowerConfigurationCluster2AAA .ep_attribute ,
370+ attribute_name = "battery_percentage_remaining" ,
371+ converter = lambda x : {0 : 10 , 1 : 50 , 2 : 100 }[x ],
372+ )
373+ .adds (TuyaPowerConfigurationCluster2AAA )
374+ # External temperature sensor (DP 38, value needs to be divided by 100 to get correct temperature)
375+ .tuya_sensor (
376+ dp_id = 38 ,
377+ attribute_name = "temperature_external" ,
378+ type = t .int32s ,
379+ converter = lambda x : x / 100 , # Divide by 100 to get correct temperature
380+ device_class = SensorDeviceClass .TEMPERATURE ,
381+ state_class = SensorStateClass .MEASUREMENT ,
382+ unit = UnitOfTemperature .CELSIUS ,
383+ translation_key = "temperature_external" ,
384+ fallback_name = "Temperature Probe" ,
385+ )
386+ .skip_configuration ()
387+ .add_to_registry (replacement_cluster = NoManufTimeTuyaMCUCluster )
388+ )
0 commit comments