mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Use shorthand attributes in intesishome climate (#145285)
This commit is contained in:
parent
99f91003d8
commit
c8183bd35a
@ -145,7 +145,9 @@ async def async_setup_platform(
|
|||||||
class IntesisAC(ClimateEntity):
|
class IntesisAC(ClimateEntity):
|
||||||
"""Represents an Intesishome air conditioning device."""
|
"""Represents an Intesishome air conditioning device."""
|
||||||
|
|
||||||
|
_attr_preset_modes = [PRESET_ECO, PRESET_COMFORT, PRESET_BOOST]
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_target_temperature_step = 1
|
||||||
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
|
|
||||||
def __init__(self, ih_device_id, ih_device, controller):
|
def __init__(self, ih_device_id, ih_device, controller):
|
||||||
@ -153,26 +155,18 @@ class IntesisAC(ClimateEntity):
|
|||||||
self._controller = controller
|
self._controller = controller
|
||||||
self._device_id = ih_device_id
|
self._device_id = ih_device_id
|
||||||
self._ih_device = ih_device
|
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._device_type = controller.device_type
|
||||||
self._connected = None
|
self._connected = None
|
||||||
self._setpoint_step = 1
|
|
||||||
self._current_temp = None
|
|
||||||
self._max_temp = None
|
|
||||||
self._attr_hvac_modes = []
|
self._attr_hvac_modes = []
|
||||||
self._min_temp = None
|
|
||||||
self._target_temp = None
|
|
||||||
self._outdoor_temp = None
|
self._outdoor_temp = None
|
||||||
self._hvac_mode = None
|
self._hvac_mode = None
|
||||||
self._preset = None
|
|
||||||
self._preset_list = [PRESET_ECO, PRESET_COMFORT, PRESET_BOOST]
|
|
||||||
self._run_hours = None
|
self._run_hours = None
|
||||||
self._rssi = None
|
self._rssi = None
|
||||||
self._swing_list = [SWING_OFF]
|
self._attr_swing_modes = [SWING_OFF]
|
||||||
self._vvane = None
|
self._vvane = None
|
||||||
self._hvane = None
|
self._hvane = None
|
||||||
self._power = False
|
self._power = False
|
||||||
self._fan_speed = None
|
|
||||||
self._power_consumption_heat = None
|
self._power_consumption_heat = None
|
||||||
self._power_consumption_cool = None
|
self._power_consumption_cool = None
|
||||||
|
|
||||||
@ -182,17 +176,20 @@ class IntesisAC(ClimateEntity):
|
|||||||
|
|
||||||
# Setup swing list
|
# Setup swing list
|
||||||
if controller.has_vertical_swing(ih_device_id):
|
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):
|
if controller.has_horizontal_swing(ih_device_id):
|
||||||
self._swing_list.append(SWING_HORIZONTAL)
|
self._attr_swing_modes.append(SWING_HORIZONTAL)
|
||||||
if SWING_HORIZONTAL in self._swing_list and SWING_VERTICAL in self._swing_list:
|
if (
|
||||||
self._swing_list.append(SWING_BOTH)
|
SWING_HORIZONTAL in self._attr_swing_modes
|
||||||
if len(self._swing_list) > 1:
|
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
|
self._attr_supported_features |= ClimateEntityFeature.SWING_MODE
|
||||||
|
|
||||||
# Setup fan speeds
|
# Setup fan speeds
|
||||||
self._fan_modes = controller.get_fan_speed_list(ih_device_id)
|
self._attr_fan_modes = controller.get_fan_speed_list(ih_device_id)
|
||||||
if self._fan_modes:
|
if self._attr_fan_modes:
|
||||||
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
|
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
|
||||||
|
|
||||||
# Preset support
|
# Preset support
|
||||||
@ -220,11 +217,6 @@ class IntesisAC(ClimateEntity):
|
|||||||
_LOGGER.error("Exception connecting to IntesisHome: %s", ex)
|
_LOGGER.error("Exception connecting to IntesisHome: %s", ex)
|
||||||
raise PlatformNotReady from ex
|
raise PlatformNotReady from ex
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the AC device."""
|
|
||||||
return self._device_name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the device specific state attributes."""
|
"""Return the device specific state attributes."""
|
||||||
@ -247,21 +239,6 @@ class IntesisAC(ClimateEntity):
|
|||||||
"""Return unique ID for this device."""
|
"""Return unique ID for this device."""
|
||||||
return self._device_id
|
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:
|
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
if hvac_mode := kwargs.get(ATTR_HVAC_MODE):
|
if hvac_mode := kwargs.get(ATTR_HVAC_MODE):
|
||||||
@ -270,7 +247,7 @@ class IntesisAC(ClimateEntity):
|
|||||||
if temperature := kwargs.get(ATTR_TEMPERATURE):
|
if temperature := kwargs.get(ATTR_TEMPERATURE):
|
||||||
_LOGGER.debug("Setting %s to %s degrees", self._device_type, temperature)
|
_LOGGER.debug("Setting %s to %s degrees", self._device_type, temperature)
|
||||||
await self._controller.set_temperature(self._device_id, 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)
|
# Write updated temperature to HA state to avoid flapping (API confirmation is slow)
|
||||||
self.async_write_ha_state()
|
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])
|
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
|
# Send the temperature again in case changing modes has changed it
|
||||||
if self._target_temp:
|
if self._attr_target_temperature:
|
||||||
await self._controller.set_temperature(self._device_id, self._target_temp)
|
await self._controller.set_temperature(
|
||||||
|
self._device_id, self._attr_target_temperature
|
||||||
|
)
|
||||||
|
|
||||||
# Updates can take longer than 2 seconds, so update locally
|
# Updates can take longer than 2 seconds, so update locally
|
||||||
self._hvac_mode = hvac_mode
|
self._hvac_mode = hvac_mode
|
||||||
@ -306,7 +285,7 @@ class IntesisAC(ClimateEntity):
|
|||||||
await self._controller.set_fan_speed(self._device_id, fan_mode)
|
await self._controller.set_fan_speed(self._device_id, fan_mode)
|
||||||
|
|
||||||
# Updates can take longer than 2 seconds, so update locally
|
# 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()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
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."""
|
"""Copy values from controller dictionary to climate device."""
|
||||||
# Update values from controller's device dictionary
|
# Update values from controller's device dictionary
|
||||||
self._connected = self._controller.is_connected
|
self._connected = self._controller.is_connected
|
||||||
self._current_temp = self._controller.get_temperature(self._device_id)
|
self._attr_current_temperature = self._controller.get_temperature(
|
||||||
self._fan_speed = self._controller.get_fan_speed(self._device_id)
|
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._power = self._controller.is_on(self._device_id)
|
||||||
self._min_temp = self._controller.get_min_setpoint(self._device_id)
|
self._attr_min_temp = self._controller.get_min_setpoint(self._device_id)
|
||||||
self._max_temp = self._controller.get_max_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._rssi = self._controller.get_rssi(self._device_id)
|
||||||
self._run_hours = self._controller.get_run_hours(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)
|
self._outdoor_temp = self._controller.get_outdoor_temperature(self._device_id)
|
||||||
|
|
||||||
# Operation mode
|
# Operation mode
|
||||||
@ -344,7 +325,7 @@ class IntesisAC(ClimateEntity):
|
|||||||
|
|
||||||
# Preset mode
|
# Preset mode
|
||||||
preset = self._controller.get_preset_mode(self._device_id)
|
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
|
# Swing mode
|
||||||
# Climate module only supports one swing setting.
|
# Climate module only supports one swing setting.
|
||||||
@ -364,12 +345,11 @@ class IntesisAC(ClimateEntity):
|
|||||||
await self._controller.stop()
|
await self._controller.stop()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self) -> str | None:
|
||||||
"""Return the icon for the current state."""
|
"""Return the icon for the current state."""
|
||||||
icon = None
|
|
||||||
if self._power:
|
if self._power:
|
||||||
icon = MAP_STATE_ICONS.get(self._hvac_mode)
|
return MAP_STATE_ICONS.get(self._hvac_mode)
|
||||||
return icon
|
return None
|
||||||
|
|
||||||
async def async_update_callback(self, device_id=None):
|
async def async_update_callback(self, device_id=None):
|
||||||
"""Let HA know there has been an update from the controller."""
|
"""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)
|
self.async_schedule_update_ha_state(True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_temp(self):
|
def swing_mode(self) -> str:
|
||||||
"""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):
|
|
||||||
"""Return current swing mode."""
|
"""Return current swing mode."""
|
||||||
if self._vvane == IH_SWING_SWING and self._hvane == IH_SWING_SWING:
|
if self._vvane == IH_SWING_SWING and self._hvane == IH_SWING_SWING:
|
||||||
swing = SWING_BOTH
|
swing = SWING_BOTH
|
||||||
@ -432,34 +397,14 @@ class IntesisAC(ClimateEntity):
|
|||||||
swing = SWING_OFF
|
swing = SWING_OFF
|
||||||
return swing
|
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
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""If the device hasn't been able to connect, mark as unavailable."""
|
"""If the device hasn't been able to connect, mark as unavailable."""
|
||||||
return self._connected or self._connected is None
|
return self._connected or self._connected is None
|
||||||
|
|
||||||
@property
|
|
||||||
def current_temperature(self):
|
|
||||||
"""Return the current temperature."""
|
|
||||||
return self._current_temp
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> HVACMode:
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""Return the current mode of operation if unit is on."""
|
"""Return the current mode of operation if unit is on."""
|
||||||
if self._power:
|
if self._power:
|
||||||
return self._hvac_mode
|
return self._hvac_mode
|
||||||
return HVACMode.OFF
|
return HVACMode.OFF
|
||||||
|
|
||||||
@property
|
|
||||||
def target_temperature(self):
|
|
||||||
"""Return the current setpoint temperature if unit is on."""
|
|
||||||
return self._target_temp
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user