1 """The lookin integration climate platform."""
3 from __future__
import annotations
6 from typing
import Any, Final, cast
8 from aiolookin
import Climate, MeteoSensor, Remote
9 from aiolookin.models
import UDPCommandType, UDPEvent
33 from .const
import DOMAIN, TYPE_TO_PLATFORM
34 from .coordinator
import LookinDataUpdateCoordinator
35 from .entity
import LookinCoordinatorEntity
36 from .models
import LookinData
38 LOOKIN_FAN_MODE_IDX_TO_HASS: Final = [FAN_AUTO, FAN_LOW, FAN_MIDDLE, FAN_HIGH]
39 LOOKIN_SWING_MODE_IDX_TO_HASS: Final = [SWING_OFF, SWING_BOTH]
40 LOOKIN_HVAC_MODE_IDX_TO_HASS: Final = [
49 HASS_TO_LOOKIN_HVAC_MODE: dict[str, int] = {
50 mode: idx
for idx, mode
in enumerate(LOOKIN_HVAC_MODE_IDX_TO_HASS)
52 HASS_TO_LOOKIN_FAN_MODE: dict[str, int] = {
53 mode: idx
for idx, mode
in enumerate(LOOKIN_FAN_MODE_IDX_TO_HASS)
55 HASS_TO_LOOKIN_SWING_MODE: dict[str, int] = {
56 mode: idx
for idx, mode
in enumerate(LOOKIN_SWING_MODE_IDX_TO_HASS)
62 LOGGER = logging.getLogger(__name__)
67 config_entry: ConfigEntry,
68 async_add_entities: AddEntitiesCallback,
70 """Set up the climate platform for lookin from a config entry."""
71 lookin_data: LookinData = hass.data[DOMAIN][config_entry.entry_id]
74 for remote
in lookin_data.devices:
75 if TYPE_TO_PLATFORM.get(remote[
"Type"]) != Platform.CLIMATE:
78 coordinator = lookin_data.device_coordinators[uuid]
79 device = cast(Climate, coordinator.data)
84 lookin_data=lookin_data,
85 coordinator=coordinator,
93 """An aircon or heat pump."""
95 _attr_current_humidity: float |
None =
None
96 _attr_temperature_unit = UnitOfTemperature.CELSIUS
97 _attr_supported_features = (
98 ClimateEntityFeature.TARGET_TEMPERATURE
99 | ClimateEntityFeature.FAN_MODE
100 | ClimateEntityFeature.SWING_MODE
101 | ClimateEntityFeature.TURN_OFF
102 | ClimateEntityFeature.TURN_ON
104 _attr_fan_modes: list[str] = LOOKIN_FAN_MODE_IDX_TO_HASS
105 _attr_swing_modes: list[str] = LOOKIN_SWING_MODE_IDX_TO_HASS
106 _attr_hvac_modes: list[HVACMode] = LOOKIN_HVAC_MODE_IDX_TO_HASS
107 _attr_min_temp = MIN_TEMP
108 _attr_max_temp = MAX_TEMP
109 _attr_target_temperature_step = PRECISION_WHOLE
110 _enable_turn_on_off_backwards_compatibility =
False
116 lookin_data: LookinData,
117 coordinator: LookinDataUpdateCoordinator[Remote],
119 """Init the ConditionerEntity."""
120 super().
__init__(coordinator, uuid, device, lookin_data)
125 return cast(Climate, self.coordinator.data)
128 """Set the hvac mode of the device."""
129 if (mode := HASS_TO_LOOKIN_HVAC_MODE.get(hvac_mode))
is None:
131 self.
_climate_climate.hvac_mode = mode
135 """Set the temperature of the device."""
136 if (temperature := kwargs.get(ATTR_TEMPERATURE))
is None:
138 self.
_climate_climate.temp_celsius =
int(temperature)
139 lookin_index = LOOKIN_HVAC_MODE_IDX_TO_HASS
140 if hvac_mode := kwargs.get(ATTR_HVAC_MODE):
141 self.
_climate_climate.hvac_mode = HASS_TO_LOOKIN_HVAC_MODE[hvac_mode]
142 elif self.
_climate_climate.hvac_mode == lookin_index.index(HVACMode.OFF):
156 if not (current_temp := meteo_data.temperature):
157 self.
_climate_climate.hvac_mode = lookin_index.index(HVACMode.AUTO)
158 elif current_temp >= self.
_climate_climate.temp_celsius:
159 self.
_climate_climate.hvac_mode = lookin_index.index(HVACMode.COOL)
161 self.
_climate_climate.hvac_mode = lookin_index.index(HVACMode.HEAT)
163 self.
_climate_climate.hvac_mode = lookin_index.index(HVACMode.AUTO)
168 """Set the fan mode of the device."""
169 if (mode := HASS_TO_LOOKIN_FAN_MODE.get(fan_mode))
is None:
171 self.
_climate_climate.fan_mode = mode
175 """Set the swing mode of the device."""
176 if (mode := HASS_TO_LOOKIN_SWING_MODE.get(swing_mode))
is None:
178 self.
_climate_climate.swing_mode = mode
182 """Update the conditioner state from the climate data."""
189 """Update attrs from data."""
194 temperature = humidity =
None
205 """Update temperature and humidity from UDP event."""
211 """Handle updated data from the coordinator."""
217 """Process an update pushed via UDP."""
218 LOGGER.debug(
"Processing push message for %s: %s", self.
entity_identity_id, event)
219 self.
_climate_climate.update_from_status(event.value)
223 """Call when the entity is added to hass."""
235 UDPCommandType.meteo,
None _async_update_from_data(self)
None async_added_to_hass(self)
None async_set_fan_mode(self, str fan_mode)
None _async_update_meteo_from_value(self, UDPEvent event)
None _async_update_conditioner(self)
_attr_current_temperature
None __init__(self, str uuid, Climate device, LookinData lookin_data, LookinDataUpdateCoordinator[Remote] coordinator)
None _async_push_update(self, UDPEvent event)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None _handle_coordinator_update(self)
None async_set_swing_mode(self, str swing_mode)
None async_set_temperature(self, **Any kwargs)
None async_set_updated_data(self, _DataT data)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)