2021-09-30 10:02:56 +00:00
|
|
|
"""Support for Tuya Climate."""
|
2020-10-28 01:26:18 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from tuya_iot import TuyaDevice, TuyaDeviceManager
|
|
|
|
|
|
|
|
from homeassistant.components.climate import DOMAIN as DEVICE_DOMAIN, ClimateEntity
|
2019-02-14 19:34:43 +00:00
|
|
|
from homeassistant.components.climate.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
HVAC_MODE_AUTO,
|
|
|
|
HVAC_MODE_COOL,
|
2021-09-30 10:02:56 +00:00
|
|
|
HVAC_MODE_DRY,
|
2019-07-31 19:25:30 +00:00
|
|
|
HVAC_MODE_FAN_ONLY,
|
|
|
|
HVAC_MODE_HEAT,
|
2019-12-05 05:11:13 +00:00
|
|
|
HVAC_MODE_OFF,
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_FAN_MODE,
|
2021-09-30 10:02:56 +00:00
|
|
|
SUPPORT_SWING_MODE,
|
|
|
|
SUPPORT_TARGET_HUMIDITY,
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_TARGET_TEMPERATURE,
|
|
|
|
)
|
2021-09-30 10:02:56 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2020-05-11 03:01:00 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2021-09-30 10:02:56 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2018-07-17 18:33:54 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
from .base import TuyaHaEntity
|
2020-10-28 01:26:18 +00:00
|
|
|
from .const import (
|
|
|
|
DOMAIN,
|
2021-09-30 10:02:56 +00:00
|
|
|
TUYA_DEVICE_MANAGER,
|
2020-10-28 01:26:18 +00:00
|
|
|
TUYA_DISCOVERY_NEW,
|
2021-09-30 10:02:56 +00:00
|
|
|
TUYA_HA_DEVICES,
|
|
|
|
TUYA_HA_TUYA_MAP,
|
2020-10-28 01:26:18 +00:00
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
# Air Conditioner
|
|
|
|
# https://developer.tuya.com/en/docs/iot/f?id=K9gf46qujdmwb
|
|
|
|
DPCODE_SWITCH = "switch"
|
|
|
|
DPCODE_TEMP_SET = "temp_set"
|
|
|
|
DPCODE_TEMP_SET_F = "temp_set_f"
|
|
|
|
DPCODE_MODE = "mode"
|
|
|
|
DPCODE_HUMIDITY_SET = "humidity_set"
|
|
|
|
DPCODE_FAN_SPEED_ENUM = "fan_speed_enum"
|
|
|
|
|
|
|
|
# Temperature unit
|
|
|
|
DPCODE_TEMP_UNIT_CONVERT = "temp_unit_convert"
|
|
|
|
DPCODE_C_F = "c_f"
|
|
|
|
|
|
|
|
# swing flap switch
|
|
|
|
DPCODE_SWITCH_HORIZONTAL = "switch_horizontal"
|
|
|
|
DPCODE_SWITCH_VERTICAL = "switch_vertical"
|
|
|
|
|
|
|
|
# status
|
|
|
|
DPCODE_TEMP_CURRENT = "temp_current"
|
|
|
|
DPCODE_TEMP_CURRENT_F = "temp_current_f"
|
|
|
|
DPCODE_HUMIDITY_CURRENT = "humidity_current"
|
|
|
|
|
|
|
|
SWING_OFF = "swing_off"
|
|
|
|
SWING_VERTICAL = "swing_vertical"
|
|
|
|
SWING_HORIZONTAL = "swing_horizontal"
|
|
|
|
SWING_BOTH = "swing_both"
|
|
|
|
|
|
|
|
DEFAULT_MIN_TEMP = 7
|
|
|
|
DEFAULT_MAX_TEMP = 35
|
|
|
|
|
|
|
|
TUYA_HVAC_TO_HA = {
|
|
|
|
"hot": HVAC_MODE_HEAT,
|
|
|
|
"cold": HVAC_MODE_COOL,
|
|
|
|
"wet": HVAC_MODE_DRY,
|
|
|
|
"wind": HVAC_MODE_FAN_ONLY,
|
|
|
|
"auto": HVAC_MODE_AUTO,
|
2018-07-17 18:33:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
TUYA_SUPPORT_TYPE = {
|
|
|
|
"kt", # Air conditioner
|
|
|
|
"qn", # Heater
|
|
|
|
"wk", # Thermostat
|
|
|
|
}
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
|
|
|
"""Set up tuya climate dynamically through tuya discovery."""
|
|
|
|
_LOGGER.debug("climate init")
|
2020-05-11 03:01:00 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
hass.data[DOMAIN][entry.entry_id][TUYA_HA_TUYA_MAP][
|
|
|
|
DEVICE_DOMAIN
|
|
|
|
] = TUYA_SUPPORT_TYPE
|
2020-05-11 03:01:00 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
@callback
|
|
|
|
def async_discover_device(dev_ids: list[str]) -> None:
|
|
|
|
"""Discover and add a discovered tuya climate."""
|
|
|
|
_LOGGER.debug("climate add-> %s", dev_ids)
|
2020-05-11 03:01:00 +00:00
|
|
|
if not dev_ids:
|
|
|
|
return
|
2021-09-30 10:02:56 +00:00
|
|
|
entities = _setup_entities(hass, entry, dev_ids)
|
2020-05-11 03:01:00 +00:00
|
|
|
async_add_entities(entities)
|
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
entry.async_on_unload(
|
|
|
|
async_dispatcher_connect(
|
|
|
|
hass, TUYA_DISCOVERY_NEW.format(DEVICE_DOMAIN), async_discover_device
|
|
|
|
)
|
2020-05-11 03:01:00 +00:00
|
|
|
)
|
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
device_manager = hass.data[DOMAIN][entry.entry_id][TUYA_DEVICE_MANAGER]
|
|
|
|
device_ids = []
|
|
|
|
for (device_id, device) in device_manager.device_map.items():
|
|
|
|
if device.category in TUYA_SUPPORT_TYPE:
|
|
|
|
device_ids.append(device_id)
|
|
|
|
async_discover_device(device_ids)
|
|
|
|
|
|
|
|
|
|
|
|
def _setup_entities(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, device_ids: list[str]
|
|
|
|
) -> list[Entity]:
|
|
|
|
"""Set up Tuya Climate."""
|
|
|
|
device_manager = hass.data[DOMAIN][entry.entry_id][TUYA_DEVICE_MANAGER]
|
|
|
|
entities: list[Entity] = []
|
|
|
|
for device_id in device_ids:
|
|
|
|
device = device_manager.device_map[device_id]
|
2020-05-11 12:45:12 +00:00
|
|
|
if device is None:
|
2018-07-17 18:33:54 +00:00
|
|
|
continue
|
2021-09-30 10:02:56 +00:00
|
|
|
entities.append(TuyaHaClimate(device, device_manager))
|
|
|
|
hass.data[DOMAIN][entry.entry_id][TUYA_HA_DEVICES].add(device_id)
|
2020-05-11 03:01:00 +00:00
|
|
|
return entities
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
class TuyaHaClimate(TuyaHaEntity, ClimateEntity):
|
|
|
|
"""Tuya Switch Device."""
|
2018-07-17 18:33:54 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
def __init__(self, device: TuyaDevice, device_manager: TuyaDeviceManager) -> None:
|
|
|
|
"""Init Tuya Ha Climate."""
|
|
|
|
super().__init__(device, device_manager)
|
|
|
|
if DPCODE_C_F in self.tuya_device.status:
|
|
|
|
self.dp_temp_unit = DPCODE_C_F
|
2020-10-28 01:26:18 +00:00
|
|
|
else:
|
2021-09-30 10:02:56 +00:00
|
|
|
self.dp_temp_unit = DPCODE_TEMP_UNIT_CONVERT
|
|
|
|
|
|
|
|
def get_temp_set_scale(self) -> int | None:
|
|
|
|
"""Get temperature set scale."""
|
|
|
|
dp_temp_set = DPCODE_TEMP_SET if self.is_celsius() else DPCODE_TEMP_SET_F
|
|
|
|
temp_set_value_range_item = self.tuya_device.status_range.get(dp_temp_set)
|
|
|
|
if not temp_set_value_range_item:
|
|
|
|
return None
|
|
|
|
|
|
|
|
temp_set_value_range = json.loads(temp_set_value_range_item.values)
|
|
|
|
return temp_set_value_range.get("scale")
|
|
|
|
|
|
|
|
def get_temp_current_scale(self) -> int | None:
|
|
|
|
"""Get temperature current scale."""
|
|
|
|
dp_temp_current = (
|
|
|
|
DPCODE_TEMP_CURRENT if self.is_celsius() else DPCODE_TEMP_CURRENT_F
|
|
|
|
)
|
|
|
|
temp_current_value_range_item = self.tuya_device.status_range.get(
|
|
|
|
dp_temp_current
|
2020-10-28 01:26:18 +00:00
|
|
|
)
|
2021-09-30 10:02:56 +00:00
|
|
|
if not temp_current_value_range_item:
|
|
|
|
return None
|
|
|
|
|
|
|
|
temp_current_value_range = json.loads(temp_current_value_range_item.values)
|
|
|
|
return temp_current_value_range.get("scale")
|
|
|
|
|
|
|
|
# Functions
|
|
|
|
|
|
|
|
def set_hvac_mode(self, hvac_mode: str) -> None:
|
|
|
|
"""Set new target hvac mode."""
|
|
|
|
commands = []
|
|
|
|
if hvac_mode == HVAC_MODE_OFF:
|
|
|
|
commands.append({"code": DPCODE_SWITCH, "value": False})
|
|
|
|
else:
|
|
|
|
commands.append({"code": DPCODE_SWITCH, "value": True})
|
|
|
|
|
|
|
|
for tuya_mode, ha_mode in TUYA_HVAC_TO_HA.items():
|
|
|
|
if ha_mode == hvac_mode:
|
|
|
|
commands.append({"code": DPCODE_MODE, "value": tuya_mode})
|
|
|
|
break
|
|
|
|
|
|
|
|
self._send_command(commands)
|
|
|
|
|
|
|
|
def set_fan_mode(self, fan_mode: str) -> None:
|
|
|
|
"""Set new target fan mode."""
|
|
|
|
self._send_command([{"code": DPCODE_FAN_SPEED_ENUM, "value": fan_mode}])
|
|
|
|
|
|
|
|
def set_humidity(self, humidity: float) -> None:
|
|
|
|
"""Set new target humidity."""
|
|
|
|
self._send_command([{"code": DPCODE_HUMIDITY_SET, "value": int(humidity)}])
|
|
|
|
|
|
|
|
def set_swing_mode(self, swing_mode: str) -> None:
|
|
|
|
"""Set new target swing operation."""
|
|
|
|
if swing_mode == SWING_BOTH:
|
|
|
|
commands = [
|
|
|
|
{"code": DPCODE_SWITCH_VERTICAL, "value": True},
|
|
|
|
{"code": DPCODE_SWITCH_HORIZONTAL, "value": True},
|
|
|
|
]
|
|
|
|
elif swing_mode == SWING_HORIZONTAL:
|
|
|
|
commands = [
|
|
|
|
{"code": DPCODE_SWITCH_VERTICAL, "value": False},
|
|
|
|
{"code": DPCODE_SWITCH_HORIZONTAL, "value": True},
|
|
|
|
]
|
|
|
|
elif swing_mode == SWING_VERTICAL:
|
|
|
|
commands = [
|
|
|
|
{"code": DPCODE_SWITCH_VERTICAL, "value": True},
|
|
|
|
{"code": DPCODE_SWITCH_HORIZONTAL, "value": False},
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
commands = [
|
|
|
|
{"code": DPCODE_SWITCH_VERTICAL, "value": False},
|
|
|
|
{"code": DPCODE_SWITCH_HORIZONTAL, "value": False},
|
|
|
|
]
|
2020-10-28 01:26:18 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
self._send_command(commands)
|
|
|
|
|
|
|
|
def set_temperature(self, **kwargs: Any) -> None:
|
|
|
|
"""Set new target temperature."""
|
|
|
|
_LOGGER.debug("climate temp-> %s", kwargs)
|
|
|
|
code = DPCODE_TEMP_SET if self.is_celsius() else DPCODE_TEMP_SET_F
|
|
|
|
temp_set_scale = self.get_temp_set_scale()
|
|
|
|
if not temp_set_scale:
|
2018-07-17 18:33:54 +00:00
|
|
|
return
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
self._send_command(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"code": code,
|
|
|
|
"value": int(kwargs["temperature"] * (10 ** temp_set_scale)),
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
def is_celsius(self) -> bool:
|
|
|
|
"""Return True if device reports in Celsius."""
|
|
|
|
if (
|
|
|
|
self.dp_temp_unit in self.tuya_device.status
|
|
|
|
and self.tuya_device.status.get(self.dp_temp_unit).lower() == "c"
|
|
|
|
):
|
|
|
|
return True
|
|
|
|
if (
|
|
|
|
DPCODE_TEMP_SET in self.tuya_device.status
|
|
|
|
or DPCODE_TEMP_CURRENT in self.tuya_device.status
|
|
|
|
):
|
|
|
|
return True
|
|
|
|
return False
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def temperature_unit(self) -> str:
|
|
|
|
"""Return true if fan is on."""
|
|
|
|
if self.is_celsius():
|
|
|
|
return TEMP_CELSIUS
|
|
|
|
return TEMP_FAHRENHEIT
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def current_temperature(self) -> float | None:
|
|
|
|
"""Return the current temperature."""
|
|
|
|
if (
|
|
|
|
DPCODE_TEMP_CURRENT not in self.tuya_device.status
|
|
|
|
and DPCODE_TEMP_CURRENT_F not in self.tuya_device.status
|
|
|
|
):
|
|
|
|
return None
|
|
|
|
|
|
|
|
temp_current_scale = self.get_temp_current_scale()
|
|
|
|
if not temp_current_scale:
|
|
|
|
return None
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
if self.is_celsius():
|
|
|
|
temperature = self.tuya_device.status.get(DPCODE_TEMP_CURRENT)
|
|
|
|
if not temperature:
|
|
|
|
return None
|
|
|
|
return temperature * 1.0 / (10 ** temp_current_scale)
|
2020-10-28 01:26:18 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
temperature = self.tuya_device.status.get(DPCODE_TEMP_CURRENT_F)
|
|
|
|
if not temperature:
|
2018-07-17 18:33:54 +00:00
|
|
|
return None
|
2021-09-30 10:02:56 +00:00
|
|
|
return temperature * 1.0 / (10 ** temp_current_scale)
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def current_humidity(self) -> int:
|
|
|
|
"""Return the current humidity."""
|
|
|
|
return int(self.tuya_device.status.get(DPCODE_HUMIDITY_CURRENT, 0))
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def target_temperature(self) -> float | None:
|
|
|
|
"""Return the temperature currently set to be reached."""
|
|
|
|
temp_set_scale = self.get_temp_set_scale()
|
|
|
|
if temp_set_scale is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
dpcode_temp_set = self.tuya_device.status.get(DPCODE_TEMP_SET)
|
|
|
|
if dpcode_temp_set is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return dpcode_temp_set * 1.0 / (10 ** temp_set_scale)
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def max_temp(self) -> float:
|
|
|
|
"""Return the maximum temperature."""
|
|
|
|
scale = self.get_temp_set_scale()
|
|
|
|
if scale is None:
|
|
|
|
return DEFAULT_MAX_TEMP
|
|
|
|
|
|
|
|
if self.is_celsius():
|
|
|
|
if DPCODE_TEMP_SET not in self.tuya_device.function:
|
|
|
|
return DEFAULT_MAX_TEMP
|
|
|
|
|
|
|
|
function_item = self.tuya_device.function.get(DPCODE_TEMP_SET)
|
|
|
|
if function_item is None:
|
|
|
|
return DEFAULT_MAX_TEMP
|
|
|
|
|
|
|
|
temp_value = json.loads(function_item.values)
|
|
|
|
|
|
|
|
temp_max = temp_value.get("max")
|
|
|
|
if temp_max is None:
|
|
|
|
return DEFAULT_MAX_TEMP
|
|
|
|
return temp_max * 1.0 / (10 ** scale)
|
|
|
|
if DPCODE_TEMP_SET_F not in self.tuya_device.function:
|
|
|
|
return DEFAULT_MAX_TEMP
|
|
|
|
|
|
|
|
function_item_f = self.tuya_device.function.get(DPCODE_TEMP_SET_F)
|
|
|
|
if function_item_f is None:
|
|
|
|
return DEFAULT_MAX_TEMP
|
|
|
|
|
|
|
|
temp_value_f = json.loads(function_item_f.values)
|
|
|
|
|
|
|
|
temp_max_f = temp_value_f.get("max")
|
|
|
|
if temp_max_f is None:
|
|
|
|
return DEFAULT_MAX_TEMP
|
|
|
|
return temp_max_f * 1.0 / (10 ** scale)
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def min_temp(self) -> float:
|
|
|
|
"""Return the minimum temperature."""
|
|
|
|
temp_set_scal = self.get_temp_set_scale()
|
|
|
|
if temp_set_scal is None:
|
|
|
|
return DEFAULT_MIN_TEMP
|
|
|
|
|
|
|
|
if self.is_celsius():
|
|
|
|
if DPCODE_TEMP_SET not in self.tuya_device.function:
|
|
|
|
return DEFAULT_MIN_TEMP
|
|
|
|
|
|
|
|
function_temp_item = self.tuya_device.function.get(DPCODE_TEMP_SET)
|
|
|
|
if function_temp_item is None:
|
|
|
|
return DEFAULT_MIN_TEMP
|
|
|
|
temp_value = json.loads(function_temp_item.values)
|
|
|
|
temp_min = temp_value.get("min")
|
|
|
|
if temp_min is None:
|
|
|
|
return DEFAULT_MIN_TEMP
|
|
|
|
return temp_min * 1.0 / (10 ** temp_set_scal)
|
|
|
|
|
|
|
|
if DPCODE_TEMP_SET_F not in self.tuya_device.function:
|
|
|
|
return DEFAULT_MIN_TEMP
|
|
|
|
|
|
|
|
temp_value_temp_f = self.tuya_device.function.get(DPCODE_TEMP_SET_F)
|
|
|
|
if temp_value_temp_f is None:
|
|
|
|
return DEFAULT_MIN_TEMP
|
|
|
|
temp_value_f = json.loads(temp_value_temp_f.values)
|
|
|
|
|
|
|
|
temp_min_f = temp_value_f.get("min")
|
|
|
|
if temp_min_f is None:
|
|
|
|
return DEFAULT_MIN_TEMP
|
|
|
|
|
|
|
|
return temp_min_f * 1.0 / (10 ** temp_set_scal)
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def target_temperature_step(self) -> float | None:
|
|
|
|
"""Return target temperature setp."""
|
|
|
|
if (
|
|
|
|
DPCODE_TEMP_SET not in self.tuya_device.status_range
|
|
|
|
and DPCODE_TEMP_SET_F not in self.tuya_device.status_range
|
|
|
|
):
|
|
|
|
return 1.0
|
|
|
|
temp_set_value_range = json.loads(
|
|
|
|
self.tuya_device.status_range.get(
|
|
|
|
DPCODE_TEMP_SET if self.is_celsius() else DPCODE_TEMP_SET_F
|
|
|
|
).values
|
|
|
|
)
|
|
|
|
step = temp_set_value_range.get("step")
|
|
|
|
if step is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
temp_set_scale = self.get_temp_set_scale()
|
|
|
|
if temp_set_scale is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return step * 1.0 / (10 ** temp_set_scale)
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def target_humidity(self) -> int:
|
|
|
|
"""Return target humidity."""
|
|
|
|
return int(self.tuya_device.status.get(DPCODE_HUMIDITY_SET, 0))
|
2018-07-17 18:33:54 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
@property
|
|
|
|
def hvac_mode(self) -> str:
|
|
|
|
"""Return hvac mode."""
|
|
|
|
if not self.tuya_device.status.get(DPCODE_SWITCH, False):
|
|
|
|
return HVAC_MODE_OFF
|
|
|
|
if DPCODE_MODE not in self.tuya_device.status:
|
|
|
|
return HVAC_MODE_OFF
|
|
|
|
if self.tuya_device.status.get(DPCODE_MODE) is not None:
|
|
|
|
return TUYA_HVAC_TO_HA[self.tuya_device.status[DPCODE_MODE]]
|
|
|
|
return HVAC_MODE_OFF
|
2018-07-17 18:33:54 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
@property
|
|
|
|
def hvac_modes(self) -> list[str]:
|
|
|
|
"""Return hvac modes for select."""
|
|
|
|
if DPCODE_MODE not in self.tuya_device.function:
|
|
|
|
return []
|
|
|
|
modes = json.loads(self.tuya_device.function.get(DPCODE_MODE, {}).values).get(
|
|
|
|
"range"
|
|
|
|
)
|
2018-07-17 18:33:54 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
hvac_modes = [HVAC_MODE_OFF]
|
|
|
|
for tuya_mode, ha_mode in TUYA_HVAC_TO_HA.items():
|
|
|
|
if tuya_mode in modes:
|
|
|
|
hvac_modes.append(ha_mode)
|
2018-07-17 18:33:54 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
return hvac_modes
|
2018-07-17 18:33:54 +00:00
|
|
|
|
2021-09-30 10:02:56 +00:00
|
|
|
@property
|
|
|
|
def fan_mode(self) -> str | None:
|
|
|
|
"""Return fan mode."""
|
|
|
|
return self.tuya_device.status.get(DPCODE_FAN_SPEED_ENUM)
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def fan_modes(self) -> list[str]:
|
|
|
|
"""Return fan modes for select."""
|
2021-10-05 10:59:51 +00:00
|
|
|
fan_speed_device_function = self.tuya_device.function.get(DPCODE_FAN_SPEED_ENUM)
|
|
|
|
if not fan_speed_device_function:
|
|
|
|
return []
|
|
|
|
return json.loads(fan_speed_device_function.values).get("range", [])
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def swing_mode(self) -> str:
|
|
|
|
"""Return swing mode."""
|
|
|
|
mode = 0
|
|
|
|
if (
|
|
|
|
DPCODE_SWITCH_HORIZONTAL in self.tuya_device.status
|
|
|
|
and self.tuya_device.status.get(DPCODE_SWITCH_HORIZONTAL)
|
|
|
|
):
|
|
|
|
mode += 1
|
|
|
|
if (
|
|
|
|
DPCODE_SWITCH_VERTICAL in self.tuya_device.status
|
|
|
|
and self.tuya_device.status.get(DPCODE_SWITCH_VERTICAL)
|
|
|
|
):
|
|
|
|
mode += 2
|
|
|
|
|
|
|
|
if mode == 3:
|
|
|
|
return SWING_BOTH
|
|
|
|
if mode == 2:
|
|
|
|
return SWING_VERTICAL
|
|
|
|
if mode == 1:
|
|
|
|
return SWING_HORIZONTAL
|
|
|
|
return SWING_OFF
|
2018-07-17 18:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-09-30 10:02:56 +00:00
|
|
|
def swing_modes(self) -> list[str]:
|
|
|
|
"""Return swing mode for select."""
|
|
|
|
return [SWING_OFF, SWING_HORIZONTAL, SWING_VERTICAL, SWING_BOTH]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self) -> int:
|
|
|
|
"""Flag supported features."""
|
|
|
|
supports = 0
|
|
|
|
if (
|
|
|
|
DPCODE_TEMP_SET in self.tuya_device.status
|
|
|
|
or DPCODE_TEMP_SET_F in self.tuya_device.status
|
|
|
|
):
|
|
|
|
supports |= SUPPORT_TARGET_TEMPERATURE
|
|
|
|
if DPCODE_FAN_SPEED_ENUM in self.tuya_device.status:
|
|
|
|
supports |= SUPPORT_FAN_MODE
|
|
|
|
if DPCODE_HUMIDITY_SET in self.tuya_device.status:
|
|
|
|
supports |= SUPPORT_TARGET_HUMIDITY
|
|
|
|
if (
|
|
|
|
DPCODE_SWITCH_HORIZONTAL in self.tuya_device.status
|
|
|
|
or DPCODE_SWITCH_VERTICAL in self.tuya_device.status
|
|
|
|
):
|
|
|
|
supports |= SUPPORT_SWING_MODE
|
|
|
|
return supports
|