Skip to content

Commit

Permalink
Add support for water heater platform #246
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed May 23, 2024
1 parent 5b41531 commit 6e7d36a
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 55 deletions.
5 changes: 5 additions & 0 deletions custom_components/localtuya/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"Siren": Platform.SIREN,
"Switch": Platform.SWITCH,
"Vacuum": Platform.VACUUM,
"Water Heater": Platform.WATER_HEATER,
}

ATTR_CURRENT = "current"
Expand Down Expand Up @@ -182,6 +183,10 @@
CONF_JAMMED_DP = "jammed_dp"
CONF_LOCK_STATE_DP = "lock_state_dp"

# Water Heater
CONF_TARGET_TEMPERATURE_LOW_DP = "target_temperature_low_dp"
CONF_TARGET_TEMPERATURE_HIGH_DP = "target_temperature_high_dp"

# States
ATTR_STATE = "raw_state"
CONF_RESTORE_ON_RECONNECT = "restore_on_reconnect"
Expand Down
2 changes: 2 additions & 0 deletions custom_components/localtuya/core/ha_entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from .switches import SWITCHES
from .vacuums import VACUUMS
from .locks import LOCKS
from .water_heaters import WATER_HEATERS

# The supported PLATFORMS [ Platform: Data ]
DATA_PLATFORMS = {
Expand All @@ -67,6 +68,7 @@
Platform.SIREN: SIRENS,
Platform.SWITCH: SWITCHES,
Platform.VACUUM: VACUUMS,
Platform.WATER_HEATER: WATER_HEATERS,
}

_LOGGER = logging.getLogger(__name__)
Expand Down
2 changes: 2 additions & 0 deletions custom_components/localtuya/core/ha_entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,14 @@ class DPCode(StrEnum):
TEMP_CURRENT = "temp_current" # Current temperature in °C
TEMP_CURRENT_F = "temp_current_f" # Current temperature in °F
TEMP_INDOOR = "temp_indoor" # Indoor temperature in °C
TEMP_LOW = "temp_low"
TEMP_PERIODIC_REPORT = "temp_periodic_report"
TEMP_SENSITIVITY = "temp_sensitivity"
TEMP_SET = "temp_set" # Set the temperature in °C
TEMP_SET_F = "temp_set_f" # Set the temperature in °F
TEMP_STATUS = "temp_status"
TEMP_UNIT_CONVERT = "temp_unit_convert" # Temperature unit switching
TEMP_UP = "temp_up"
TEMP_VALUE = "temp_value" # Color temperature
TEMP_VALUE_V2 = "temp_value_v2"
TIM = "tim" # Ikuu SXSEN003PIR IP65 Motion Detector (Wi-Fi)
Expand Down
102 changes: 52 additions & 50 deletions custom_components/localtuya/core/ha_entities/climates.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,58 +148,60 @@ def localtuya_climate(
),
# Heater
# https://developer.tuya.com/en/docs/iot/f?id=K9gf46epy4j82
"qn": (
LocalTuyaEntity(
id=DPCode.SWITCH,
target_temperature_dp=(DPCode.TEMP_SET, DPCode.TEMP_SET_F),
current_temperature_dp=(DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F),
hvac_mode_dp=DPCode.SWITCH,
hvac_action_dp=(DPCode.WORK_STATE, DPCode.WORK_MODE, DPCode.WORK_STATUS),
preset_dp=DPCode.MODE,
fan_speed_dp=(DPCode.FAN_SPEED_ENUM, DPCode.WINDSPEED),
custom_configs=localtuya_climate(
hvac_mode_set={
HVACMode.OFF: False,
HVACMode.HEAT: True,
},
temp_step=1,
actions_set={
HVACAction.HEATING: True,
HVACAction.IDLE: False,
},
values_precsion=0.1,
target_precision=0.1,
preset_set={},
),
),
),
## Converted to Water Heaters
# "qn": (
# LocalTuyaEntity(
# id=DPCode.SWITCH,
# target_temperature_dp=(DPCode.TEMP_SET, DPCode.TEMP_SET_F),
# current_temperature_dp=(DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F),
# hvac_mode_dp=DPCode.SWITCH,
# hvac_action_dp=(DPCode.WORK_STATE, DPCode.WORK_MODE, DPCode.WORK_STATUS),
# preset_dp=DPCode.MODE,
# fan_speed_dp=(DPCode.FAN_SPEED_ENUM, DPCode.WINDSPEED),
# custom_configs=localtuya_climate(
# hvac_mode_set={
# HVACMode.OFF: False,
# HVACMode.HEAT: True,
# },
# temp_step=1,
# actions_set={
# HVACAction.HEATING: True,
# HVACAction.IDLE: False,
# },
# values_precsion=0.1,
# target_precision=0.1,
# preset_set={},
# ),
# ),
# ),
# Heater
# https://developer.tuya.com/en/docs/iot/categoryrs?id=Kaiuz0nfferyx
"rs": (
LocalTuyaEntity(
id=DPCode.SWITCH,
target_temperature_dp=(DPCode.TEMP_SET, DPCode.TEMP_SET_F),
current_temperature_dp=(DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F),
hvac_action_dp=(DPCode.WORK_STATE, DPCode.WORK_MODE, DPCode.WORK_STATUS),
preset_dp=DPCode.MODE,
fan_speed_dp=(DPCode.FAN_SPEED_ENUM, DPCode.WINDSPEED),
custom_configs=localtuya_climate(
hvac_mode_set={
HVACMode.OFF: "off",
HVACMode.HEAT: "hot",
},
temp_step=1,
actions_set={
HVACAction.HEATING: "heating",
HVACAction.IDLE: "warming",
},
unit=UNIT_C,
values_precsion=0.1,
target_precision=0.1,
preset_set={},
),
),
),
## Converted to Water Heaters
# "rs": (
# LocalTuyaEntity(
# id=DPCode.SWITCH,
# target_temperature_dp=(DPCode.TEMP_SET, DPCode.TEMP_SET_F),
# current_temperature_dp=(DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F),
# hvac_action_dp=(DPCode.WORK_STATE, DPCode.WORK_MODE, DPCode.WORK_STATUS),
# preset_dp=DPCode.MODE,
# fan_speed_dp=(DPCode.FAN_SPEED_ENUM, DPCode.WINDSPEED),
# custom_configs=localtuya_climate(
# hvac_mode_set={
# HVACMode.OFF: "off",
# HVACMode.HEAT: "hot",
# },
# temp_step=1,
# actions_set={
# HVACAction.HEATING: "heating",
# HVACAction.IDLE: "warming",
# },
# unit=UNIT_C,
# values_precsion=0.1,
# target_precision=0.1,
# preset_set={},
# ),
# ),
# ),
# Thermostat
# https://developer.tuya.com/en/docs/iot/f?id=K9gf45ld5l0t9
"wk": (
Expand Down
99 changes: 99 additions & 0 deletions custom_components/localtuya/core/ha_entities/water_heaters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
This a file contains available tuya data
https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq
Credits: official HA Tuya integration.
Modified by: xZetsubou
"""

from homeassistant.components.water_heater import (
DEFAULT_MAX_TEMP,
DEFAULT_MIN_TEMP,
)
from homeassistant.const import CONF_TEMPERATURE_UNIT

from .base import DPCode, LocalTuyaEntity, CLOUD_VALUE
from ...const import (
CONF_TARGET_TEMPERATURE_LOW_DP,
CONF_TARGET_TEMPERATURE_HIGH_DP,
CONF_PRECISION,
CONF_TARGET_PRECISION,
CONF_CURRENT_TEMPERATURE_DP,
CONF_MAX_TEMP,
CONF_MIN_TEMP,
CONF_TARGET_TEMPERATURE_DP,
CONF_MODES,
CONF_MODE_DP,
)


UNIT_C = "celsius"
UNIT_F = "fahrenheit"


def localtuya_water_heater(
modes={},
unit=None,
min_temperature=DEFAULT_MIN_TEMP,
max_temperature=DEFAULT_MAX_TEMP,
current_precsion=0.1,
target_precision=1,
) -> dict:
"""Create localtuya climate configs"""
data = {}
for key, conf in {
CONF_MODES: CLOUD_VALUE(modes, CONF_MODE_DP, "range", dict),
CONF_MIN_TEMP: CLOUD_VALUE(
min_temperature, CONF_TARGET_TEMPERATURE_DP, "min", scale=True
),
CONF_MAX_TEMP: CLOUD_VALUE(
max_temperature, CONF_TARGET_TEMPERATURE_DP, "max", scale=True
),
CONF_TEMPERATURE_UNIT: unit,
CONF_PRECISION: CLOUD_VALUE(
str(current_precsion), CONF_CURRENT_TEMPERATURE_DP, "scale", str
),
CONF_TARGET_PRECISION: CLOUD_VALUE(
str(target_precision), CONF_TARGET_TEMPERATURE_DP, "scale", str
),
}.items():
if conf is not None:
data.update({key: conf})

return data


WATER_HEATERS: dict[str, tuple[LocalTuyaEntity, ...]] = {
# Heater
# https://developer.tuya.com/en/docs/iot/f?id=K9gf46epy4j82
"qn": (
LocalTuyaEntity(
id=DPCode.SWITCH,
target_temperature_dp=(DPCode.TEMP_SET, DPCode.TEMP_SET_F),
current_temperature_dp=(DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F),
target_temperature_low_dp=(DPCode.TEMP_LOW, DPCode.LOWER_TEMP),
target_temperature_high_dp=(DPCode.TEMP_UP, DPCode.UPPER_TEMP),
mode_dp=DPCode.MODE,
fan_speed_dp=(DPCode.FAN_SPEED_ENUM, DPCode.WINDSPEED),
custom_configs=localtuya_water_heater(
current_precsion=0.1, target_precision=0.1
),
),
),
# Heater
# https://developer.tuya.com/en/docs/iot/categoryrs?id=Kaiuz0nfferyx
"rs": (
LocalTuyaEntity(
id=DPCode.SWITCH,
target_temperature_dp=(DPCode.TEMP_SET, DPCode.TEMP_SET_F),
current_temperature_dp=(DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F),
target_temperature_low_dp=(DPCode.TEMP_LOW, DPCode.LOWER_TEMP),
target_temperature_high_dp=(DPCode.TEMP_UP, DPCode.UPPER_TEMP),
mode_dp=DPCode.MODE,
fan_speed_dp=(DPCode.FAN_SPEED_ENUM, DPCode.WINDSPEED),
custom_configs=localtuya_water_heater(
current_precsion=0.1, target_precision=0.1
),
),
),
}
6 changes: 4 additions & 2 deletions custom_components/localtuya/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"docked_status_value": "Docked Status (comma-separated)",
"fault_dp": "Fault DP (usually 11)",
"battery_dp": "Battery status DP (usually 14)",
"mode_dp": "Mode DP (usually 27)",
"mode_dp": "Mode DP",
"modes": "Modes list",
"return_mode": "Return home mode",
"fan_speed_dp": "(Optional) Fan speeds DP",
Expand Down Expand Up @@ -242,7 +242,9 @@
"receive_dp":"Receiving signals DP. (default is 202)",
"key_study_dp":"(Optional) Key Study DP (usually 7)",
"lock_state_dp":"(Optional) Lock state DP",
"jammed_dp":"(Optional) Jam DP"
"jammed_dp":"(Optional) Jam DP",
"target_temperature_high_dp":"(Optional) Target Temperature High DP",
"target_temperature_low_dp":"(Optional) Target Temperature Low DP"
},
"data_description": {
"hvac_mode_set":"Each line represents [ hvac_mode: device_value ] [Supported HVAC Modes](https://developers.home-assistant.io/docs/core/entity/climate/#hvac-modes)",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/localtuya/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"docked_status_value": "Docked Status (comma-separated)",
"fault_dp": "Fault DP (usually 11)",
"battery_dp": "Battery status DP (usually 14)",
"mode_dp": "Mode DP (usually 27)",
"mode_dp": "Mode DP",
"modes": "Modes list",
"return_mode": "Return home mode",
"fan_speed_dp": "(Optional) Fan speeds DP",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/localtuya/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"docked_status_value": "Stan zadokowania (oddzielone przecinkami)",
"fault_dp": "DP błędu (zazwyczaj 11)",
"battery_dp": "DP statusu baterii (zazwyczaj 14)",
"mode_dp": "DP trybu (zazwyczaj 27)",
"mode_dp": "DP trybu",
"modes": "Lista trybów",
"return_mode": "Tryb powrotu do domu",
"fan_speed_dp": "(Opcjonalnie) DP prędkości wentylatora",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/localtuya/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"docked_status_value": "Docked Status (comma-separated)",
"fault_dp": "Fault DP (usually 11)",
"battery_dp": "Battery status DP (usually 14)",
"mode_dp": "Mode DP (usually 27)",
"mode_dp": "Mode DP ",
"modes": "Modes list",
"return_mode": "Return home mode",
"fan_speed_dp": "(Optional) Fan speeds DP",
Expand Down
Loading

0 comments on commit 6e7d36a

Please sign in to comment.