1 """Support for the Electra climate."""
3 from __future__
import annotations
5 from datetime
import timedelta
10 from electrasmart.api
import STATUS_SUCCESS, Attributes, ElectraAPI, ElectraApiError
11 from electrasmart.device
import ElectraAirConditioner, OperationMode
12 from electrasmart.device.const
import MAX_TEMP, MIN_TEMP, Feature
36 CONSECUTIVE_FAILURE_THRESHOLD,
41 UNAVAILABLE_THRESH_SEC,
44 FAN_ELECTRA_TO_HASS = {
45 OperationMode.FAN_SPEED_AUTO: FAN_AUTO,
46 OperationMode.FAN_SPEED_LOW: FAN_LOW,
47 OperationMode.FAN_SPEED_MED: FAN_MEDIUM,
48 OperationMode.FAN_SPEED_HIGH: FAN_HIGH,
51 FAN_HASS_TO_ELECTRA = {
52 FAN_AUTO: OperationMode.FAN_SPEED_AUTO,
53 FAN_LOW: OperationMode.FAN_SPEED_LOW,
54 FAN_MEDIUM: OperationMode.FAN_SPEED_MED,
55 FAN_HIGH: OperationMode.FAN_SPEED_HIGH,
58 HVAC_MODE_ELECTRA_TO_HASS = {
59 OperationMode.MODE_COOL: HVACMode.COOL,
60 OperationMode.MODE_HEAT: HVACMode.HEAT,
61 OperationMode.MODE_FAN: HVACMode.FAN_ONLY,
62 OperationMode.MODE_DRY: HVACMode.DRY,
63 OperationMode.MODE_AUTO: HVACMode.AUTO,
66 HVAC_MODE_HASS_TO_ELECTRA = {
67 HVACMode.COOL: OperationMode.MODE_COOL,
68 HVACMode.HEAT: OperationMode.MODE_HEAT,
69 HVACMode.FAN_ONLY: OperationMode.MODE_FAN,
70 HVACMode.DRY: OperationMode.MODE_DRY,
71 HVACMode.AUTO: OperationMode.MODE_AUTO,
74 ELECTRA_FAN_MODES = [FAN_AUTO, FAN_HIGH, FAN_MEDIUM, FAN_LOW]
84 _LOGGER = logging.getLogger(__name__)
87 SCAN_INTERVAL =
timedelta(seconds=SCAN_INTERVAL_SEC)
92 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
94 """Add Electra AC devices."""
95 api: ElectraAPI = hass.data[DOMAIN][entry.entry_id]
97 _LOGGER.debug(
"Discovered %i Electra devices", len(api.devices))
104 """Define an Electra climate."""
106 _attr_fan_modes = ELECTRA_FAN_MODES
107 _attr_target_temperature_step = 1
108 _attr_max_temp = MAX_TEMP
109 _attr_min_temp = MIN_TEMP
110 _attr_temperature_unit = UnitOfTemperature.CELSIUS
111 _attr_hvac_modes = ELECTRA_MODES
112 _attr_has_entity_name =
True
114 _enable_turn_on_off_backwards_compatibility =
False
116 def __init__(self, device: ElectraAirConditioner, api: ElectraAPI) ->
None:
117 """Initialize Electra climate entity."""
122 ClimateEntityFeature.TARGET_TEMPERATURE
123 | ClimateEntityFeature.FAN_MODE
124 | ClimateEntityFeature.PRESET_MODE
125 | ClimateEntityFeature.TURN_OFF
126 | ClimateEntityFeature.TURN_ON
129 swing_modes: list = []
131 swing_modes.append(SWING_VERTICAL)
133 swing_modes.append(SWING_HORIZONTAL)
135 if all(elem
in [SWING_HORIZONTAL, SWING_VERTICAL]
for elem
in swing_modes):
136 swing_modes.append(SWING_BOTH)
138 swing_modes.append(SWING_OFF)
163 _LOGGER.debug(
"Added %s Electra AC device", self.
_attr_name_attr_name)
167 """Return True if the AC is available."""
170 and super().available
174 """Update Electra device."""
182 _LOGGER.debug(
"Skipping state update, keeping old values")
198 "Electra AC %s (%s) is not available, check its status in the Electra Smart mobile app",
207 "%s (%s) is now available",
214 "%s (%s) state updated: %s",
219 except ElectraApiError
as exp:
222 "Failed to get %s state: %s (try #%i since last success), keeping old state",
230 f
"Failed to get {self.name} state: {exp} for the {self._consecutive_failures} time",
231 )
from ElectraApiError
237 """Set AC fan mode."""
238 mode = FAN_HASS_TO_ELECTRA[fan_mode]
245 if hvac_mode == HVACMode.OFF:
248 self.
_electra_ac_device_electra_ac_device.set_mode(HVAC_MODE_HASS_TO_ELECTRA[hvac_mode])
254 """Set new target temperature."""
256 if (temperature := kwargs.get(ATTR_TEMPERATURE))
is None:
257 raise ValueError(
"No target temperature provided")
290 PRESET_SHABAT
if self.
_electra_ac_device_electra_ac_device.get_shabat_mode()
else PRESET_NONE
294 """Set AC swing mdde."""
295 if swing_mode == SWING_BOTH:
299 elif swing_mode == SWING_VERTICAL:
303 elif swing_mode == SWING_HORIZONTAL:
313 """Set Preset mode."""
314 if preset_mode == PRESET_SHABAT:
322 """Send HVAC parameters to API."""
326 except ElectraApiError
as exp:
328 f
"Error communicating with Electra API: {exp}"
332 resp[Attributes.STATUS] == STATUS_SUCCESS
333 and resp[Attributes.DATA][Attributes.RES] == STATUS_SUCCESS
None set_temperature(self, **Any kwargs)
_attr_current_temperature
None async_set_swing_mode(self, str swing_mode)
None async_set_temperature(self, **Any kwargs)
None async_set_preset_mode(self, str preset_mode)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None __init__(self, ElectraAirConditioner device, ElectraAPI api)
None _async_operate_electra_ac(self)
None async_set_fan_mode(self, str fan_mode)
None _update_device_attrs(self)
None _async_write_ha_state(self)
str|UndefinedType|None name(self)
bool is_on(HomeAssistant hass, str entity_id)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
float|None get_temperature(MadVRCoordinator coordinator, str key)