mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Fix Hyperion brightness setting (#45335)
This commit is contained in:
parent
b9a525a9a7
commit
3647d549b0
@ -415,7 +415,6 @@ class HyperionLight(LightEntity):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# == Get key parameters ==
|
# == Get key parameters ==
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS, self._brightness)
|
|
||||||
if ATTR_EFFECT not in kwargs and ATTR_HS_COLOR in kwargs:
|
if ATTR_EFFECT not in kwargs and ATTR_HS_COLOR in kwargs:
|
||||||
effect = KEY_EFFECT_SOLID
|
effect = KEY_EFFECT_SOLID
|
||||||
else:
|
else:
|
||||||
@ -427,17 +426,21 @@ class HyperionLight(LightEntity):
|
|||||||
rgb_color = self._rgb_color
|
rgb_color = self._rgb_color
|
||||||
|
|
||||||
# == Set brightness ==
|
# == Set brightness ==
|
||||||
if self._brightness != brightness:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
if not await self._client.async_send_set_adjustment(
|
brightness = kwargs[ATTR_BRIGHTNESS]
|
||||||
**{
|
for item in self._client.adjustment:
|
||||||
const.KEY_ADJUSTMENT: {
|
if const.KEY_ID in item:
|
||||||
const.KEY_BRIGHTNESS: int(
|
if not await self._client.async_send_set_adjustment(
|
||||||
round((float(brightness) * 100) / 255)
|
**{
|
||||||
)
|
const.KEY_ADJUSTMENT: {
|
||||||
}
|
const.KEY_BRIGHTNESS: int(
|
||||||
}
|
round((float(brightness) * 100) / 255)
|
||||||
):
|
),
|
||||||
return
|
const.KEY_ID: item[const.KEY_ID],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
# == Set an external source
|
# == Set an external source
|
||||||
if effect and effect in const.KEY_COMPONENTID_EXTERNAL_SOURCES:
|
if effect and effect in const.KEY_COMPONENTID_EXTERNAL_SOURCES:
|
||||||
|
@ -20,6 +20,7 @@ TEST_HOST = "test"
|
|||||||
TEST_PORT = const.DEFAULT_PORT_JSON + 1
|
TEST_PORT = const.DEFAULT_PORT_JSON + 1
|
||||||
TEST_PORT_UI = const.DEFAULT_PORT_UI + 1
|
TEST_PORT_UI = const.DEFAULT_PORT_UI + 1
|
||||||
TEST_INSTANCE = 1
|
TEST_INSTANCE = 1
|
||||||
|
TEST_ID = "default"
|
||||||
TEST_SYSINFO_ID = "f9aab089-f85a-55cf-b7c1-222a72faebe9"
|
TEST_SYSINFO_ID = "f9aab089-f85a-55cf-b7c1-222a72faebe9"
|
||||||
TEST_SYSINFO_VERSION = "2.0.0-alpha.8"
|
TEST_SYSINFO_VERSION = "2.0.0-alpha.8"
|
||||||
TEST_PRIORITY = 180
|
TEST_PRIORITY = 180
|
||||||
|
@ -43,6 +43,7 @@ from . import (
|
|||||||
TEST_ENTITY_ID_2,
|
TEST_ENTITY_ID_2,
|
||||||
TEST_ENTITY_ID_3,
|
TEST_ENTITY_ID_3,
|
||||||
TEST_HOST,
|
TEST_HOST,
|
||||||
|
TEST_ID,
|
||||||
TEST_INSTANCE_1,
|
TEST_INSTANCE_1,
|
||||||
TEST_INSTANCE_2,
|
TEST_INSTANCE_2,
|
||||||
TEST_INSTANCE_3,
|
TEST_INSTANCE_3,
|
||||||
@ -387,6 +388,7 @@ async def test_light_async_turn_on(hass: HomeAssistantType) -> None:
|
|||||||
brightness = 128
|
brightness = 128
|
||||||
client.async_send_set_color = AsyncMock(return_value=True)
|
client.async_send_set_color = AsyncMock(return_value=True)
|
||||||
client.async_send_set_adjustment = AsyncMock(return_value=True)
|
client.async_send_set_adjustment = AsyncMock(return_value=True)
|
||||||
|
client.adjustment = [{const.KEY_ID: TEST_ID}]
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -395,7 +397,7 @@ async def test_light_async_turn_on(hass: HomeAssistantType) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert client.async_send_set_adjustment.call_args == call(
|
assert client.async_send_set_adjustment.call_args == call(
|
||||||
**{const.KEY_ADJUSTMENT: {const.KEY_BRIGHTNESS: 50}}
|
**{const.KEY_ADJUSTMENT: {const.KEY_BRIGHTNESS: 50, const.KEY_ID: TEST_ID}}
|
||||||
)
|
)
|
||||||
assert client.async_send_set_color.call_args == call(
|
assert client.async_send_set_color.call_args == call(
|
||||||
**{
|
**{
|
||||||
@ -405,6 +407,16 @@ async def test_light_async_turn_on(hass: HomeAssistantType) -> None:
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Simulate a false return of async_send_set_adjustment
|
||||||
|
client.async_send_set_adjustment = AsyncMock(return_value=False)
|
||||||
|
client.adjustment = [{const.KEY_ID: TEST_ID}]
|
||||||
|
await hass.services.async_call(
|
||||||
|
LIGHT_DOMAIN,
|
||||||
|
SERVICE_TURN_ON,
|
||||||
|
{ATTR_ENTITY_ID: TEST_ENTITY_ID_1, ATTR_BRIGHTNESS: brightness},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Simulate a state callback from Hyperion.
|
# Simulate a state callback from Hyperion.
|
||||||
client.adjustment = [{const.KEY_BRIGHTNESS: 50}]
|
client.adjustment = [{const.KEY_BRIGHTNESS: 50}]
|
||||||
_call_registered_callback(client, "adjustment-update")
|
_call_registered_callback(client, "adjustment-update")
|
||||||
@ -447,6 +459,7 @@ async def test_light_async_turn_on(hass: HomeAssistantType) -> None:
|
|||||||
brightness = 255
|
brightness = 255
|
||||||
client.async_send_set_color = AsyncMock(return_value=True)
|
client.async_send_set_color = AsyncMock(return_value=True)
|
||||||
client.async_send_set_adjustment = AsyncMock(return_value=True)
|
client.async_send_set_adjustment = AsyncMock(return_value=True)
|
||||||
|
client.adjustment = [{const.KEY_ID: TEST_ID}]
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
@ -456,7 +469,7 @@ async def test_light_async_turn_on(hass: HomeAssistantType) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert client.async_send_set_adjustment.call_args == call(
|
assert client.async_send_set_adjustment.call_args == call(
|
||||||
**{const.KEY_ADJUSTMENT: {const.KEY_BRIGHTNESS: 100}}
|
**{const.KEY_ADJUSTMENT: {const.KEY_BRIGHTNESS: 100, const.KEY_ID: TEST_ID}}
|
||||||
)
|
)
|
||||||
assert client.async_send_set_color.call_args == call(
|
assert client.async_send_set_color.call_args == call(
|
||||||
**{
|
**{
|
||||||
|
Loading…
Reference in New Issue
Block a user