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
This commit is contained in:
javicalle 2019-02-10 12:50:40 +01:00 committed by Martin Hjelmare
parent 5f7f7777a0
commit 13421b326b
3 changed files with 18 additions and 1 deletions

View file

@ -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."""

View file

@ -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][

View file

@ -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