Skip to content

Commit

Permalink
Init quirk
Browse files Browse the repository at this point in the history
  • Loading branch information
prairiesnpr committed Jan 25, 2025
1 parent d9481d3 commit a3b7768
Showing 1 changed file with 242 additions and 28 deletions.
270 changes: 242 additions & 28 deletions zhaquirks/tuya/ts0601_trv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from typing import Optional, Union

from zigpy.profiles import zha
from zigpy.quirks.v2.homeassistant import UnitOfTemperature
from zigpy.quirks.v2 import EntityPlatform, EntityType
from zigpy.quirks.v2.homeassistant import PERCENTAGE, UnitOfTemperature
from zigpy.quirks.v2.homeassistant.binary_sensor import BinarySensorDeviceClass
from zigpy.quirks.v2.homeassistant.sensor import SensorStateClass
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import (
Expand Down Expand Up @@ -54,6 +56,54 @@
_LOGGER = logging.getLogger(__name__)


class TuyaWindowOpen(t.enum8):
"""Tuya window open state."""

Closed = 0x00
Open = 0x01


class TuyaDisplayBrightness(t.enum8):
"""Tuya display brightness mode."""

High = 0x00
Medium = 0x01
Low = 0x02


class TuyaMotorThrust(t.enum8):
"""Tuya motor thrust mode."""

Strong = 0x00
Middle = 0x01
Weak = 0x02


class TuyaDisplayOrientation(t.enum8):
"""Tuya display orientation mode."""

Up = 0x00
Down = 0x01


class TuyaHysteresis(t.enum8):
"""Tuya hysteresis mode."""

Comfort = 0x00
Eco = 0x01


class TuyaPresetMode(t.enum8):
"""Tuya preset mode."""

Off = 0x00
Antifrost = 0x01
Eco = 0x02
Comfort = 0x03
Auto = 0x04
Heat = 0x05


class TuyaThermostatSystemMode(t.enum8):
"""Tuya thermostat system mode enum."""

Expand Down Expand Up @@ -1800,6 +1850,38 @@ def __init__(self, *args, **kwargs):
}


base_tuya_trv = (
TuyaQuirkBuilder()
.tuya_dp(
dp_id=3,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.running_state.name,
converter=lambda x: 0x01 if not x else 0x00, # Heat, Idle
)
.tuya_dp(
dp_id=4,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.occupied_heating_setpoint.name,
converter=lambda x: x * 10,
dp_converter=lambda x: x // 10,
)
.tuya_dp(
dp_id=5,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.local_temperature.name,
converter=lambda x: x * 10,
)
.tuya_dp(
dp_id=47,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.local_temperature_calibration.name,
converter=lambda x: x,
dp_converter=lambda x: x + 0x100000000 if x < 0 else x,
)
.adds(TuyaThermostatV2)
.skip_configuration()
)

(
TuyaQuirkBuilder("_TZE204_rtrmfadk", "TS0601")
.tuya_dp(
Expand Down Expand Up @@ -1905,7 +1987,9 @@ def __init__(self, *args, **kwargs):


(
TuyaQuirkBuilder("_TZE200_bvu2wnxz", "TS0601")
base_tuya_trv.clone()
# DPs 3, 4, 5, and 47 from base
.applies_to("_TZE200_bvu2wnxz", "TS0601")
.applies_to("_TZE200_6rdj8dzm", "TS0601")
.applies_to("_TZE200_9xfjixap", "TS0601")
.applies_to("_TZE200_p3dbf6qs", "TS0601")
Expand Down Expand Up @@ -1933,32 +2017,6 @@ def __init__(self, *args, **kwargs):
Thermostat.SystemMode.Off: TuyaThermostatSystemMode.Off,
}[x],
)
.tuya_dp(
dp_id=3,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.running_state.name,
converter=lambda x: 0x01 if not x else 0x00, # Heat, Idle
)
.tuya_dp(
dp_id=4,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.occupied_heating_setpoint.name,
converter=lambda x: x * 10,
dp_converter=lambda x: x // 10,
)
.tuya_dp(
dp_id=5,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.local_temperature.name,
converter=lambda x: x * 10,
)
.tuya_dp(
dp_id=47,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.local_temperature_calibration.name,
converter=lambda x: x,
dp_converter=lambda x: x + 0x100000000 if x < 0 else x,
)
.tuya_switch(
dp_id=7,
attribute_name="child_lock",
Expand Down Expand Up @@ -1987,3 +2045,159 @@ def __init__(self, *args, **kwargs):
.skip_configuration()
.add_to_registry()
)

# Moes TRV602Z and TRV801Z
(
base_tuya_trv.clone()
.appliess_to("_TZE204_qyr2m29i", "TS0601")
.applies_to("_TZE204_ltwbm23f", "TS0601")
# DPs 3, 4, 5, and 47 from base
# preset mode and system mode are on the same datapoint, using only system mode
# until we support multiple values on a single DP
# .tuya_enum(
# dp_id=2,
# attribute_name="preset_mode",
# enum_class=TuyaPresetMode,
# translation_key="preset_mode",
# fallback_name="Preset mode",
# )
.tuya_dp(
dp_id=2,
ep_attribute=TuyaThermostatV2.ep_attribute,
attribute_name=TuyaThermostatV2.AttributeDefs.system_mode.name,
converter=lambda x: {
TuyaPresetMode.Auto: Thermostat.SystemMode.Auto,
TuyaPresetMode.Antifrost: Thermostat.SystemMode.Auto,
TuyaPresetMode.Eco: Thermostat.SystemMode.Auto,
TuyaPresetMode.Comfort: Thermostat.SystemMode.Auto,
TuyaPresetMode.Heat: Thermostat.SystemMode.Heat,
TuyaPresetMode.Off: Thermostat.SystemMode.Off,
}[x],
dp_converter=lambda x: {
Thermostat.SystemMode.Auto: TuyaPresetMode.Auto,
Thermostat.SystemMode.Heat: TuyaPresetMode.Heat,
Thermostat.SystemMode.Off: TuyaPresetMode.Off,
}[x],
)
.tuya_battery(dp_id=6)
.tuya_switch(
dp_id=7,
attribute_name="child_lock",
translation_key="child_lock",
fallback_name="Child lock",
)
.tuya_number(
dp_id=9,
attribute_name="max_temperature",
type=t.uint16_t,
unit=UnitOfTemperature.CELSIUS,
min_value=15,
max_value=35,
step=1,
scale=0.1,
translation_key="max_temperature",
fallback_name="Max temperature",
)
.tuya_number(
dp_id=10,
attribute_name="min_temperature",
type=t.uint16_t,
unit=UnitOfTemperature.CELSIUS,
min_value=1,
max_value=15,
step=1,
scale=0.1,
translation_key="min_temperature",
fallback_name="Min temperature",
)
.tuya_switch(
dp_id=14,
attribute_name="window_detection",
translation_key="window_detection",
fallback_name="Open window detection",
)
.tuya_enum(
dp_id=15,
attribute_name="window_open",
enum_class=TuyaWindowOpen,
entity_platform=EntityPlatform.SENSOR,
entity_type=EntityType.STANDARD,
translation_key="window_open",
fallback_name="Widow open",
)
.tuya_enum(
dp_id=110,
attribute_name="motor_thrust",
enum_class=TuyaMotorThrust,
translation_key="motor_thrust",
fallback_name="Motor thrust",
)
.tuya_enum(
dp_id=111,
attribute_name="display_brightness",
enum_class=TuyaDisplayBrightness,
translation_key="display_brightness",
fallback_name="Display brightness",
)
.tuya_enum(
dp_id=113,
attribute_name="display_orientation",
enum_class=TuyaDisplayOrientation,
translation_key="display_orientation",
fallback_name="Display orientation",
)
.tuya_sensor(
dp_id=114,
attribute_name="valve_position",
type=t.int16s,
divisor=10,
state_class=SensorStateClass.MEASUREMENT,
unit=PERCENTAGE,
translation_key="valve_position",
fallback_name="Valve position",
)
.tuya_number(
dp_id=119,
attribute_name="comfort_temperature",
type=t.uint16_t,
unit=UnitOfTemperature.CELSIUS,
min_value=5,
max_value=30,
step=1,
scale=0.1,
translation_key="comfort_temperature",
fallback_name="Comfort temperature",
)
.tuya_number(
dp_id=120,
attribute_name="eco_temperature",
type=t.uint16_t,
unit=UnitOfTemperature.CELSIUS,
min_value=5,
max_value=30,
step=1,
scale=0.1,
translation_key="eco_temperature",
fallback_name="Eco temperature",
)
.tuya_number(
dp_id=121,
attribute_name="holiday_temperature",
type=t.uint16_t,
unit=UnitOfTemperature.CELSIUS,
min_value=5,
max_value=30,
step=1,
scale=0.1,
translation_key="holiday_temperature",
fallback_name="Holiday temperature",
)
.tuya_enum(
dp_id=127,
attribute_name="hysteresis_mode",
enum_class=TuyaDisplayOrientation,
translation_key="hysteresis_mode",
fallback_name="Hysteresis mode",
)
.add_to_registry()
)

0 comments on commit a3b7768

Please sign in to comment.