Ensure flux_led bulbs turn on even if brightness is 0 (#59661)

This commit is contained in:
J. Nick Koston 2021-11-13 23:55:23 -06:00 committed by GitHub
parent 570f80a73c
commit c323815760
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 3 deletions

View file

@ -328,13 +328,21 @@ class FluxLight(FluxEntity, CoordinatorEntity, LightEntity):
async def _async_turn_on(self, **kwargs: Any) -> None:
"""Turn the specified or all lights on."""
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is None:
brightness = self.brightness
if not self.is_on:
await self._device.async_turn_on()
if not kwargs:
return
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is None:
brightness = self.brightness
# If the brightness was previously 0, the light
# will not turn on unless brightness is at least 1
if not brightness:
brightness = 1
elif not brightness:
# If the device was on and brightness was not
# set, it means it was masked by an effect
brightness = 255
# Handle switch to CCT Color Mode
if ATTR_COLOR_TEMP in kwargs:

View file

@ -214,11 +214,26 @@ async def test_rgb_light(hass: HomeAssistant) -> None:
await async_mock_device_turn_off(hass, bulb)
assert hass.states.get(entity_id).state == STATE_OFF
bulb.brightness = 0
await hass.services.async_call(
LIGHT_DOMAIN,
"turn_on",
{ATTR_ENTITY_ID: entity_id, ATTR_RGB_COLOR: (10, 10, 30)},
blocking=True,
)
# If the bulb is off and we are using existing brightness
# it has to be at least 1 or the bulb won't turn on
bulb.async_set_levels.assert_called_with(10, 10, 30, brightness=1)
bulb.async_set_levels.reset_mock()
bulb.async_turn_on.reset_mock()
await hass.services.async_call(
LIGHT_DOMAIN, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
)
bulb.async_turn_on.assert_called_once()
bulb.async_turn_on.reset_mock()
await async_mock_device_turn_on(hass, bulb)
assert hass.states.get(entity_id).state == STATE_ON
await hass.services.async_call(
LIGHT_DOMAIN,
@ -229,6 +244,19 @@ async def test_rgb_light(hass: HomeAssistant) -> None:
bulb.async_set_levels.assert_called_with(255, 0, 0, brightness=100)
bulb.async_set_levels.reset_mock()
await hass.services.async_call(
LIGHT_DOMAIN,
"turn_on",
{ATTR_ENTITY_ID: entity_id, ATTR_RGB_COLOR: (10, 10, 30)},
blocking=True,
)
# If the bulb is on and we are using existing brightness
# and brightness was 0 it means we could not read it because
# an effect is in progress so we use 255
bulb.async_set_levels.assert_called_with(10, 10, 30, brightness=255)
bulb.async_set_levels.reset_mock()
bulb.brightness = 128
await hass.services.async_call(
LIGHT_DOMAIN,
"turn_on",