From 895bb89712c587b6e2c7c3a692b74677d1a3b8f5 Mon Sep 17 00:00:00 2001 From: prairiesnpr Date: Sat, 25 Jan 2025 20:28:28 -0500 Subject: [PATCH] Add Tuya outdoor temp humidity sensor `_TZE204_upagmta9` (#3709) --- tests/test_tuya_sensor.py | 37 ++++++++++++++--------- zhaquirks/tuya/tuya_sensor.py | 57 +++++++++++++++++++++++------------ 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/tests/test_tuya_sensor.py b/tests/test_tuya_sensor.py index 2628e54821..58a672fcef 100644 --- a/tests/test_tuya_sensor.py +++ b/tests/test_tuya_sensor.py @@ -9,6 +9,14 @@ from zhaquirks.tuya import TuyaLocalCluster from zhaquirks.tuya.mcu import TuyaMCUCluster +# Temp DP 1, Humidity DP 2, Battery DP 3 +TUYA_TEMP01_HUM02_BAT03 = b"\x09\xe0\x02\x0b\x33\x01\x02\x00\x04\x00\x00\x00\xfd\x02\x02\x00\x04\x00\x00\x00\x47\x03\x02\x00\x04\x00\x00\x00\x01" +# Temp DP 1, Humidity DP 2, Battery DP 4 +TUYA_TEMP01_HUM02_BAT04 = b"\x09\xe0\x02\x0b\x33\x01\x02\x00\x04\x00\x00\x00\xfd\x02\x02\x00\x04\x00\x00\x00\x47\x04\x02\x00\x04\x00\x00\x00\x01" +TUYA_USP = b"\x09\xe0\x02\x0b\x33\x01\x02\x00\x04\x00\x00\x00\xfd\x02\x02\x00\x04\x00\x00\x00\x47\xff\x02\x00\x04\x00\x00\x00\x64" + +ZCL_TUYA_VERSION_RSP = b"\x09\x06\x11\x01\x6d\x82" + zhaquirks.setup() @@ -74,8 +82,7 @@ async def test_handle_get_data( == data.data.datapoints[2].data.payload * 2 ) - message = b"\x09\xe0\x02\x0b\x33\x01\x02\x00\x04\x00\x00\x00\xfd\x02\x02\x00\x04\x00\x00\x00\x47\xff\x02\x00\x04\x00\x00\x00\x64" - hdr, data = ep.tuya_manufacturer.deserialize(message) + hdr, data = ep.tuya_manufacturer.deserialize(TUYA_USP) status = ep.tuya_manufacturer.handle_get_data(data.data) assert status == foundation.Status.UNSUPPORTED_ATTRIBUTE @@ -91,19 +98,21 @@ async def test_handle_get_data( @pytest.mark.parametrize( - "model,manuf,rh_scale,temp_scale", + "model,manuf,rh_scale,temp_scale,state_rpt", [ - ("_TZE200_yjjdcqsq", "TS0601", 100, 10), - ("_TZE200_9yapgbuv", "TS0601", 100, 10), - ("_TZE204_yjjdcqsq", "TS0601", 100, 10), - ("_TZE200_utkemkbs", "TS0601", 100, 10), - ("_TZE204_utkemkbs", "TS0601", 100, 10), - ("_TZE204_yjjdcqsq", "TS0601", 100, 10), - ("_TZE204_ksz749x8", "TS0601", 100, 10), + ("_TZE200_yjjdcqsq", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04), + ("_TZE200_9yapgbuv", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04), + ("_TZE204_yjjdcqsq", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04), + ("_TZE200_utkemkbs", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04), + ("_TZE204_utkemkbs", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04), + ("_TZE204_yjjdcqsq", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04), + ("_TZE204_ksz749x8", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04), + ("_TZE204_upagmta9", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT03), + ("_TZE204_upagmta9", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT03), ], ) async def test_handle_get_data_enum_batt( - zigpy_device_from_v2_quirk, model, manuf, rh_scale, temp_scale + zigpy_device_from_v2_quirk, model, manuf, rh_scale, temp_scale, state_rpt ): """Test handle_get_data for multiple attributes - enum battery.""" @@ -116,8 +125,7 @@ async def test_handle_get_data_enum_batt( assert ep.tuya_manufacturer is not None assert isinstance(ep.tuya_manufacturer, TuyaMCUCluster) - message = b"\x09\xe0\x02\x0b\x33\x01\x02\x00\x04\x00\x00\x00\xfd\x02\x02\x00\x04\x00\x00\x00\x47\x04\x02\x00\x04\x00\x00\x00\x01" - hdr, data = ep.tuya_manufacturer.deserialize(message) + hdr, data = ep.tuya_manufacturer.deserialize(state_rpt) status = ep.tuya_manufacturer.handle_get_data(data.data) @@ -135,8 +143,7 @@ async def test_handle_get_data_enum_batt( assert ep.power.get("battery_percentage_remaining") == 100 - message = b"\x09\xe0\x02\x0b\x33\x01\x02\x00\x04\x00\x00\x00\xfd\x02\x02\x00\x04\x00\x00\x00\x47\xff\x02\x00\x04\x00\x00\x00\x64" - hdr, data = ep.tuya_manufacturer.deserialize(message) + hdr, data = ep.tuya_manufacturer.deserialize(TUYA_USP) status = ep.tuya_manufacturer.handle_get_data(data.data) assert status == foundation.Status.UNSUPPORTED_ATTRIBUTE diff --git a/zhaquirks/tuya/tuya_sensor.py b/zhaquirks/tuya/tuya_sensor.py index 486f5182b9..f63f6b1bcd 100644 --- a/zhaquirks/tuya/tuya_sensor.py +++ b/zhaquirks/tuya/tuya_sensor.py @@ -33,6 +33,26 @@ class TuyaNousTempHumiAlarm(t.enum8): Canceled = 0x02 +class NoManufTimeTuyaMCUCluster(TuyaMCUCluster): + """Tuya Manufacturer Cluster with set_time mod.""" + + set_time_offset = 1970 + set_time_local_offset = 1970 + + # Deepcopy required to override 'set_time', without, it will revert + server_commands = copy.deepcopy(TuyaMCUCluster.server_commands) + server_commands.update( + { + TUYA_SET_TIME: foundation.ZCLCommandDef( + "set_time", + {"time": TuyaTimePayload}, + False, + is_manufacturer_specific=False, + ), + } + ) + + ( TuyaQuirkBuilder("_TZE200_bjawzodf", "TS0601") .applies_to("_TZE200_zl1kmjqx", "TS0601") @@ -89,26 +109,6 @@ class TuyaNousTempHumiAlarm(t.enum8): ) -class NoManufTimeTuyaMCUCluster(TuyaMCUCluster): - """Tuya Manufacturer Cluster with set_time mod.""" - - set_time_offset = 1970 - set_time_local_offset = 1970 - - # Deepcopy required to override 'set_time', without, it will revert - server_commands = copy.deepcopy(TuyaMCUCluster.server_commands) - server_commands.update( - { - TUYA_SET_TIME: foundation.ZCLCommandDef( - "set_time", - {"time": TuyaTimePayload}, - False, - is_manufacturer_specific=False, - ), - } - ) - - # TH01Z - Temperature and humidity sensor with clock ( TuyaQuirkBuilder("_TZE200_lve3dvpy", "TS0601") @@ -311,3 +311,20 @@ class NoManufTimeTuyaMCUCluster(TuyaMCUCluster): .skip_configuration() .add_to_registry() ) + + +( + TuyaQuirkBuilder("_TZE204_upagmta9", "TS0601") + .tuya_temperature(dp_id=1, scale=10) + .tuya_humidity(dp_id=2) + .tuya_dp( + dp_id=3, + ep_attribute=TuyaPowerConfigurationCluster2AAA.ep_attribute, + attribute_name="battery_percentage_remaining", + converter=lambda x: {0: 50, 1: 100, 2: 200}[x], + ) + .adds(TuyaPowerConfigurationCluster2AAA) + .tuya_enchantment(data_query_spell=True) + .skip_configuration() + .add_to_registry() +)