diff --git a/custom_components/versatile_thermostat/thermostat_sonoff_trvzb.py b/custom_components/versatile_thermostat/thermostat_sonoff_trvzb.py index 37007fb..b1996bb 100644 --- a/custom_components/versatile_thermostat/thermostat_sonoff_trvzb.py +++ b/custom_components/versatile_thermostat/thermostat_sonoff_trvzb.py @@ -217,12 +217,9 @@ class ThermostatOverSonoffTRVZB(ThermostatOverClimate): self._valve_open_percent = new_valve_percent - for under in self._underlyings_sonoff_trvzb: - under.set_valve_open_percent() - self._last_calculation_timestamp = now - self.update_custom_attributes() + super().recalculate() async def _send_regulated_temperature(self, force=False): """Sends the regulated temperature to all underlying""" @@ -236,7 +233,8 @@ class ThermostatOverSonoffTRVZB(ThermostatOverClimate): self._attr_min_temp, ) - self.recalculate() + for under in self._underlyings_sonoff_trvzb: + await under.set_valve_open_percent() @property def is_over_sonoff_trvzb(self) -> bool: @@ -269,3 +267,8 @@ class ThermostatOverSonoffTRVZB(ThermostatOverClimate): """Returns the current hvac_action by checking all hvac_action of the _underlyings_sonoff_trvzb""" return self.calculate_hvac_action(self._underlyings_sonoff_trvzb) + + @property + def is_device_active(self) -> bool: + """A hack to overrides the state from underlyings""" + return self.valve_open_percent > 0 diff --git a/custom_components/versatile_thermostat/thermostat_valve.py b/custom_components/versatile_thermostat/thermostat_valve.py index 35579fe..ec05254 100644 --- a/custom_components/versatile_thermostat/thermostat_valve.py +++ b/custom_components/versatile_thermostat/thermostat_valve.py @@ -248,8 +248,9 @@ class ThermostatOverValve(BaseThermostat[UnderlyingValve]): # pylint: disable=a self._valve_open_percent = new_valve_percent - for under in self._underlyings: - under.set_valve_open_percent() + # is one in start_cycle now + # for under in self._underlyings: + # under.set_valve_open_percent() self._last_calculation_timestamp = now diff --git a/custom_components/versatile_thermostat/underlyings.py b/custom_components/versatile_thermostat/underlyings.py index 052df45..e40d8df 100644 --- a/custom_components/versatile_thermostat/underlyings.py +++ b/custom_components/versatile_thermostat/underlyings.py @@ -920,7 +920,7 @@ class UnderlyingValve(UnderlyingEntity): async def turn_on(self): """Nothing to do for Valve because it cannot be turned on""" - self.set_valve_open_percent() + await self.set_valve_open_percent() async def set_hvac_mode(self, hvac_mode: HVACMode) -> bool: """Set the HVACmode. Returns true if something have change""" @@ -958,11 +958,8 @@ class UnderlyingValve(UnderlyingEntity): force=False, ): """We use this function to change the on_percent""" - if force: - # self._percent_open = self.cap_sent_value(self._percent_open) - # await self.send_percent_open() - # avoid to send 2 times the same value at startup - self.set_valve_open_percent() + # if force: + await self.set_valve_open_percent() @overrides def cap_sent_value(self, value) -> float: @@ -995,7 +992,7 @@ class UnderlyingValve(UnderlyingEntity): return new_value - def set_valve_open_percent(self): + async def set_valve_open_percent(self): """Update the valve open percent""" caped_val = self.cap_sent_value(self._thermostat.valve_open_percent) if self._percent_open == caped_val: @@ -1009,7 +1006,8 @@ class UnderlyingValve(UnderlyingEntity): "%s - Setting valve ouverture percent to %s", self, self._percent_open ) # Send the change to the valve, in background - self._hass.create_task(self.send_percent_open()) + # self._hass.create_task(self.send_percent_open()) + await self.send_percent_open() def remove_entity(self): """Remove the entity after stopping its cycle""" @@ -1138,6 +1136,19 @@ class UnderlyingSonoffTRVZB(UnderlyingValve): return [] return [HVACMode.OFF, HVACMode.HEAT] + @overrides + async def start_cycle( + self, + hvac_mode: HVACMode, + _1, + _2, + _3, + force=False, + ): + """We use this function to change the on_percent""" + # if force: + await self.set_valve_open_percent() + @property def is_device_active(self): """If the opening valve is open."""