From 13421b326bcd25def93cd6c6dcf12a8d22203e6e Mon Sep 17 00:00:00 2001 From: javicalle <31999997+javicalle@users.noreply.github.com> Date: Sun, 10 Feb 2019 12:50:40 +0100 Subject: [PATCH] Fix RFLink restore state (#20588) * some minor tests refactor * unused import * async/await refactor * Correct tests failures * Restore state bug added call to super().async_added_to_hass() * Show brightness attribute if device supports it * Fix light/test_rflink Dimmable devices defaults to 255 brightness * delete super().device_state_attributes call --- homeassistant/components/light/rflink.py | 16 ++++++++++++++++ homeassistant/components/rflink/__init__.py | 1 + tests/components/light/test_rflink.py | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/rflink.py b/homeassistant/components/light/rflink.py index ef389bb84f9..726433b4f70 100644 --- a/homeassistant/components/light/rflink.py +++ b/homeassistant/components/light/rflink.py @@ -185,6 +185,14 @@ class DimmableRflinkLight(SwitchableRflinkDevice, Light): """Return the brightness of this light between 0..255.""" return self._brightness + @property + def device_state_attributes(self): + """Return the device state attributes.""" + attr = {} + if self._brightness is not None: + attr[ATTR_BRIGHTNESS] = self._brightness + return attr + @property def supported_features(self): """Flag supported features.""" @@ -239,6 +247,14 @@ class HybridRflinkLight(SwitchableRflinkDevice, Light): """Return the brightness of this light between 0..255.""" return self._brightness + @property + def device_state_attributes(self): + """Return the device state attributes.""" + attr = {} + if self._brightness is not None: + attr[ATTR_BRIGHTNESS] = self._brightness + return attr + @property def supported_features(self): """Flag supported features.""" diff --git a/homeassistant/components/rflink/__init__.py b/homeassistant/components/rflink/__init__.py index b91ff251bd1..ce9777151cf 100644 --- a/homeassistant/components/rflink/__init__.py +++ b/homeassistant/components/rflink/__init__.py @@ -345,6 +345,7 @@ class RflinkDevice(Entity): async def async_added_to_hass(self): """Register update callback.""" + await super().async_added_to_hass() # Remove temporary bogus entity_id if added tmp_entity = TMP_ENTITY.format(self._device_id) if tmp_entity in self.hass.data[DATA_ENTITY_LOOKUP][ diff --git a/tests/components/light/test_rflink.py b/tests/components/light/test_rflink.py index e2b80d12ce0..901a2d3a286 100644 --- a/tests/components/light/test_rflink.py +++ b/tests/components/light/test_rflink.py @@ -632,7 +632,7 @@ async def test_restore_state(hass, monkeypatch): state = hass.states.get(DOMAIN + '.l4') assert state assert state.state == STATE_OFF - assert not state.attributes.get(ATTR_BRIGHTNESS) + assert state.attributes[ATTR_BRIGHTNESS] == 255 assert state.attributes['assumed_state'] # test coverage for dimmable light