Handle brightness being None for senseme (#65372)

This commit is contained in:
J. Nick Koston 2022-02-01 16:51:28 -06:00 committed by Franck Nijhof
parent 37f9c833c0
commit 95d4be375c
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 17 additions and 1 deletions

View File

@ -51,7 +51,8 @@ class HASensemeLight(SensemeEntity, LightEntity):
def _async_update_attrs(self) -> None:
"""Update attrs from device."""
self._attr_is_on = self._device.light_on
self._attr_brightness = int(min(255, self._device.light_brightness * 16))
if self._device.light_brightness is not None:
self._attr_brightness = int(min(255, self._device.light_brightness * 16))
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""

View File

@ -74,6 +74,21 @@ async def test_fan_light(hass: HomeAssistant) -> None:
assert device.light_on is True
async def test_fan_light_no_brightness(hass: HomeAssistant) -> None:
"""Test a fan light without brightness."""
device = _mock_device()
device.brightness = None
await _setup_mocked_entry(hass, device)
entity_id = "light.haiku_fan"
state = hass.states.get(entity_id)
assert state.state == STATE_ON
attributes = state.attributes
assert attributes[ATTR_BRIGHTNESS] == 255
assert attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
async def test_standalone_light(hass: HomeAssistant) -> None:
"""Test a standalone light."""
device = _mock_device()