diff --git a/custom_components/uponor/__init__.py b/custom_components/uponor/__init__.py index 24b8243..fef59dd 100644 --- a/custom_components/uponor/__init__.py +++ b/custom_components/uponor/__init__.py @@ -9,6 +9,7 @@ from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.storage import Store from UponorJnap import UponorJnap +import homeassistant.util.dt as dt_util from .const import ( DOMAIN, @@ -86,6 +87,7 @@ def __init__(self, hass, host, store): self._store = store self._data = {} self._storage_data = {} + self.next_sp_from_dt = None # Thermostats config @@ -280,11 +282,19 @@ def get_eco_setback(self, thermostat): var = thermostat + '_eco_offset' if var in self._data: return round(int(self._data[var]) / 18, 1) + + def get_last_update(self): + return self.next_sp_from_dt # Rest - - async def async_update(self): - self._data = await self._hass.async_add_executor_job(lambda: self._client.get_data()) + async def async_update(self,_=None): + '# try to change update calls doing one in same second' + 'TODO call self.async_write_ha_state() in climate and switch' + if self.next_sp_from_dt is None or dt_util.now() >= self.next_sp_from_dt: + self.next_sp_from_dt = dt_util.now() + self._data = await self._hass.async_add_executor_job(lambda: self._client.get_data()) + else: + _LOGGER.warning("A lot of asyn_update calls at " + str(dt_util.now())) def set_variable(self, var_name, var_value): _LOGGER.debug("Called set variable: name: %s, value: %s, data: %s", var_name, var_value, self._data) diff --git a/custom_components/uponor/climate.py b/custom_components/uponor/climate.py index 1428c65..838c13a 100644 --- a/custom_components/uponor/climate.py +++ b/custom_components/uponor/climate.py @@ -152,7 +152,7 @@ async def async_turn_on(self): async def async_update(self): # Update uponor (to get HC mode) and thermostat try: -### se ha elimininado el 0 del update + ### se ha elimininado el 0 del update await self._state_proxy.async_update() temp = self._state_proxy.get_setpoint(self._thermostat) is_cool = self._state_proxy.is_cool_enabled()