From b7bf07eaca92f5c948a5868578c61b707e8ed946 Mon Sep 17 00:00:00 2001 From: Gianluca Barbaro Date: Wed, 18 Jan 2017 12:20:39 +0100 Subject: [PATCH 1/5] Update generic_thermostat.py After _control_heating() is executed, current_operation() is correctly called but _is_device_active() still reports the old state if the heater switch, at least in my case. The resulting climate state is incorrect until the next refresh, which apparently occurs only when _sensor_changed() gets called (it can be minutes after). I think the state of the heater switch should be forced to update at the end of _control_heating(), but I don't know how to do that... A simple sleep() fixes it, but obviously is just a temporary workaround, I'm not really expecting this PR to be actually committed, unless there's no other solution. --- homeassistant/components/climate/generic_thermostat.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index a40795c37c5..a61c71a6551 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -16,6 +16,7 @@ from homeassistant.const import ( from homeassistant.helpers import condition from homeassistant.helpers.event import track_state_change import homeassistant.helpers.config_validation as cv +import time _LOGGER = logging.getLogger(__name__) @@ -222,6 +223,7 @@ 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): From 72dca1da091945651788ed6cc5e314570b79361f Mon Sep 17 00:00:00 2001 From: Gianluca Barbaro Date: Wed, 18 Jan 2017 12:39:16 +0100 Subject: [PATCH 2/5] Update generic_thermostat.py --- homeassistant/components/climate/generic_thermostat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index a61c71a6551..efebcbbf7e9 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -5,6 +5,7 @@ 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 @@ -16,7 +17,6 @@ from homeassistant.const import ( from homeassistant.helpers import condition from homeassistant.helpers.event import track_state_change import homeassistant.helpers.config_validation as cv -import time _LOGGER = logging.getLogger(__name__) From a87d653077b0a83c6fef29854694d1f225e50804 Mon Sep 17 00:00:00 2001 From: Gianluca Barbaro Date: Thu, 19 Jan 2017 10:57:45 +0100 Subject: [PATCH 3/5] 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): From 6ef9714dc115b8ad6e1e5a205a25d3c3348123eb Mon Sep 17 00:00:00 2001 From: Gianluca Barbaro Date: Thu, 19 Jan 2017 19:46:58 +0100 Subject: [PATCH 4/5] Update generic_thermostat.py --- homeassistant/components/climate/generic_thermostat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index 3bf64fab2df..4bf704327d2 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -134,8 +134,8 @@ class GenericThermostat(ClimateDevice): if temperature is None: return self._target_temp = temperature + self.schedule_update_ha_state() self._control_heating() - self.update_ha_state() @property def min_temp(self): @@ -163,8 +163,8 @@ class GenericThermostat(ClimateDevice): return self._update_temp(new_state) - self._control_heating() self.schedule_update_ha_state() + self._control_heating() def _switch_changed(self, entity_id, old_state, new_state): """Called when heater switch changes state.""" From 64c9cd805ab4e9b47e5f2cfe67cac1f33e1f3acd Mon Sep 17 00:00:00 2001 From: Gianluca Barbaro Date: Thu, 19 Jan 2017 21:26:12 +0100 Subject: [PATCH 5/5] Update generic_thermostat.py --- homeassistant/components/climate/generic_thermostat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index 4bf704327d2..562847567a3 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -134,8 +134,8 @@ class GenericThermostat(ClimateDevice): if temperature is None: return self._target_temp = temperature - self.schedule_update_ha_state() self._control_heating() + self.schedule_update_ha_state() @property def min_temp(self): @@ -163,8 +163,8 @@ class GenericThermostat(ClimateDevice): return self._update_temp(new_state) - self.schedule_update_ha_state() self._control_heating() + self.schedule_update_ha_state() def _switch_changed(self, entity_id, old_state, new_state): """Called when heater switch changes state."""