Update schluter to use CoordinatorEntity (#39454)
This commit is contained in:
parent
705b253a99
commit
25f9560fb6
1 changed files with 14 additions and 28 deletions
|
@ -17,7 +17,11 @@ from homeassistant.components.climate.const import (
|
|||
SUPPORT_TARGET_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, CONF_SCAN_INTERVAL
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
UpdateFailed,
|
||||
)
|
||||
|
||||
from . import DATA_SCHLUTER_API, DATA_SCHLUTER_SESSION, DOMAIN
|
||||
|
||||
|
@ -63,27 +67,17 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
)
|
||||
|
||||
|
||||
class SchluterThermostat(ClimateEntity):
|
||||
class SchluterThermostat(CoordinatorEntity, ClimateEntity):
|
||||
"""Representation of a Schluter thermostat."""
|
||||
|
||||
def __init__(self, coordinator, serial_number, api, session_id):
|
||||
"""Initialize the thermostat."""
|
||||
self._coordinator = coordinator
|
||||
super().__init__(coordinator)
|
||||
self._serial_number = serial_number
|
||||
self._api = api
|
||||
self._session_id = session_id
|
||||
self._support_flags = SUPPORT_TARGET_TEMPERATURE
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return if thermostat is available."""
|
||||
return self._coordinator.last_update_success
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return if platform should poll."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
|
@ -97,7 +91,7 @@ class SchluterThermostat(ClimateEntity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the thermostat."""
|
||||
return self._coordinator.data[self._serial_number].name
|
||||
return self.coordinator.data[self._serial_number].name
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
|
@ -107,7 +101,7 @@ class SchluterThermostat(ClimateEntity):
|
|||
@property
|
||||
def current_temperature(self):
|
||||
"""Return the current temperature."""
|
||||
return self._coordinator.data[self._serial_number].temperature
|
||||
return self.coordinator.data[self._serial_number].temperature
|
||||
|
||||
@property
|
||||
def hvac_mode(self):
|
||||
|
@ -119,14 +113,14 @@ class SchluterThermostat(ClimateEntity):
|
|||
"""Return current operation. Can only be heating or idle."""
|
||||
return (
|
||||
CURRENT_HVAC_HEAT
|
||||
if self._coordinator.data[self._serial_number].is_heating
|
||||
if self.coordinator.data[self._serial_number].is_heating
|
||||
else CURRENT_HVAC_IDLE
|
||||
)
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
"""Return the temperature we try to reach."""
|
||||
return self._coordinator.data[self._serial_number].set_point_temp
|
||||
return self.coordinator.data[self._serial_number].set_point_temp
|
||||
|
||||
@property
|
||||
def hvac_modes(self):
|
||||
|
@ -136,12 +130,12 @@ class SchluterThermostat(ClimateEntity):
|
|||
@property
|
||||
def min_temp(self):
|
||||
"""Identify min_temp in Schluter API."""
|
||||
return self._coordinator.data[self._serial_number].min_temp
|
||||
return self.coordinator.data[self._serial_number].min_temp
|
||||
|
||||
@property
|
||||
def max_temp(self):
|
||||
"""Identify max_temp in Schluter API."""
|
||||
return self._coordinator.data[self._serial_number].max_temp
|
||||
return self.coordinator.data[self._serial_number].max_temp
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
"""Mode is always heating, so do nothing."""
|
||||
|
@ -150,7 +144,7 @@ class SchluterThermostat(ClimateEntity):
|
|||
"""Set new target temperature."""
|
||||
target_temp = None
|
||||
target_temp = kwargs.get(ATTR_TEMPERATURE)
|
||||
serial_number = self._coordinator.data[self._serial_number].serial_number
|
||||
serial_number = self.coordinator.data[self._serial_number].serial_number
|
||||
_LOGGER.debug("Setting thermostat temperature: %s", target_temp)
|
||||
|
||||
try:
|
||||
|
@ -158,11 +152,3 @@ class SchluterThermostat(ClimateEntity):
|
|||
self._api.set_temperature(self._session_id, serial_number, target_temp)
|
||||
except RequestException as ex:
|
||||
_LOGGER.error("An error occurred while setting temperature: %s", ex)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""When entity is added to hass."""
|
||||
self._coordinator.async_add_listener(self.async_write_ha_state)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""When entity will be removed from hass."""
|
||||
self._coordinator.async_remove_listener(self.async_write_ha_state)
|
||||
|
|
Loading…
Add table
Reference in a new issue