From 5dd45efac3a1774f39d717cb79b268b3395049da Mon Sep 17 00:00:00 2001 From: Ryan Kraus Date: Fri, 20 Jan 2017 01:22:33 -0500 Subject: [PATCH] Updated ISY component to not overwrite state_attributes. (#5433) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated ISY component to not overwrite state_attributes. The ISY component included an ISYDevice base class that is used by all of the isy994 platforms. This still overwrote the state_attributes property instead of the more appropriate device_state_attributes property. This was also repeated in the isy994 light platform. Both of these were addressed. This also fixes issue #5428. * Removed custom state attributes from ISY lights. The brightness attribute need not be manually reported by the isy994 light platform. * Removed ISY Node cleanup. The ISY entities don’t really need to unsubscribe themselves while hass is shutting down. Because these updates are not sent in a thread, there is no negative impact from shutting down without unsubscribing. This greatly speeds up hass shutdown. * Removed unused attribute from isy994 light platform. * Cleaned up ISY994 light entity class. 1) Removed the state property. This property is set in the Entity base class and shouldn’t be overridden here. 2) Set the brightness property. This is the proper way of setting the brightness for the Light base class. 3) Removed properties that are now unused because of these changes. --- homeassistant/components/isy994.py | 6 +----- homeassistant/components/light/isy994.py | 22 ++++++---------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/isy994.py b/homeassistant/components/isy994.py index 7451b3286f7..cbe7c7166e7 100644 --- a/homeassistant/components/isy994.py +++ b/homeassistant/components/isy994.py @@ -228,10 +228,6 @@ class ISYDevice(Entity): self._change_handler = self._node.status.subscribe('changed', self.on_update) - def __del__(self) -> None: - """Cleanup the subscriptions.""" - self._change_handler.unsubscribe() - # pylint: disable=unused-argument def on_update(self, event: object) -> None: """Handle the update event from the ISY994 Node.""" @@ -272,7 +268,7 @@ class ISYDevice(Entity): return self._node.status._val @property - def state_attributes(self) -> Dict: + def device_state_attributes(self) -> Dict: """Get the state attributes for the device.""" attr = {} if hasattr(self._node, 'aux_properties'): diff --git a/homeassistant/components/light/isy994.py b/homeassistant/components/light/isy994.py index 952c52b2809..1cde50de820 100644 --- a/homeassistant/components/light/isy994.py +++ b/homeassistant/components/light/isy994.py @@ -8,18 +8,13 @@ import logging from typing import Callable from homeassistant.components.light import ( - Light, SUPPORT_BRIGHTNESS, ATTR_BRIGHTNESS) + Light, SUPPORT_BRIGHTNESS) import homeassistant.components.isy994 as isy -from homeassistant.const import STATE_ON, STATE_OFF, STATE_UNKNOWN +from homeassistant.const import STATE_ON, STATE_OFF from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) -VALUE_TO_STATE = { - False: STATE_OFF, - True: STATE_ON, -} - UOM = ['2', '51', '78'] STATES = [STATE_OFF, STATE_ON, 'true', 'false', '%'] @@ -52,12 +47,12 @@ class ISYLightDevice(isy.ISYDevice, Light): @property def is_on(self) -> bool: """Get whether the ISY994 light is on.""" - return self.state == STATE_ON + return self.value > 0 @property - def state(self) -> str: - """Get the state of the ISY994 light.""" - return VALUE_TO_STATE.get(bool(self.value), STATE_UNKNOWN) + def brightness(self) -> float: + """Get the brightness of the ISY994 light.""" + return self.value def turn_off(self, **kwargs) -> None: """Send the turn off command to the ISY994 light device.""" @@ -69,11 +64,6 @@ class ISYLightDevice(isy.ISYDevice, Light): if not self._node.on(val=brightness): _LOGGER.debug('Unable to turn on light.') - @property - def state_attributes(self): - """Flag supported attributes.""" - return {ATTR_BRIGHTNESS: self.value} - @property def supported_features(self): """Flag supported features."""