1 """Support for climate entities."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
9 from thinqconnect
import DeviceType
10 from thinqconnect.integration
import ExtendedProperty
13 ATTR_TARGET_TEMP_HIGH,
16 ClimateEntityDescription,
25 from .
import ThinqConfigEntry
26 from .coordinator
import DeviceDataUpdateCoordinator
27 from .entity
import ThinQEntity
30 @dataclass(frozen=True, kw_only=True)
32 """Describes ThinQ climate entity."""
34 min_temp: float |
None =
None
35 max_temp: float |
None =
None
36 step: float |
None =
None
39 DEVICE_TYPE_CLIMATE_MAP: dict[DeviceType, tuple[ThinQClimateEntityDescription, ...]] = {
40 DeviceType.AIR_CONDITIONER: (
42 key=ExtendedProperty.CLIMATE_AIR_CONDITIONER,
44 translation_key=ExtendedProperty.CLIMATE_AIR_CONDITIONER,
47 DeviceType.SYSTEM_BOILER: (
49 key=ExtendedProperty.CLIMATE_SYSTEM_BOILER,
58 STR_TO_HVAC: dict[str, HVACMode] = {
59 "air_dry": HVACMode.DRY,
60 "auto": HVACMode.AUTO,
61 "cool": HVACMode.COOL,
62 "fan": HVACMode.FAN_ONLY,
63 "heat": HVACMode.HEAT,
66 HVAC_TO_STR: dict[HVACMode, str] = {
67 HVACMode.AUTO:
"auto",
68 HVACMode.COOL:
"cool",
69 HVACMode.DRY:
"air_dry",
70 HVACMode.FAN_ONLY:
"fan",
71 HVACMode.HEAT:
"heat",
74 THINQ_PRESET_MODE: list[str] = [
"air_clean",
"aroma",
"energy_saving"]
76 _LOGGER = logging.getLogger(__name__)
81 entry: ThinqConfigEntry,
82 async_add_entities: AddEntitiesCallback,
84 """Set up an entry for climate platform."""
85 entities: list[ThinQClimateEntity] = []
86 for coordinator
in entry.runtime_data.coordinators.values():
88 descriptions := DEVICE_TYPE_CLIMATE_MAP.get(
89 coordinator.api.device.device_type
92 for description
in descriptions:
95 for property_id
in coordinator.api.get_active_idx(description.key)
103 """Represent a thinq climate platform."""
105 entity_description: ThinQClimateEntityDescription
109 coordinator: DeviceDataUpdateCoordinator,
110 entity_description: ThinQClimateEntityDescription,
113 """Initialize a climate entity."""
114 super().
__init__(coordinator, entity_description, property_id)
117 ClimateEntityFeature.TARGET_TEMPERATURE
118 | ClimateEntityFeature.TURN_ON
119 | ClimateEntityFeature.TURN_OFF
129 if mode
in STR_TO_HVAC:
131 elif mode
in THINQ_PRESET_MODE:
143 ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
147 """Update status itself."""
155 if hvac_mode
in STR_TO_HVAC:
158 elif hvac_mode
in THINQ_PRESET_MODE:
188 "[%s:%s] update status: c:%s, t:%s, l:%s, h:%s, hvac:%s, unit:%s, step:%s",
189 self.coordinator.device_name,
201 """Cancel request to set hvac mode."""
205 """Turn the entity on."""
207 "[%s:%s] async_turn_on", self.coordinator.device_name, self.
property_idproperty_id
212 """Turn the entity off."""
214 "[%s:%s] async_turn_off", self.coordinator.device_name, self.
property_idproperty_id
219 """Set new target hvac mode."""
220 if hvac_mode == HVACMode.OFF:
235 "[%s:%s] async_set_hvac_mode: %s",
236 self.coordinator.device_name,
241 self.coordinator.api.async_set_hvac_mode(
248 """Set new preset mode."""
250 "[%s:%s] async_set_preset_mode: %s",
251 self.coordinator.device_name,
256 self.coordinator.api.async_set_hvac_mode(self.
property_idproperty_id, preset_mode)
260 """Set new target fan mode."""
262 "[%s:%s] async_set_fan_mode: %s",
263 self.coordinator.device_name,
268 self.coordinator.api.async_set_fan_mode(self.
property_idproperty_id, fan_mode)
272 """Round the value by step."""
275 self.coordinator.hass,
277 self.coordinator.hass.config.units.temperature_unit,
286 """Set new target temperature."""
288 "[%s:%s] async_set_temperature: %s",
289 self.coordinator.device_name,
294 if (temperature := kwargs.get(ATTR_TEMPERATURE))
is not None:
299 self.coordinator.api.async_set_target_temperature(
304 if (temperature_low := kwargs.get(ATTR_TARGET_TEMP_LOW))
is not None:
306 target_temp_low := self.
_round_by_step_round_by_step(temperature_low)
309 self.coordinator.api.async_set_target_temperature_low(
314 if (temperature_high := kwargs.get(ATTR_TARGET_TEMP_HIGH))
is not None:
316 target_temp_high := self.
_round_by_step_round_by_step(temperature_high)
319 self.coordinator.api.async_set_target_temperature_high(
list[str]|None fan_modes(self)
float|None target_temperature_low(self)
str temperature_unit(self)
ClimateEntityFeature supported_features(self)
float|None target_temperature_high(self)
float|None target_temperature(self)
HVACMode|None hvac_mode(self)
None async_turn_off(self)
float|None current_temperature(self)
float|None target_temperature_step(self)
None async_turn_off(self)
None __init__(self, DeviceDataUpdateCoordinator coordinator, ThinQClimateEntityDescription entity_description, str property_id)
_attr_current_temperature
float _round_by_step(self, float temperature)
_attr_target_temperature_step
None _update_status(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_set_fan_mode(self, str fan_mode)
None reset_requested_hvac_mode(self)
None async_set_temperature(self, **Any kwargs)
_attr_target_temperature_high
None async_set_preset_mode(self, str preset_mode)
_attr_target_temperature_low
None async_call_api(self, Coroutine[Any, Any, Any] target, Callable[[], None]|None on_fail_method=None)
int|None supported_features(self)
None async_setup_entry(HomeAssistant hass, ThinqConfigEntry entry, AddEntitiesCallback async_add_entities)
float|None display_temp(HomeAssistant hass, float|None temperature, str unit, float precision)