diff --git a/homeassistant/components/yeelight/light.py b/homeassistant/components/yeelight/light.py index bc4d027ce93..be876690b06 100644 --- a/homeassistant/components/yeelight/light.py +++ b/homeassistant/components/yeelight/light.py @@ -859,7 +859,12 @@ class YeelightColorLightWithoutNightlightSwitch( @property def _brightness_property(self): - return "current_brightness" + # If the nightlight is not active, we do not + # want to "current_brightness" since it will check + # "bg_power" and main light could still be on + if self.device.is_nightlight_enabled: + return "current_brightness" + return super()._brightness_property class YeelightColorLightWithNightlightSwitch( @@ -883,7 +888,12 @@ class YeelightWhiteTempWithoutNightlightSwitch( @property def _brightness_property(self): - return "current_brightness" + # If the nightlight is not active, we do not + # want to "current_brightness" since it will check + # "bg_power" and main light could still be on + if self.device.is_nightlight_enabled: + return "current_brightness" + return super()._brightness_property class YeelightWithNightLight( diff --git a/tests/components/yeelight/test_light.py b/tests/components/yeelight/test_light.py index 17924facfad..030f6a54cea 100644 --- a/tests/components/yeelight/test_light.py +++ b/tests/components/yeelight/test_light.py @@ -96,6 +96,7 @@ from homeassistant.util.color import ( ) from . import ( + CAPABILITIES, ENTITY_LIGHT, ENTITY_NIGHTLIGHT, IP_ADDRESS, @@ -1178,3 +1179,38 @@ async def test_state_fails_to_update_triggers_update(hass: HomeAssistant): ) assert len(mocked_bulb.async_turn_on.mock_calls) == 1 assert len(mocked_bulb.async_get_properties.mock_calls) == 3 + + +async def test_ambilight_with_nightlight_disabled(hass: HomeAssistant): + """Test that main light on ambilights with the nightlight disabled shows the correct brightness.""" + mocked_bulb = _mocked_bulb() + properties = {**PROPERTIES} + capabilities = {**CAPABILITIES} + capabilities["model"] = "ceiling10" + properties["color_mode"] = "3" # HSV + properties["bg_power"] = "off" + properties["current_brightness"] = 0 + properties["bg_lmode"] = "2" # CT + mocked_bulb.last_properties = properties + mocked_bulb.bulb_type = BulbType.WhiteTempMood + main_light_entity_id = "light.yeelight_ceiling10_0x15243f" + + config_entry = MockConfigEntry( + domain=DOMAIN, + data={**CONFIG_ENTRY_DATA, CONF_NIGHTLIGHT_SWITCH: False}, + options={**CONFIG_ENTRY_DATA, CONF_NIGHTLIGHT_SWITCH: False}, + ) + config_entry.add_to_hass(hass) + with _patch_discovery(capabilities=capabilities), patch( + f"{MODULE}.AsyncBulb", return_value=mocked_bulb + ): + assert await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + # We use asyncio.create_task now to avoid + # blocking starting so we need to block again + await hass.async_block_till_done() + + state = hass.states.get(main_light_entity_id) + assert state.state == "on" + # bg_power off should not set the brightness to 0 + assert state.attributes[ATTR_BRIGHTNESS] == 128