diff --git a/homeassistant/components/tplink/light.py b/homeassistant/components/tplink/light.py index 49e8adbf08e..3f4b130a5cc 100644 --- a/homeassistant/components/tplink/light.py +++ b/homeassistant/components/tplink/light.py @@ -69,6 +69,14 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity): if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None: brightness = round((brightness * 100.0) / 255.0) + if self.device.is_dimmer and transition is None: + # This is a stopgap solution for inconsistent set_brightness handling + # in the upstream library, see #57265. + # This should be removed when the upstream has fixed the issue. + # The device logic is to change the settings without turning it on + # except when transition is defined, so we leverage that here for now. + transition = 1 + # Handle turning to temp mode if ATTR_COLOR_TEMP in kwargs: color_tmp = mired_to_kelvin(int(kwargs[ATTR_COLOR_TEMP])) diff --git a/tests/components/tplink/__init__.py b/tests/components/tplink/__init__.py index 870e05e970b..f25fc13784a 100644 --- a/tests/components/tplink/__init__.py +++ b/tests/components/tplink/__init__.py @@ -33,6 +33,7 @@ def _mocked_bulb() -> SmartBulb: bulb.is_color = True bulb.is_strip = False bulb.is_plug = False + bulb.is_dimmer = False bulb.hsv = (10, 30, 5) bulb.device_id = MAC_ADDRESS bulb.valid_temperature_range.min = 4000 diff --git a/tests/components/tplink/test_light.py b/tests/components/tplink/test_light.py index 93d8cdbf07d..1017ad38eae 100644 --- a/tests/components/tplink/test_light.py +++ b/tests/components/tplink/test_light.py @@ -349,3 +349,29 @@ async def test_off_at_start_light(hass: HomeAssistant) -> None: assert state.state == "off" attributes = state.attributes assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["onoff"] + + +async def test_dimmer_turn_on_fix(hass: HomeAssistant) -> None: + """Test a light.""" + already_migrated_config_entry = MockConfigEntry( + domain=DOMAIN, data={}, unique_id=MAC_ADDRESS + ) + already_migrated_config_entry.add_to_hass(hass) + bulb = _mocked_bulb() + bulb.is_dimmer = True + bulb.is_on = False + + with _patch_discovery(device=bulb), _patch_single_discovery(device=bulb): + await async_setup_component(hass, tplink.DOMAIN, {tplink.DOMAIN: {}}) + await hass.async_block_till_done() + + entity_id = "light.my_bulb" + + state = hass.states.get(entity_id) + assert state.state == "off" + + await hass.services.async_call( + LIGHT_DOMAIN, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True + ) + bulb.turn_on.assert_called_once_with(transition=1) + bulb.turn_on.reset_mock()