Skip to content

Commit

Permalink
Init quirk
Browse files Browse the repository at this point in the history
  • Loading branch information
prairiesnpr committed Jan 19, 2025
1 parent e61ecbb commit fa6e3c1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
6 changes: 5 additions & 1 deletion tests/test_tuya_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class TestEnum(t.enum8):
A = 0x00
B = 0x01

class ModTuyaMCUCluster(TuyaMCUCluster):
"""Modified Cluster."""

entry = (
TuyaQuirkBuilder(device_mock.manufacturer, device_mock.model, registry=registry)
.tuya_battery(dp_id=1)
Expand Down Expand Up @@ -123,7 +126,7 @@ class TestEnum(t.enum8):
fallback_name="Test enum",
)
.skip_configuration()
.add_to_registry()
.add_to_registry(replacement_cluster=ModTuyaMCUCluster)
)

# coverage for overridden __eq__ method
Expand All @@ -140,6 +143,7 @@ class TestEnum(t.enum8):
assert isinstance(ep.basic, Basic)

assert ep.tuya_manufacturer is not None
assert isinstance(ep.tuya_manufacturer, ModTuyaMCUCluster)
assert isinstance(ep.tuya_manufacturer, TuyaMCUCluster)

tuya_cluster = ep.tuya_manufacturer
Expand Down
53 changes: 50 additions & 3 deletions zhaquirks/tuya/ts0601_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
import zigpy.types as t
from zigpy.zcl import foundation

from zhaquirks.tuya.builder import (
from zhaquirks.tuya import (
TUYA_MCU_VERSION_REQ,
TUYA_QUERY_DATA,
TuyaPowerConfigurationCluster2AAA,
TuyaQuirkBuilder,
TuyaTemperatureMeasurement,
)
from zhaquirks.tuya.builder import TuyaQuirkBuilder, TuyaTemperatureMeasurement
from zhaquirks.tuya.mcu import TuyaMCUCluster

(
TuyaQuirkBuilder("_TZE200_bjawzodf", "TS0601")
Expand Down Expand Up @@ -61,6 +64,50 @@
.add_to_registry()
)


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 76 in zhaquirks/tuya/ts0601_sensor.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/tuya/ts0601_sensor.py#L76

Added line #L76 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 80 in zhaquirks/tuya/ts0601_sensor.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/tuya/ts0601_sensor.py#L79-L80

Added lines #L79 - L80 were not covered by tests

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


(
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)
)


(
TuyaQuirkBuilder("_TZE200_yjjdcqsq", "TS0601")
.applies_to("_TZE200_9yapgbuv", "TS0601")
Expand Down

0 comments on commit fa6e3c1

Please sign in to comment.