Automatically select "Solid" effect in Hyperion (#43799)
This commit is contained in:
parent
b294e1c98c
commit
39601090ba
2 changed files with 50 additions and 5 deletions
|
@ -342,7 +342,7 @@ class HyperionLight(LightEntity):
|
|||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if not black."""
|
||||
return bool(self._client.is_on())
|
||||
return bool(self._client.is_on()) and self._client.visible_priority is not None
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
|
@ -413,7 +413,10 @@ class HyperionLight(LightEntity):
|
|||
|
||||
# == Get key parameters ==
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS, self._brightness)
|
||||
effect = kwargs.get(ATTR_EFFECT, self._effect)
|
||||
if ATTR_EFFECT not in kwargs and ATTR_HS_COLOR in kwargs:
|
||||
effect = KEY_EFFECT_SOLID
|
||||
else:
|
||||
effect = kwargs.get(ATTR_EFFECT, self._effect)
|
||||
rgb_color: Sequence[int]
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
rgb_color = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
|
||||
|
@ -549,7 +552,7 @@ class HyperionLight(LightEntity):
|
|||
rgb_color=visible_priority[const.KEY_VALUE][const.KEY_RGB],
|
||||
effect=KEY_EFFECT_SOLID,
|
||||
)
|
||||
self.async_write_ha_state()
|
||||
self.async_write_ha_state()
|
||||
|
||||
def _update_effect_list(self, _: Optional[Dict[str, Any]] = None) -> None:
|
||||
"""Update Hyperion effects."""
|
||||
|
|
|
@ -502,6 +502,36 @@ async def test_light_async_turn_on(hass: HomeAssistantType) -> None:
|
|||
assert entity_state.attributes["icon"] == hyperion_light.ICON_EFFECT
|
||||
assert entity_state.attributes["effect"] == effect
|
||||
|
||||
# On (=), 100% (=), [0,0,255] (!)
|
||||
# Ensure changing the color will move the effect to 'Solid' automatically.
|
||||
hs_color = (240.0, 100.0)
|
||||
client.async_send_set_color = AsyncMock(return_value=True)
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: TEST_ENTITY_ID_1, ATTR_HS_COLOR: hs_color},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert client.async_send_set_color.call_args == call(
|
||||
**{
|
||||
const.KEY_PRIORITY: TEST_PRIORITY,
|
||||
const.KEY_COLOR: (0, 0, 255),
|
||||
const.KEY_ORIGIN: hyperion_light.DEFAULT_ORIGIN,
|
||||
}
|
||||
)
|
||||
# Simulate a state callback from Hyperion.
|
||||
client.visible_priority = {
|
||||
const.KEY_COMPONENTID: const.KEY_COMPONENTID_COLOR,
|
||||
const.KEY_VALUE: {const.KEY_RGB: (0, 0, 255)},
|
||||
}
|
||||
_call_registered_callback(client, "priorities-update")
|
||||
entity_state = hass.states.get(TEST_ENTITY_ID_1)
|
||||
assert entity_state
|
||||
assert entity_state.attributes["hs_color"] == hs_color
|
||||
assert entity_state.attributes["icon"] == hyperion_light.ICON_LIGHTBULB
|
||||
assert entity_state.attributes["effect"] == hyperion_light.KEY_EFFECT_SOLID
|
||||
|
||||
# No calls if disconnected.
|
||||
client.has_loaded_state = False
|
||||
_call_registered_callback(client, "client-update", {"loaded-state": False})
|
||||
|
@ -627,6 +657,14 @@ async def test_light_async_updates_from_hyperion_client(
|
|||
assert entity_state.attributes["icon"] == hyperion_light.ICON_LIGHTBULB
|
||||
assert entity_state.attributes["hs_color"] == (180.0, 100.0)
|
||||
|
||||
# Update priorities (None)
|
||||
client.visible_priority = None
|
||||
|
||||
_call_registered_callback(client, "priorities-update")
|
||||
entity_state = hass.states.get(TEST_ENTITY_ID_1)
|
||||
assert entity_state
|
||||
assert entity_state.state == "off"
|
||||
|
||||
# Update effect list
|
||||
effects = [{const.KEY_NAME: "One"}, {const.KEY_NAME: "Two"}]
|
||||
client.effects = effects
|
||||
|
@ -648,6 +686,10 @@ async def test_light_async_updates_from_hyperion_client(
|
|||
|
||||
# Update connection status (e.g. re-connection)
|
||||
client.has_loaded_state = True
|
||||
client.visible_priority = {
|
||||
const.KEY_COMPONENTID: const.KEY_COMPONENTID_COLOR,
|
||||
const.KEY_VALUE: {const.KEY_RGB: rgb},
|
||||
}
|
||||
_call_registered_callback(client, "client-update", {"loaded-state": True})
|
||||
entity_state = hass.states.get(TEST_ENTITY_ID_1)
|
||||
assert entity_state
|
||||
|
@ -691,7 +733,7 @@ async def test_unload_entry(hass: HomeAssistantType) -> None:
|
|||
assert client.async_client_disconnect.call_count == 2
|
||||
|
||||
|
||||
async def test_version_log_warning(caplog, hass: HomeAssistantType) -> None:
|
||||
async def test_version_log_warning(caplog, hass: HomeAssistantType) -> None: # type: ignore[no-untyped-def]
|
||||
"""Test warning on old version."""
|
||||
client = create_mock_client()
|
||||
client.async_sysinfo_version = AsyncMock(return_value="2.0.0-alpha.7")
|
||||
|
@ -700,7 +742,7 @@ async def test_version_log_warning(caplog, hass: HomeAssistantType) -> None:
|
|||
assert "Please consider upgrading" in caplog.text
|
||||
|
||||
|
||||
async def test_version_no_log_warning(caplog, hass: HomeAssistantType) -> None:
|
||||
async def test_version_no_log_warning(caplog, hass: HomeAssistantType) -> None: # type: ignore[no-untyped-def]
|
||||
"""Test no warning on acceptable version."""
|
||||
client = create_mock_client()
|
||||
client.async_sysinfo_version = AsyncMock(return_value="2.0.0-alpha.9")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue