2020-09-24 19:37:34 +00:00
|
|
|
"""Support for Hyperion-NG remotes."""
|
2020-11-30 17:38:52 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-09-29 14:19:06 +00:00
|
|
|
from collections.abc import Callable, Mapping, Sequence
|
2021-02-08 09:45:46 +00:00
|
|
|
import functools
|
2015-10-17 17:36:52 +00:00
|
|
|
import logging
|
2020-11-30 17:38:52 +00:00
|
|
|
from types import MappingProxyType
|
2021-09-29 14:19:06 +00:00
|
|
|
from typing import Any
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
from hyperion import client, const
|
2016-09-11 07:24:25 +00:00
|
|
|
|
|
|
|
from homeassistant.components.light import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_BRIGHTNESS,
|
|
|
|
ATTR_EFFECT,
|
|
|
|
ATTR_HS_COLOR,
|
2022-04-23 19:15:54 +00:00
|
|
|
ColorMode,
|
2020-04-26 16:49:41 +00:00
|
|
|
LightEntity,
|
2022-04-06 09:59:23 +00:00
|
|
|
LightEntityFeature,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2021-01-29 08:05:00 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-04-23 08:11:58 +00:00
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2020-11-30 17:38:52 +00:00
|
|
|
from homeassistant.helpers.dispatcher import (
|
|
|
|
async_dispatcher_connect,
|
|
|
|
async_dispatcher_send,
|
|
|
|
)
|
2021-04-30 21:21:39 +00:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
2021-05-04 21:36:48 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2018-03-18 22:00:29 +00:00
|
|
|
import homeassistant.util.color as color_util
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2021-04-13 08:35:38 +00:00
|
|
|
from . import (
|
|
|
|
get_hyperion_device_id,
|
|
|
|
get_hyperion_unique_id,
|
|
|
|
listen_for_instance_updates,
|
|
|
|
)
|
2020-11-30 17:38:52 +00:00
|
|
|
from .const import (
|
2021-03-22 14:59:12 +00:00
|
|
|
CONF_EFFECT_HIDE_LIST,
|
2021-01-27 08:35:13 +00:00
|
|
|
CONF_INSTANCE_CLIENTS,
|
2020-11-30 17:38:52 +00:00
|
|
|
CONF_PRIORITY,
|
|
|
|
DEFAULT_ORIGIN,
|
|
|
|
DEFAULT_PRIORITY,
|
|
|
|
DOMAIN,
|
2021-04-13 08:35:38 +00:00
|
|
|
HYPERION_MANUFACTURER_NAME,
|
|
|
|
HYPERION_MODEL_NAME,
|
2021-01-27 08:35:13 +00:00
|
|
|
SIGNAL_ENTITY_REMOVE,
|
2020-11-30 17:38:52 +00:00
|
|
|
TYPE_HYPERION_LIGHT,
|
|
|
|
)
|
|
|
|
|
2015-10-17 17:36:52 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2016-09-11 07:24:25 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_DEFAULT_COLOR = "default_color"
|
|
|
|
CONF_HDMI_PRIORITY = "hdmi_priority"
|
|
|
|
CONF_EFFECT_LIST = "effect_list"
|
2016-09-11 07:24:25 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
# As we want to preserve brightness control for effects (e.g. to reduce the
|
2023-06-28 11:51:42 +00:00
|
|
|
# brightness), we need to persist the effect that is in flight, so
|
|
|
|
# subsequent calls to turn_on will know to keep the effect enabled.
|
2020-09-24 19:37:34 +00:00
|
|
|
# Unfortunately the Home Assistant UI does not easily expose a way to remove a
|
|
|
|
# selected effect (there is no 'No Effect' option by default). Instead, we
|
|
|
|
# create a new fake effect ("Solid") that is always selected by default for
|
|
|
|
# showing a solid color. This is the same method used by WLED.
|
|
|
|
KEY_EFFECT_SOLID = "Solid"
|
|
|
|
|
2016-09-11 07:24:25 +00:00
|
|
|
DEFAULT_COLOR = [255, 255, 255]
|
2020-09-24 19:37:34 +00:00
|
|
|
DEFAULT_BRIGHTNESS = 255
|
|
|
|
DEFAULT_EFFECT = KEY_EFFECT_SOLID
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_NAME = "Hyperion"
|
2020-11-30 17:38:52 +00:00
|
|
|
DEFAULT_PORT = const.DEFAULT_PORT_JSON
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
DEFAULT_HDMI_PRIORITY = 880
|
2021-03-18 08:25:40 +00:00
|
|
|
DEFAULT_EFFECT_LIST: list[str] = []
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
ICON_LIGHTBULB = "mdi:lightbulb"
|
|
|
|
ICON_EFFECT = "mdi:lava-lamp"
|
|
|
|
|
2016-09-11 07:24:25 +00:00
|
|
|
|
2020-11-30 17:38:52 +00:00
|
|
|
async def async_setup_entry(
|
2021-05-04 21:36:48 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
2022-01-12 11:53:50 +00:00
|
|
|
) -> None:
|
2020-11-30 17:38:52 +00:00
|
|
|
"""Set up a Hyperion platform from config entry."""
|
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
entry_data = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
server_id = config_entry.unique_id
|
2021-01-26 20:39:02 +00:00
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@callback
|
|
|
|
def instance_add(instance_num: int, instance_name: str) -> None:
|
|
|
|
"""Add entities for a new Hyperion instance."""
|
|
|
|
assert server_id
|
2021-04-13 08:35:38 +00:00
|
|
|
args = (
|
|
|
|
server_id,
|
|
|
|
instance_num,
|
|
|
|
instance_name,
|
|
|
|
config_entry.options,
|
|
|
|
entry_data[CONF_INSTANCE_CLIENTS][instance_num],
|
|
|
|
)
|
2021-01-27 08:35:13 +00:00
|
|
|
async_add_entities(
|
|
|
|
[
|
2021-04-13 08:35:38 +00:00
|
|
|
HyperionLight(*args),
|
2021-01-27 08:35:13 +00:00
|
|
|
]
|
|
|
|
)
|
2020-11-30 17:38:52 +00:00
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@callback
|
|
|
|
def instance_remove(instance_num: int) -> None:
|
|
|
|
"""Remove entities for an old Hyperion instance."""
|
|
|
|
assert server_id
|
2023-06-28 11:51:42 +00:00
|
|
|
async_dispatcher_send(
|
|
|
|
hass,
|
|
|
|
SIGNAL_ENTITY_REMOVE.format(
|
|
|
|
get_hyperion_unique_id(server_id, instance_num, TYPE_HYPERION_LIGHT)
|
|
|
|
),
|
|
|
|
)
|
2020-11-30 17:38:52 +00:00
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
listen_for_instance_updates(hass, config_entry, instance_add, instance_remove)
|
2020-11-30 17:38:52 +00:00
|
|
|
|
|
|
|
|
2023-06-28 11:51:42 +00:00
|
|
|
class HyperionLight(LightEntity):
|
|
|
|
"""A Hyperion light that acts as a client for the configured priority."""
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2022-04-23 19:15:54 +00:00
|
|
|
_attr_color_mode = ColorMode.HS
|
2022-08-26 08:20:38 +00:00
|
|
|
_attr_should_poll = False
|
2022-04-23 19:15:54 +00:00
|
|
|
_attr_supported_color_modes = {ColorMode.HS}
|
2022-04-06 09:59:23 +00:00
|
|
|
_attr_supported_features = LightEntityFeature.EFFECT
|
2022-04-04 15:39:21 +00:00
|
|
|
|
2020-11-30 17:38:52 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
2021-04-13 08:35:38 +00:00
|
|
|
server_id: str,
|
|
|
|
instance_num: int,
|
|
|
|
instance_name: str,
|
2020-11-30 17:38:52 +00:00
|
|
|
options: MappingProxyType[str, Any],
|
|
|
|
hyperion_client: client.HyperionClient,
|
|
|
|
) -> None:
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Initialize the light."""
|
2021-04-13 08:35:38 +00:00
|
|
|
self._unique_id = self._compute_unique_id(server_id, instance_num)
|
|
|
|
self._name = self._compute_name(instance_name)
|
|
|
|
self._device_id = get_hyperion_device_id(server_id, instance_num)
|
|
|
|
self._instance_name = instance_name
|
2020-11-30 17:38:52 +00:00
|
|
|
self._options = options
|
2020-09-24 19:37:34 +00:00
|
|
|
self._client = hyperion_client
|
|
|
|
|
|
|
|
# Active state representing the Hyperion instance.
|
2020-11-30 17:38:52 +00:00
|
|
|
self._brightness: int = 255
|
|
|
|
self._rgb_color: Sequence[int] = DEFAULT_COLOR
|
|
|
|
self._effect: str = KEY_EFFECT_SOLID
|
|
|
|
|
2021-03-18 08:25:40 +00:00
|
|
|
self._static_effect_list: list[str] = [KEY_EFFECT_SOLID]
|
|
|
|
self._effect_list: list[str] = self._static_effect_list[:]
|
2021-01-27 08:35:13 +00:00
|
|
|
|
2021-03-18 08:25:40 +00:00
|
|
|
self._client_callbacks: Mapping[str, Callable[[dict[str, Any]], None]] = {
|
2021-01-27 08:35:13 +00:00
|
|
|
f"{const.KEY_ADJUSTMENT}-{const.KEY_UPDATE}": self._update_adjustment,
|
|
|
|
f"{const.KEY_COMPONENTS}-{const.KEY_UPDATE}": self._update_components,
|
|
|
|
f"{const.KEY_EFFECTS}-{const.KEY_UPDATE}": self._update_effect_list,
|
|
|
|
f"{const.KEY_PRIORITIES}-{const.KEY_UPDATE}": self._update_priorities,
|
|
|
|
f"{const.KEY_CLIENT}-{const.KEY_UPDATE}": self._update_client,
|
|
|
|
}
|
|
|
|
|
2021-04-13 08:35:38 +00:00
|
|
|
def _compute_unique_id(self, server_id: str, instance_num: int) -> str:
|
|
|
|
"""Compute a unique id for this instance."""
|
2023-06-28 11:51:42 +00:00
|
|
|
return get_hyperion_unique_id(server_id, instance_num, TYPE_HYPERION_LIGHT)
|
2021-04-13 08:35:38 +00:00
|
|
|
|
|
|
|
def _compute_name(self, instance_name: str) -> str:
|
|
|
|
"""Compute the name of the light."""
|
2023-06-28 11:51:42 +00:00
|
|
|
return f"{instance_name}".strip()
|
2021-04-13 08:35:38 +00:00
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@property
|
|
|
|
def entity_registry_enabled_default(self) -> bool:
|
|
|
|
"""Whether or not the entity is enabled by default."""
|
|
|
|
return True
|
2020-09-24 19:37:34 +00:00
|
|
|
|
2015-10-17 17:36:52 +00:00
|
|
|
@property
|
2020-11-30 17:38:52 +00:00
|
|
|
def name(self) -> str:
|
2017-07-09 22:06:31 +00:00
|
|
|
"""Return the name of the light."""
|
2015-10-17 17:36:52 +00:00
|
|
|
return self._name
|
|
|
|
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
@property
|
2020-11-30 17:38:52 +00:00
|
|
|
def brightness(self) -> int:
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
"""Return the brightness of this light between 0..255."""
|
|
|
|
return self._brightness
|
|
|
|
|
2015-10-17 17:36:52 +00:00
|
|
|
@property
|
2021-03-18 08:25:40 +00:00
|
|
|
def hs_color(self) -> tuple[float, float]:
|
2018-03-18 22:00:29 +00:00
|
|
|
"""Return last color value set."""
|
|
|
|
return color_util.color_RGB_to_hs(*self._rgb_color)
|
2015-10-17 17:36:52 +00:00
|
|
|
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
@property
|
2020-11-30 17:38:52 +00:00
|
|
|
def icon(self) -> str:
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
"""Return state specific icon."""
|
2021-01-26 09:46:54 +00:00
|
|
|
if self.is_on:
|
|
|
|
if self.effect != KEY_EFFECT_SOLID:
|
|
|
|
return ICON_EFFECT
|
|
|
|
return ICON_LIGHTBULB
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
|
|
|
|
@property
|
2020-11-30 17:38:52 +00:00
|
|
|
def effect(self) -> str:
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
"""Return the current effect."""
|
|
|
|
return self._effect
|
|
|
|
|
|
|
|
@property
|
2021-03-18 08:25:40 +00:00
|
|
|
def effect_list(self) -> list[str]:
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
"""Return the list of supported effects."""
|
2021-01-27 08:35:13 +00:00
|
|
|
return self._effect_list
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
@property
|
2020-11-30 17:38:52 +00:00
|
|
|
def available(self) -> bool:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Return server availability."""
|
2020-11-30 17:38:52 +00:00
|
|
|
return bool(self._client.has_loaded_state)
|
2020-09-24 19:37:34 +00:00
|
|
|
|
|
|
|
@property
|
2020-11-30 17:38:52 +00:00
|
|
|
def unique_id(self) -> str:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Return a unique id for this instance."""
|
2020-11-30 17:38:52 +00:00
|
|
|
return self._unique_id
|
|
|
|
|
2021-04-13 08:35:38 +00:00
|
|
|
@property
|
2021-04-30 21:21:39 +00:00
|
|
|
def device_info(self) -> DeviceInfo:
|
2021-04-13 08:35:38 +00:00
|
|
|
"""Return device information."""
|
2021-10-23 13:35:33 +00:00
|
|
|
return DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, self._device_id)},
|
|
|
|
manufacturer=HYPERION_MANUFACTURER_NAME,
|
|
|
|
model=HYPERION_MODEL_NAME,
|
|
|
|
name=self._instance_name,
|
2022-03-05 08:10:39 +00:00
|
|
|
configuration_url=self._client.remote_url,
|
2021-10-23 13:35:33 +00:00
|
|
|
)
|
2021-04-13 08:35:38 +00:00
|
|
|
|
2020-11-30 17:38:52 +00:00
|
|
|
def _get_option(self, key: str) -> Any:
|
|
|
|
"""Get a value from the provided options."""
|
2021-03-22 14:59:12 +00:00
|
|
|
defaults = {
|
|
|
|
CONF_PRIORITY: DEFAULT_PRIORITY,
|
|
|
|
CONF_EFFECT_HIDE_LIST: [],
|
|
|
|
}
|
2020-11-30 17:38:52 +00:00
|
|
|
return self._options.get(key, defaults[key])
|
2020-09-24 19:37:34 +00:00
|
|
|
|
2023-06-28 11:51:42 +00:00
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if light is on. Light is considered on when there is a source at the configured HA priority."""
|
|
|
|
return self._get_priority_entry_that_dictates_state() is not None
|
|
|
|
|
2020-11-30 17:38:52 +00:00
|
|
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
2021-01-27 08:35:13 +00:00
|
|
|
"""Turn on the light."""
|
2020-09-24 19:37:34 +00:00
|
|
|
# == Get key parameters ==
|
2020-12-02 18:40:49 +00:00
|
|
|
if ATTR_EFFECT not in kwargs and ATTR_HS_COLOR in kwargs:
|
|
|
|
effect = KEY_EFFECT_SOLID
|
|
|
|
else:
|
|
|
|
effect = kwargs.get(ATTR_EFFECT, self._effect)
|
2020-11-30 17:38:52 +00:00
|
|
|
rgb_color: Sequence[int]
|
2018-03-18 22:00:29 +00:00
|
|
|
if ATTR_HS_COLOR in kwargs:
|
|
|
|
rgb_color = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
|
2016-07-28 04:11:12 +00:00
|
|
|
else:
|
2020-09-24 19:37:34 +00:00
|
|
|
rgb_color = self._rgb_color
|
|
|
|
|
|
|
|
# == Set brightness ==
|
2021-01-26 09:45:41 +00:00
|
|
|
if ATTR_BRIGHTNESS in kwargs:
|
|
|
|
brightness = kwargs[ATTR_BRIGHTNESS]
|
2021-03-01 17:10:28 +00:00
|
|
|
for item in self._client.adjustment or []:
|
2021-03-27 10:30:29 +00:00
|
|
|
if (
|
|
|
|
const.KEY_ID in item
|
|
|
|
and not await self._client.async_send_set_adjustment(
|
2021-01-26 09:45:41 +00:00
|
|
|
**{
|
|
|
|
const.KEY_ADJUSTMENT: {
|
|
|
|
const.KEY_BRIGHTNESS: int(
|
|
|
|
round((float(brightness) * 100) / 255)
|
|
|
|
),
|
|
|
|
const.KEY_ID: item[const.KEY_ID],
|
|
|
|
}
|
|
|
|
}
|
2021-03-27 10:30:29 +00:00
|
|
|
)
|
|
|
|
):
|
|
|
|
return
|
Hyperion: Add brightness, HDMI and effect support (#11543)
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
* Hyperion: Add brightness, HDMI and effect support
- added brightness support to dim the hyperion light
- changed the "OFF" command to set the color to [0,0,0] after clearing all priorities.
This is neccesary to keep the light turned off when an HDMI grabber is used for ambilight with hyperion.
- added HDMI ambilight mode recognition and control.
by setting the "hdmi_priority" in your "configuration.yaml" file (defaults to 880), home assistant will now be able to recognize when the hyperion light is in HDMI ambilight mode and will change its icon to an HDMI symbol and set the status to ON.
Switching the hyperion light to HDMI ambilight mode can be done through the effect option (clears all priorities such that the HDMI grabber remains).
- added effect support for the default effects of hyperion, a custom list can be defined in the "configuration.yaml" file by using the "effect_list" option.
- fixed some style issues with too long lines
* Hyperion: Add brightness, HDMI and effect support
- fixed some more indentation style issues
* Hyperion: Add brightness, HDMI and effect support
- yet more fixed visuel indent issues
* Hyperion: Add brightness, HDMI and effect support
- more visuel indents
* Hyperion: Add brightness, HDMI and effect support
- fixed invalid variable "A"
* Hyperion: Add brightness, HDMI and effect support
- remove unnececary brackets
- specify specific exceptions
* correct changing state holding attributes during a service method
Proccesed the comments of @MartinHjelmare: https://github.com/home-assistant/home-assistant/pull/11543#pullrequestreview-88328659
* indent correction
corrected tab instead of 4 spaces
* Hyperion: Add brightness, HDMI and effect support
- changed 'none' to None
- renamed "self._skip_check" to "self._skip_update"
* Add brightness, HDMI and effect support
changed checking if a list is empty from "list == []" to "not list"
2018-01-13 20:06:34 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
# == Set an effect
|
2023-06-28 11:51:42 +00:00
|
|
|
if effect and effect != KEY_EFFECT_SOLID:
|
2020-09-24 19:37:34 +00:00
|
|
|
if not await self._client.async_send_set_effect(
|
|
|
|
**{
|
2020-11-30 17:38:52 +00:00
|
|
|
const.KEY_PRIORITY: self._get_option(CONF_PRIORITY),
|
2020-09-24 19:37:34 +00:00
|
|
|
const.KEY_EFFECT: {const.KEY_NAME: effect},
|
|
|
|
const.KEY_ORIGIN: DEFAULT_ORIGIN,
|
|
|
|
}
|
|
|
|
):
|
|
|
|
return
|
2023-06-28 11:51:42 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
# == Set a color
|
2023-06-27 15:42:46 +00:00
|
|
|
elif not await self._client.async_send_set_color(
|
|
|
|
**{
|
|
|
|
const.KEY_PRIORITY: self._get_option(CONF_PRIORITY),
|
|
|
|
const.KEY_COLOR: rgb_color,
|
|
|
|
const.KEY_ORIGIN: DEFAULT_ORIGIN,
|
|
|
|
}
|
|
|
|
):
|
|
|
|
return
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2023-06-28 11:51:42 +00:00
|
|
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
|
|
|
"""Turn off the light i.e. clear the configured priority."""
|
|
|
|
if not await self._client.async_send_clear(
|
|
|
|
**{const.KEY_PRIORITY: self._get_option(CONF_PRIORITY)}
|
|
|
|
):
|
|
|
|
return
|
|
|
|
|
2020-11-30 17:38:52 +00:00
|
|
|
def _set_internal_state(
|
|
|
|
self,
|
2021-03-18 08:25:40 +00:00
|
|
|
brightness: int | None = None,
|
|
|
|
rgb_color: Sequence[int] | None = None,
|
|
|
|
effect: str | None = None,
|
2020-11-30 17:38:52 +00:00
|
|
|
) -> None:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Set the internal state."""
|
|
|
|
if brightness is not None:
|
|
|
|
self._brightness = brightness
|
|
|
|
if rgb_color is not None:
|
|
|
|
self._rgb_color = rgb_color
|
|
|
|
if effect is not None:
|
|
|
|
self._effect = effect
|
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@callback
|
2021-03-18 08:25:40 +00:00
|
|
|
def _update_components(self, _: dict[str, Any] | None = None) -> None:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Update Hyperion components."""
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@callback
|
2021-03-18 08:25:40 +00:00
|
|
|
def _update_adjustment(self, _: dict[str, Any] | None = None) -> None:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Update Hyperion adjustments."""
|
|
|
|
if self._client.adjustment:
|
|
|
|
brightness_pct = self._client.adjustment[0].get(
|
|
|
|
const.KEY_BRIGHTNESS, DEFAULT_BRIGHTNESS
|
|
|
|
)
|
|
|
|
if brightness_pct < 0 or brightness_pct > 100:
|
|
|
|
return
|
|
|
|
self._set_internal_state(
|
|
|
|
brightness=int(round((brightness_pct * 255) / float(100)))
|
|
|
|
)
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@callback
|
2021-03-18 08:25:40 +00:00
|
|
|
def _update_priorities(self, _: dict[str, Any] | None = None) -> None:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Update Hyperion priorities."""
|
2021-01-27 08:35:13 +00:00
|
|
|
priority = self._get_priority_entry_that_dictates_state()
|
2023-06-28 11:51:42 +00:00
|
|
|
if priority:
|
|
|
|
component_id = priority.get(const.KEY_COMPONENTID)
|
|
|
|
if component_id == const.KEY_COMPONENTID_EFFECT:
|
2020-09-24 19:37:34 +00:00
|
|
|
# Owner is the effect name.
|
|
|
|
# See: https://docs.hyperion-project.org/en/json/ServerInfo.html#priorities
|
|
|
|
self._set_internal_state(
|
2021-01-27 08:35:13 +00:00
|
|
|
rgb_color=DEFAULT_COLOR, effect=priority[const.KEY_OWNER]
|
2020-09-24 19:37:34 +00:00
|
|
|
)
|
2023-06-28 11:51:42 +00:00
|
|
|
elif component_id == const.KEY_COMPONENTID_COLOR:
|
2020-09-24 19:37:34 +00:00
|
|
|
self._set_internal_state(
|
2021-01-27 08:35:13 +00:00
|
|
|
rgb_color=priority[const.KEY_VALUE][const.KEY_RGB],
|
2020-09-24 19:37:34 +00:00
|
|
|
effect=KEY_EFFECT_SOLID,
|
|
|
|
)
|
2020-12-02 18:40:49 +00:00
|
|
|
self.async_write_ha_state()
|
2020-09-24 19:37:34 +00:00
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@callback
|
2021-03-18 08:25:40 +00:00
|
|
|
def _update_effect_list(self, _: dict[str, Any] | None = None) -> None:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Update Hyperion effects."""
|
|
|
|
if not self._client.effects:
|
|
|
|
return
|
2021-03-18 08:25:40 +00:00
|
|
|
effect_list: list[str] = []
|
2021-03-22 14:59:12 +00:00
|
|
|
hide_effects = self._get_option(CONF_EFFECT_HIDE_LIST)
|
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
for effect in self._client.effects or []:
|
|
|
|
if const.KEY_NAME in effect:
|
2021-03-22 14:59:12 +00:00
|
|
|
effect_name = effect[const.KEY_NAME]
|
|
|
|
if effect_name not in hide_effects:
|
|
|
|
effect_list.append(effect_name)
|
|
|
|
|
|
|
|
self._effect_list = [
|
|
|
|
effect for effect in self._static_effect_list if effect not in hide_effects
|
|
|
|
] + effect_list
|
|
|
|
self.async_write_ha_state()
|
2020-09-24 19:37:34 +00:00
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@callback
|
2020-11-30 17:38:52 +00:00
|
|
|
def _update_full_state(self) -> None:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Update full Hyperion state."""
|
|
|
|
self._update_adjustment()
|
|
|
|
self._update_priorities()
|
|
|
|
self._update_effect_list()
|
|
|
|
|
|
|
|
_LOGGER.debug(
|
2022-12-22 10:38:59 +00:00
|
|
|
(
|
|
|
|
"Hyperion full state update: On=%s,Brightness=%i,Effect=%s "
|
|
|
|
"(%i effects total),Color=%s"
|
|
|
|
),
|
2020-09-24 19:37:34 +00:00
|
|
|
self.is_on,
|
|
|
|
self._brightness,
|
|
|
|
self._effect,
|
|
|
|
len(self._effect_list),
|
|
|
|
self._rgb_color,
|
|
|
|
)
|
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
@callback
|
2021-03-18 08:25:40 +00:00
|
|
|
def _update_client(self, _: dict[str, Any] | None = None) -> None:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Update client connection state."""
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
2020-11-30 17:38:52 +00:00
|
|
|
async def async_added_to_hass(self) -> None:
|
2020-09-24 19:37:34 +00:00
|
|
|
"""Register callbacks when entity added to hass."""
|
2020-11-30 17:38:52 +00:00
|
|
|
self.async_on_remove(
|
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass,
|
2021-04-13 08:35:38 +00:00
|
|
|
SIGNAL_ENTITY_REMOVE.format(self.unique_id),
|
2021-02-08 09:45:46 +00:00
|
|
|
functools.partial(self.async_remove, force_remove=True),
|
2020-11-30 17:38:52 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-01-27 08:35:13 +00:00
|
|
|
self._client.add_callbacks(self._client_callbacks)
|
2020-09-24 19:37:34 +00:00
|
|
|
|
|
|
|
# Load initial state.
|
|
|
|
self._update_full_state()
|
2020-11-30 17:38:52 +00:00
|
|
|
|
|
|
|
async def async_will_remove_from_hass(self) -> None:
|
2021-01-27 08:35:13 +00:00
|
|
|
"""Cleanup prior to hass removal."""
|
|
|
|
self._client.remove_callbacks(self._client_callbacks)
|
|
|
|
|
2021-03-18 08:25:40 +00:00
|
|
|
def _get_priority_entry_that_dictates_state(self) -> dict[str, Any] | None:
|
2021-01-27 08:35:13 +00:00
|
|
|
"""Get the relevant Hyperion priority entry to consider."""
|
2023-06-28 11:51:42 +00:00
|
|
|
# Return whether or not the HA priority is among the active priorities.
|
|
|
|
for priority in self._client.priorities or []:
|
|
|
|
if priority.get(const.KEY_PRIORITY) == self._get_option(CONF_PRIORITY):
|
|
|
|
return priority
|
2021-01-27 08:35:13 +00:00
|
|
|
return None
|