From a87d653077b0a83c6fef29854694d1f225e50804 Mon Sep 17 00:00:00 2001 From: Gianluca Barbaro Date: Thu, 19 Jan 2017 10:57:45 +0100 Subject: [PATCH] Update generic_thermostat.py As suggested, I added a callback on the heater switch state change. Still it doesn't solve the problem. --- homeassistant/components/climate/generic_thermostat.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index efebcbbf7e9..3bf64fab2df 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -5,7 +5,6 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/climate.generic_thermostat/ """ import logging -import time import voluptuous as vol @@ -88,6 +87,7 @@ class GenericThermostat(ClimateDevice): self._unit = hass.config.units.temperature_unit track_state_change(hass, sensor_entity_id, self._sensor_changed) + track_state_change(hass, heater_entity_id, self._switch_changed) sensor_state = hass.states.get(sensor_entity_id) if sensor_state: @@ -166,6 +166,12 @@ class GenericThermostat(ClimateDevice): self._control_heating() self.schedule_update_ha_state() + def _switch_changed(self, entity_id, old_state, new_state): + """Called when heater switch changes state.""" + if new_state is None: + return + self.schedule_update_ha_state() + def _update_temp(self, state): """Update thermostat with latest state from sensor.""" unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) @@ -223,7 +229,6 @@ class GenericThermostat(ClimateDevice): if too_cold: _LOGGER.info('Turning on heater %s', self.heater_entity_id) switch.turn_on(self.hass, self.heater_entity_id) - time.sleep(.1) @property def _is_device_active(self):