Skip to content

Commit

Permalink
Add Tuya outdoor temp humidity sensor _TZE204_upagmta9 (#3709)
Browse files Browse the repository at this point in the history
  • Loading branch information
prairiesnpr authored Jan 26, 2025
1 parent 068cf83 commit 895bb89
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 35 deletions.
37 changes: 22 additions & 15 deletions tests/test_tuya_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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
Expand All @@ -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."""

Expand All @@ -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)

Expand All @@ -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
Expand Down
57 changes: 37 additions & 20 deletions zhaquirks/tuya/tuya_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
)

0 comments on commit 895bb89

Please sign in to comment.