Skip to content

Commit

Permalink
Init Quirk
Browse files Browse the repository at this point in the history
  • Loading branch information
prairiesnpr committed Jan 12, 2025
1 parent 278817c commit 4e23f81
Showing 1 changed file with 26 additions and 149 deletions.
175 changes: 26 additions & 149 deletions zhaquirks/tuya/ts0601_sensor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""Tuya temp and humidity sensors."""

from zigpy.quirks.v2 import EntityPlatform, EntityType
from zigpy.quirks.v2.homeassistant import PERCENTAGE, UnitOfTemperature, UnitOfTime
from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
import zigpy.types as t
from zigpy.zcl import foundation

from zhaquirks.tuya import (
TUYA_SET_TIME,
TUYA_MCU_VERSION_REQ,
TUYA_QUERY_DATA,
TuyaPowerConfigurationCluster2AAA,
TuyaTimePayload,
)
from zhaquirks.tuya.builder import TuyaQuirkBuilder
from zhaquirks.tuya.mcu import TuyaMCUCluster
Expand Down Expand Up @@ -58,167 +56,46 @@ class TuyaNousTempHumiAlarm(t.enum8):
)


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

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

self.create_catching_task(
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)

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


# TH01Z - Temperature and humidity sensor with clock
(
TuyaQuirkBuilder("_TZE200_lve3dvpy", "TS0601")
.applies_to("_TZE200_c7emyjom", "TS0601")
.applies_to("_TZE200_locansqn", "TS0601")
.applies_to("_TZE200_qrztc3ev", "TS0601")
.applies_to("_TZE200_snloy4rw", "TS0601")
.applies_to("_TZE200_eanjj2pa", "TS0601")
.applies_to("_TZE200_ydrdfkim", "TS0601")
.applies_to("_TZE284_locansqn", "TS0601")
TuyaQuirkBuilder("_TZE204_upagmta9", "TS0601")
.tuya_temperature(dp_id=1, scale=10)
.tuya_humidity(dp_id=2)
.tuya_battery(dp_id=4)
.tuya_number(
dp_id=17,
attribute_name="temperature_report_interval",
type=t.uint16_t,
device_class=SensorDeviceClass.DURATION,
unit=UnitOfTime.MINUTES,
min_value=5,
max_value=120,
step=5,
entity_type=EntityType.CONFIG,
translation_key="temperature_report_interval",
fallback_name="Temperature report interval",
)
.tuya_number(
dp_id=18,
attribute_name="humidity_report_interval",
type=t.uint16_t,
device_class=SensorDeviceClass.DURATION,
unit=UnitOfTime.MINUTES,
min_value=5,
max_value=120,
step=5,
entity_type=EntityType.CONFIG,
translation_key="humidity_report_interval",
fallback_name="Humidity report interval",
)
.tuya_enum(
dp_id=9,
attribute_name="display_unit",
enum_class=TuyaTempUnitConvert,
entity_type=EntityType.CONFIG,
translation_key="display_unit",
fallback_name="Display unit",
)
.tuya_enum(
dp_id=14,
attribute_name="temperature_alarm",
enum_class=TuyaNousTempHumiAlarm,
entity_platform=EntityPlatform.SENSOR,
entity_type=EntityType.STANDARD,
translation_key="temperature_alarm",
fallback_name="Temperature alarm",
)
.tuya_number(
dp_id=10,
attribute_name="alarm_temperature_max",
type=t.uint16_t,
unit=UnitOfTemperature.CELSIUS,
min_value=-20,
max_value=60,
step=1,
multiplier=0.1,
entity_type=EntityType.CONFIG,
translation_key="alarm_temperature_max",
fallback_name="Alarm temperature max",
)
.tuya_number(
dp_id=11,
attribute_name="alarm_temperature_min",
type=t.uint16_t,
unit=UnitOfTemperature.CELSIUS,
min_value=-20,
max_value=60,
step=1,
multiplier=0.1,
entity_type=EntityType.CONFIG,
translation_key="alarm_temperature_min",
fallback_name="Alarm temperature min",
)
.tuya_number(
dp_id=19,
attribute_name="temperature_sensitivity",
type=t.uint16_t,
unit=UnitOfTemperature.CELSIUS,
min_value=0.1,
max_value=50,
step=0.1,
multiplier=0.1,
entity_type=EntityType.CONFIG,
translation_key="temperature_sensitivity",
fallback_name="Temperature sensitivity",
)
.tuya_enum(
dp_id=15,
attribute_name="humidity_alarm",
enum_class=TuyaNousTempHumiAlarm,
entity_platform=EntityPlatform.SENSOR,
entity_type=EntityType.STANDARD,
translation_key="humidity_alarm",
fallback_name="Humidity alarm",
)
.tuya_number(
dp_id=12,
attribute_name="alarm_humidity_max",
type=t.uint16_t,
unit=PERCENTAGE,
min_value=0,
max_value=100,
step=1,
entity_type=EntityType.CONFIG,
translation_key="alarm_humidity_max",
fallback_name="Alarm humidity max",
)
.tuya_number(
dp_id=13,
attribute_name="alarm_humidity_min",
type=t.uint16_t,
unit=PERCENTAGE,
min_value=0,
max_value=100,
step=1,
entity_type=EntityType.CONFIG,
translation_key="alarm_humidity_min",
fallback_name="Alarm humidity min",
)
.tuya_number(
dp_id=20,
attribute_name="humidity_sensitivity",
type=t.uint16_t,
unit=PERCENTAGE,
min_value=1,
max_value=100,
step=1,
entity_type=EntityType.CONFIG,
translation_key="humidity_sensitivity",
fallback_name="Humidity sensitivity",
.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(mcu_cluster=NoManufTimeTuyaMCUCluster)
.add_to_registry(mcu_cluster=RespondingTuyaMCUCluster)
)


Expand Down

0 comments on commit 4e23f81

Please sign in to comment.