mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Stopgap fix for inconsistent upstream API of tplink dimmers (#57285)
This commit is contained in:
parent
ddab7f3024
commit
8fb0da7720
@ -69,6 +69,14 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity):
|
|||||||
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
|
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
|
||||||
brightness = round((brightness * 100.0) / 255.0)
|
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
|
# Handle turning to temp mode
|
||||||
if ATTR_COLOR_TEMP in kwargs:
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
color_tmp = mired_to_kelvin(int(kwargs[ATTR_COLOR_TEMP]))
|
color_tmp = mired_to_kelvin(int(kwargs[ATTR_COLOR_TEMP]))
|
||||||
|
@ -33,6 +33,7 @@ def _mocked_bulb() -> SmartBulb:
|
|||||||
bulb.is_color = True
|
bulb.is_color = True
|
||||||
bulb.is_strip = False
|
bulb.is_strip = False
|
||||||
bulb.is_plug = False
|
bulb.is_plug = False
|
||||||
|
bulb.is_dimmer = False
|
||||||
bulb.hsv = (10, 30, 5)
|
bulb.hsv = (10, 30, 5)
|
||||||
bulb.device_id = MAC_ADDRESS
|
bulb.device_id = MAC_ADDRESS
|
||||||
bulb.valid_temperature_range.min = 4000
|
bulb.valid_temperature_range.min = 4000
|
||||||
|
@ -349,3 +349,29 @@ async def test_off_at_start_light(hass: HomeAssistant) -> None:
|
|||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
attributes = state.attributes
|
attributes = state.attributes
|
||||||
assert attributes[ATTR_SUPPORTED_COLOR_MODES] == ["onoff"]
|
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user