From c7c3b30e0af18b33b38b0c23e5ea2985e42c17a6 Mon Sep 17 00:00:00 2001 From: Erik Eriksson Date: Fri, 10 Feb 2017 17:59:58 +0100 Subject: [PATCH] Do not call state if device isn't available (#5835) --- homeassistant/helpers/entity.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 854d1bc169d..a80f2f5edae 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -210,26 +210,24 @@ class Entity(object): start = timer() - state = self.state - - if state is None: - state = STATE_UNKNOWN - else: - state = str(state) - - attr = self.state_attributes or {} - - device_attr = self.device_state_attributes - - if device_attr is not None: - attr.update(device_attr) - - self._attr_setter('unit_of_measurement', str, ATTR_UNIT_OF_MEASUREMENT, - attr) - if not self.available: state = STATE_UNAVAILABLE attr = {} + else: + state = self.state + + if state is None: + state = STATE_UNKNOWN + else: + state = str(state) + + attr = self.state_attributes or {} + device_attr = self.device_state_attributes + if device_attr is not None: + attr.update(device_attr) + + self._attr_setter('unit_of_measurement', str, ATTR_UNIT_OF_MEASUREMENT, + attr) self._attr_setter('name', str, ATTR_FRIENDLY_NAME, attr) self._attr_setter('icon', str, ATTR_ICON, attr)