From 1b79722b6973babddd3b0d86d5028f5750da5cfa Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 8 Nov 2016 21:00:33 -0800 Subject: [PATCH] Fix KNX async I/O (#4267) --- homeassistant/components/climate/knx.py | 19 +++++++++++++------ homeassistant/components/knx.py | 2 -- homeassistant/components/sensor/knx.py | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/climate/knx.py b/homeassistant/components/climate/knx.py index ef7445c35fd..888a217d90c 100644 --- a/homeassistant/components/climate/knx.py +++ b/homeassistant/components/climate/knx.py @@ -56,6 +56,8 @@ class KNXThermostat(KNXMultiAddressDevice, ClimateDevice): self._unit_of_measurement = TEMP_CELSIUS # KNX always used celsius self._away = False # not yet supported self._is_fan_on = False # not yet supported + self._current_temp = None + self._target_temp = None @property def should_poll(self): @@ -70,16 +72,12 @@ class KNXThermostat(KNXMultiAddressDevice, ClimateDevice): @property def current_temperature(self): """Return the current temperature.""" - from knxip.conversion import knx2_to_float - - return knx2_to_float(self.value('temperature')) + return self._current_temp @property def target_temperature(self): """Return the temperature we try to reach.""" - from knxip.conversion import knx2_to_float - - return knx2_to_float(self.value('setpoint')) + return self._target_temp def set_temperature(self, **kwargs): """Set new target temperature.""" @@ -94,3 +92,12 @@ class KNXThermostat(KNXMultiAddressDevice, ClimateDevice): def set_operation_mode(self, operation_mode): """Set operation mode.""" raise NotImplementedError() + + def update(self): + """Update KNX climate.""" + from knxip.conversion import knx2_to_float + + super().update() + + self._current_temp = knx2_to_float(self.value('temperature')) + self._target_temp = knx2_to_float(self.value('setpoint')) diff --git a/homeassistant/components/knx.py b/homeassistant/components/knx.py index 5d096b30ee0..8653f33c663 100644 --- a/homeassistant/components/knx.py +++ b/homeassistant/components/knx.py @@ -161,8 +161,6 @@ class KNXGroupAddress(Entity): @property def is_on(self): """Return True if the value is not 0 is on, else False.""" - if self.should_poll: - self.update() return self._state != 0 @property diff --git a/homeassistant/components/sensor/knx.py b/homeassistant/components/sensor/knx.py index 007291f5fb1..1f5c9a76520 100644 --- a/homeassistant/components/sensor/knx.py +++ b/homeassistant/components/sensor/knx.py @@ -113,15 +113,24 @@ class KNXSensorFloatClass(KNXGroupAddress, KNXSensorBaseClass): self._unit_of_measurement = unit_of_measurement self._minimum_value = minimum_sensor_value self._maximum_value = maximum_sensor_value + self._value = None KNXGroupAddress.__init__(self, hass, config) @property def state(self): """Return the Value of the KNX Sensor.""" + return self._value + + def update(self): + """Update KNX sensor.""" + from knxip.conversion import knx2_to_float + + super().update() + + self._value = None + if self._data: - from knxip.conversion import knx2_to_float value = knx2_to_float(self._data) if self._minimum_value <= value <= self._maximum_value: - return value - return None + self._value = value