mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +00:00
Fix light brightness_step on multiple entities (#47746)
* Fix light brightness_step on multiple entities * Fix comment Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
7e615cb7fd
commit
b9c2f80cab
@ -207,7 +207,7 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
If brightness is set to 0, this service will turn the light off.
|
If brightness is set to 0, this service will turn the light off.
|
||||||
"""
|
"""
|
||||||
params = call.data["params"]
|
params = dict(call.data["params"])
|
||||||
|
|
||||||
# Only process params once we processed brightness step
|
# Only process params once we processed brightness step
|
||||||
if params and (
|
if params and (
|
||||||
|
@ -706,36 +706,51 @@ async def test_light_turn_on_auth(hass, hass_admin_user):
|
|||||||
async def test_light_brightness_step(hass):
|
async def test_light_brightness_step(hass):
|
||||||
"""Test that light context works."""
|
"""Test that light context works."""
|
||||||
platform = getattr(hass.components, "test.light")
|
platform = getattr(hass.components, "test.light")
|
||||||
platform.init()
|
platform.init(empty=True)
|
||||||
entity = platform.ENTITIES[0]
|
platform.ENTITIES.append(platform.MockLight("Test_0", STATE_ON))
|
||||||
entity.supported_features = light.SUPPORT_BRIGHTNESS
|
platform.ENTITIES.append(platform.MockLight("Test_1", STATE_ON))
|
||||||
entity.brightness = 100
|
entity0 = platform.ENTITIES[0]
|
||||||
|
entity0.supported_features = light.SUPPORT_BRIGHTNESS
|
||||||
|
entity0.brightness = 100
|
||||||
|
entity1 = platform.ENTITIES[1]
|
||||||
|
entity1.supported_features = light.SUPPORT_BRIGHTNESS
|
||||||
|
entity1.brightness = 50
|
||||||
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(entity.entity_id)
|
state = hass.states.get(entity0.entity_id)
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.attributes["brightness"] == 100
|
assert state.attributes["brightness"] == 100
|
||||||
|
state = hass.states.get(entity1.entity_id)
|
||||||
|
assert state is not None
|
||||||
|
assert state.attributes["brightness"] == 50
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
"turn_on",
|
"turn_on",
|
||||||
{"entity_id": entity.entity_id, "brightness_step": -10},
|
{"entity_id": [entity0.entity_id, entity1.entity_id], "brightness_step": -10},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
_, data = entity.last_call("turn_on")
|
_, data = entity0.last_call("turn_on")
|
||||||
assert data["brightness"] == 90, data
|
assert data["brightness"] == 90 # 100 - 10
|
||||||
|
_, data = entity1.last_call("turn_on")
|
||||||
|
assert data["brightness"] == 40 # 50 - 10
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
"turn_on",
|
"turn_on",
|
||||||
{"entity_id": entity.entity_id, "brightness_step_pct": 10},
|
{
|
||||||
|
"entity_id": [entity0.entity_id, entity1.entity_id],
|
||||||
|
"brightness_step_pct": 10,
|
||||||
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
_, data = entity.last_call("turn_on")
|
_, data = entity0.last_call("turn_on")
|
||||||
assert data["brightness"] == 126, data
|
assert data["brightness"] == 126 # 100 + (255 * 0.10)
|
||||||
|
_, data = entity1.last_call("turn_on")
|
||||||
|
assert data["brightness"] == 76 # 50 + (255 * 0.10)
|
||||||
|
|
||||||
|
|
||||||
async def test_light_brightness_pct_conversion(hass):
|
async def test_light_brightness_pct_conversion(hass):
|
||||||
@ -760,7 +775,7 @@ async def test_light_brightness_pct_conversion(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
_, data = entity.last_call("turn_on")
|
_, data = entity.last_call("turn_on")
|
||||||
assert data["brightness"] == 3, data
|
assert data["brightness"] == 3
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
@ -770,7 +785,7 @@ async def test_light_brightness_pct_conversion(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
_, data = entity.last_call("turn_on")
|
_, data = entity.last_call("turn_on")
|
||||||
assert data["brightness"] == 5, data
|
assert data["brightness"] == 5
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
@ -780,7 +795,7 @@ async def test_light_brightness_pct_conversion(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
_, data = entity.last_call("turn_on")
|
_, data = entity.last_call("turn_on")
|
||||||
assert data["brightness"] == 128, data
|
assert data["brightness"] == 128
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
@ -790,7 +805,7 @@ async def test_light_brightness_pct_conversion(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
_, data = entity.last_call("turn_on")
|
_, data = entity.last_call("turn_on")
|
||||||
assert data["brightness"] == 252, data
|
assert data["brightness"] == 252
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"light",
|
"light",
|
||||||
@ -800,7 +815,7 @@ async def test_light_brightness_pct_conversion(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
_, data = entity.last_call("turn_on")
|
_, data = entity.last_call("turn_on")
|
||||||
assert data["brightness"] == 255, data
|
assert data["brightness"] == 255
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_base_class(caplog):
|
def test_deprecated_base_class(caplog):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user