Use shorthand attributes in intesishome climate (#145285)

This commit is contained in:
epenet 2025-05-20 10:10:24 +02:00 committed by GitHub
parent 99f91003d8
commit c8183bd35a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -145,7 +145,9 @@ async def async_setup_platform(
class IntesisAC(ClimateEntity):
"""Represents an Intesishome air conditioning device."""
_attr_preset_modes = [PRESET_ECO, PRESET_COMFORT, PRESET_BOOST]
_attr_should_poll = False
_attr_target_temperature_step = 1
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, ih_device_id, ih_device, controller):
@ -153,26 +155,18 @@ class IntesisAC(ClimateEntity):
self._controller = controller
self._device_id = ih_device_id
self._ih_device = ih_device
self._device_name = ih_device.get("name")
self._attr_name = ih_device.get("name")
self._device_type = controller.device_type
self._connected = None
self._setpoint_step = 1
self._current_temp = None
self._max_temp = None
self._attr_hvac_modes = []
self._min_temp = None
self._target_temp = None
self._outdoor_temp = None
self._hvac_mode = None
self._preset = None
self._preset_list = [PRESET_ECO, PRESET_COMFORT, PRESET_BOOST]
self._run_hours = None
self._rssi = None
self._swing_list = [SWING_OFF]
self._attr_swing_modes = [SWING_OFF]
self._vvane = None
self._hvane = None
self._power = False
self._fan_speed = None
self._power_consumption_heat = None
self._power_consumption_cool = None
@ -182,17 +176,20 @@ class IntesisAC(ClimateEntity):
# Setup swing list
if controller.has_vertical_swing(ih_device_id):
self._swing_list.append(SWING_VERTICAL)
self._attr_swing_modes.append(SWING_VERTICAL)
if controller.has_horizontal_swing(ih_device_id):
self._swing_list.append(SWING_HORIZONTAL)
if SWING_HORIZONTAL in self._swing_list and SWING_VERTICAL in self._swing_list:
self._swing_list.append(SWING_BOTH)
if len(self._swing_list) > 1:
self._attr_swing_modes.append(SWING_HORIZONTAL)
if (
SWING_HORIZONTAL in self._attr_swing_modes
and SWING_VERTICAL in self._attr_swing_modes
):
self._attr_swing_modes.append(SWING_BOTH)
if len(self._attr_swing_modes) > 1:
self._attr_supported_features |= ClimateEntityFeature.SWING_MODE
# Setup fan speeds
self._fan_modes = controller.get_fan_speed_list(ih_device_id)
if self._fan_modes:
self._attr_fan_modes = controller.get_fan_speed_list(ih_device_id)
if self._attr_fan_modes:
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
# Preset support
@ -220,11 +217,6 @@ class IntesisAC(ClimateEntity):
_LOGGER.error("Exception connecting to IntesisHome: %s", ex)
raise PlatformNotReady from ex
@property
def name(self):
"""Return the name of the AC device."""
return self._device_name
@property
def extra_state_attributes(self):
"""Return the device specific state attributes."""
@ -247,21 +239,6 @@ class IntesisAC(ClimateEntity):
"""Return unique ID for this device."""
return self._device_id
@property
def target_temperature_step(self) -> float:
"""Return whether setpoint should be whole or half degree precision."""
return self._setpoint_step
@property
def preset_modes(self):
"""Return a list of HVAC preset modes."""
return self._preset_list
@property
def preset_mode(self):
"""Return the current preset mode."""
return self._preset
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
if hvac_mode := kwargs.get(ATTR_HVAC_MODE):
@ -270,7 +247,7 @@ class IntesisAC(ClimateEntity):
if temperature := kwargs.get(ATTR_TEMPERATURE):
_LOGGER.debug("Setting %s to %s degrees", self._device_type, temperature)
await self._controller.set_temperature(self._device_id, temperature)
self._target_temp = temperature
self._attr_target_temperature = temperature
# Write updated temperature to HA state to avoid flapping (API confirmation is slow)
self.async_write_ha_state()
@ -294,8 +271,10 @@ class IntesisAC(ClimateEntity):
await self._controller.set_mode(self._device_id, MAP_HVAC_MODE_TO_IH[hvac_mode])
# Send the temperature again in case changing modes has changed it
if self._target_temp:
await self._controller.set_temperature(self._device_id, self._target_temp)
if self._attr_target_temperature:
await self._controller.set_temperature(
self._device_id, self._attr_target_temperature
)
# Updates can take longer than 2 seconds, so update locally
self._hvac_mode = hvac_mode
@ -306,7 +285,7 @@ class IntesisAC(ClimateEntity):
await self._controller.set_fan_speed(self._device_id, fan_mode)
# Updates can take longer than 2 seconds, so update locally
self._fan_speed = fan_mode
self._attr_fan_mode = fan_mode
self.async_write_ha_state()
async def async_set_preset_mode(self, preset_mode: str) -> None:
@ -328,14 +307,16 @@ class IntesisAC(ClimateEntity):
"""Copy values from controller dictionary to climate device."""
# Update values from controller's device dictionary
self._connected = self._controller.is_connected
self._current_temp = self._controller.get_temperature(self._device_id)
self._fan_speed = self._controller.get_fan_speed(self._device_id)
self._attr_current_temperature = self._controller.get_temperature(
self._device_id
)
self._attr_fan_mode = self._controller.get_fan_speed(self._device_id)
self._power = self._controller.is_on(self._device_id)
self._min_temp = self._controller.get_min_setpoint(self._device_id)
self._max_temp = self._controller.get_max_setpoint(self._device_id)
self._attr_min_temp = self._controller.get_min_setpoint(self._device_id)
self._attr_max_temp = self._controller.get_max_setpoint(self._device_id)
self._rssi = self._controller.get_rssi(self._device_id)
self._run_hours = self._controller.get_run_hours(self._device_id)
self._target_temp = self._controller.get_setpoint(self._device_id)
self._attr_target_temperature = self._controller.get_setpoint(self._device_id)
self._outdoor_temp = self._controller.get_outdoor_temperature(self._device_id)
# Operation mode
@ -344,7 +325,7 @@ class IntesisAC(ClimateEntity):
# Preset mode
preset = self._controller.get_preset_mode(self._device_id)
self._preset = MAP_IH_TO_PRESET_MODE.get(preset)
self._attr_preset_mode = MAP_IH_TO_PRESET_MODE.get(preset)
# Swing mode
# Climate module only supports one swing setting.
@ -364,12 +345,11 @@ class IntesisAC(ClimateEntity):
await self._controller.stop()
@property
def icon(self):
def icon(self) -> str | None:
"""Return the icon for the current state."""
icon = None
if self._power:
icon = MAP_STATE_ICONS.get(self._hvac_mode)
return icon
return MAP_STATE_ICONS.get(self._hvac_mode)
return None
async def async_update_callback(self, device_id=None):
"""Let HA know there has been an update from the controller."""
@ -405,22 +385,7 @@ class IntesisAC(ClimateEntity):
self.async_schedule_update_ha_state(True)
@property
def min_temp(self):
"""Return the minimum temperature for the current mode of operation."""
return self._min_temp
@property
def max_temp(self):
"""Return the maximum temperature for the current mode of operation."""
return self._max_temp
@property
def fan_mode(self):
"""Return whether the fan is on."""
return self._fan_speed
@property
def swing_mode(self):
def swing_mode(self) -> str:
"""Return current swing mode."""
if self._vvane == IH_SWING_SWING and self._hvane == IH_SWING_SWING:
swing = SWING_BOTH
@ -432,34 +397,14 @@ class IntesisAC(ClimateEntity):
swing = SWING_OFF
return swing
@property
def fan_modes(self):
"""List of available fan modes."""
return self._fan_modes
@property
def swing_modes(self):
"""List of available swing positions."""
return self._swing_list
@property
def available(self) -> bool:
"""If the device hasn't been able to connect, mark as unavailable."""
return self._connected or self._connected is None
@property
def current_temperature(self):
"""Return the current temperature."""
return self._current_temp
@property
def hvac_mode(self) -> HVACMode:
"""Return the current mode of operation if unit is on."""
if self._power:
return self._hvac_mode
return HVACMode.OFF
@property
def target_temperature(self):
"""Return the current setpoint temperature if unit is on."""
return self._target_temp