Skip to content

Commit

Permalink
Init quirk
Browse files Browse the repository at this point in the history
  • Loading branch information
prairiesnpr committed Jan 23, 2025
1 parent c99f86b commit 3b25f04
Showing 1 changed file with 65 additions and 20 deletions.
85 changes: 65 additions & 20 deletions zhaquirks/tuya/tuya_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from zigpy.zcl import foundation

from zhaquirks.tuya import (
TUYA_MCU_VERSION_REQ,
TUYA_QUERY_DATA,
TUYA_SET_TIME,
TuyaPowerConfigurationCluster2AAA,
TuyaTimePayload,
Expand All @@ -32,6 +34,53 @@ 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,
),
}
)


class RespondingTuyaMCUCluster(TuyaMCUCluster):
"""Tuya Manufacturer Cluster with mcu version response."""

def handle_mcu_version_response(
self, payload: TuyaMCUCluster.MCUVersion
) -> foundation.Status:
"""Handle MCU version response."""

self.create_catching_task(

Check warning on line 65 in zhaquirks/tuya/tuya_sensor.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/tuya/tuya_sensor.py#L65

Added line #L65 was not covered by tests
super().command(TUYA_MCU_VERSION_REQ, 2, expect_reply=False)
)
self.create_catching_task(super().command(TUYA_QUERY_DATA, expect_reply=False))
super().handle_mcu_version_response(payload)

Check warning on line 69 in zhaquirks/tuya/tuya_sensor.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/tuya/tuya_sensor.py#L68-L69

Added lines #L68 - L69 were not covered by tests

server_commands = copy.deepcopy(TuyaMCUCluster.server_commands)
server_commands.update(
{
TUYA_MCU_VERSION_REQ: foundation.ZCLCommandDef(
"mcu_version_req",
{"data": t.uint16_t},
True,
is_manufacturer_specific=False,
),
}
)


(
TuyaQuirkBuilder("_TZE200_bjawzodf", "TS0601")
.applies_to("_TZE200_zl1kmjqx", "TS0601")
Expand Down Expand Up @@ -87,26 +136,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 @@ -317,3 +346,19 @@ 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)
.skip_configuration()
.add_to_registry(replacement_cluster=RespondingTuyaMCUCluster)
)

0 comments on commit 3b25f04

Please sign in to comment.