|
2 | 2 |
|
3 | 3 | from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
|
4 | 4 | import zigpy.types as t
|
| 5 | +from zigpy.zcl import foundation |
5 | 6 |
|
6 |
| -from zhaquirks.tuya.builder import ( |
| 7 | +from zhaquirks.tuya import ( |
| 8 | + TUYA_MCU_VERSION_REQ, |
| 9 | + TUYA_QUERY_DATA, |
7 | 10 | TuyaPowerConfigurationCluster2AAA,
|
8 |
| - TuyaQuirkBuilder, |
9 |
| - TuyaTemperatureMeasurement, |
10 | 11 | )
|
| 12 | +from zhaquirks.tuya.builder import TuyaQuirkBuilder, TuyaTemperatureMeasurement |
| 13 | +from zhaquirks.tuya.mcu import TuyaMCUCluster |
11 | 14 |
|
12 | 15 | (
|
13 | 16 | TuyaQuirkBuilder("_TZE200_bjawzodf", "TS0601")
|
|
61 | 64 | .add_to_registry()
|
62 | 65 | )
|
63 | 66 |
|
| 67 | + |
| 68 | +class RespondingTuyaMCUCluster(TuyaMCUCluster): |
| 69 | + """Tuya Manufacturer Cluster with mcu version response.""" |
| 70 | + |
| 71 | + def handle_mcu_version_response( |
| 72 | + self, payload: TuyaMCUCluster.MCUVersion |
| 73 | + ) -> foundation.Status: |
| 74 | + """Handle MCU version response.""" |
| 75 | + |
| 76 | + self.create_catching_task( |
| 77 | + super().command(TUYA_MCU_VERSION_REQ, 2, expect_reply=False) |
| 78 | + ) |
| 79 | + self.create_catching_task(super().command(TUYA_QUERY_DATA, expect_reply=False)) |
| 80 | + super().handle_mcu_version_response(payload) |
| 81 | + |
| 82 | + server_commands = TuyaMCUCluster.server_commands.copy() |
| 83 | + server_commands.update( |
| 84 | + { |
| 85 | + TUYA_MCU_VERSION_REQ: foundation.ZCLCommandDef( |
| 86 | + "mcu_version_req", |
| 87 | + {"data": t.uint16_t}, |
| 88 | + True, |
| 89 | + is_manufacturer_specific=False, |
| 90 | + ), |
| 91 | + } |
| 92 | + ) |
| 93 | + |
| 94 | + |
| 95 | +( |
| 96 | + TuyaQuirkBuilder("_TZE204_upagmta9", "TS0601") |
| 97 | + .tuya_temperature(dp_id=1, scale=10) |
| 98 | + .tuya_humidity(dp_id=2) |
| 99 | + .tuya_dp( |
| 100 | + dp_id=3, |
| 101 | + ep_attribute=TuyaPowerConfigurationCluster2AAA.ep_attribute, |
| 102 | + attribute_name="battery_percentage_remaining", |
| 103 | + converter=lambda x: {0: 50, 1: 100, 2: 200}[x], |
| 104 | + ) |
| 105 | + .adds(TuyaPowerConfigurationCluster2AAA) |
| 106 | + .skip_configuration() |
| 107 | + .add_to_registry(replacement_cluster=RespondingTuyaMCUCluster) |
| 108 | +) |
| 109 | + |
| 110 | + |
64 | 111 | (
|
65 | 112 | TuyaQuirkBuilder("_TZE200_yjjdcqsq", "TS0601")
|
66 | 113 | .applies_to("_TZE200_9yapgbuv", "TS0601")
|
|
0 commit comments