2020-09-24 19:37:34 +00:00
|
|
|
"""Support for Hyperion-NG remotes."""
|
2015-10-17 17:36:52 +00:00
|
|
|
import logging
|
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
from hyperion import client, const
|
2016-09-11 07:24:25 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from homeassistant.components.light import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_BRIGHTNESS,
|
|
|
|
ATTR_EFFECT,
|
|
|
|
ATTR_HS_COLOR,
|
|
|
|
PLATFORM_SCHEMA,
|
|
|
|
SUPPORT_BRIGHTNESS,
|
|
|
|
SUPPORT_COLOR,
|
|
|
|
SUPPORT_EFFECT,
|
2020-04-26 16:49:41 +00:00
|
|
|
LightEntity,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-03-23 21:05:47 +00:00
|
|
|
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
|
2020-09-24 19:37:34 +00:00
|
|
|
from homeassistant.exceptions import PlatformNotReady
|
2016-09-11 07:24:25 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2018-03-18 22:00:29 +00:00
|
|
|
import homeassistant.util.color as color_util
|
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_PRIORITY = "priority"
|
|
|
|
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
|
|
|
|
# brightness for V4L), we need to persist the effect that is in flight, so
|
|
|
|
# subsequent calls to turn_on will know the keep the effect enabled.
|
|
|
|
# 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-09-24 19:37:34 +00:00
|
|
|
DEFAULT_ORIGIN = "Home Assistant"
|
2016-09-11 07:24:25 +00:00
|
|
|
DEFAULT_PORT = 19444
|
2017-10-30 20:48:42 +00:00
|
|
|
DEFAULT_PRIORITY = 128
|
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
|
2020-09-24 19:37:34 +00:00
|
|
|
DEFAULT_EFFECT_LIST = []
|
2019-07-31 19:25:30 +00:00
|
|
|
|
|
|
|
SUPPORT_HYPERION = SUPPORT_COLOR | SUPPORT_BRIGHTNESS | SUPPORT_EFFECT
|
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
PLATFORM_SCHEMA = vol.All(
|
|
|
|
cv.deprecated(CONF_HDMI_PRIORITY, invalidation_version="0.118"),
|
|
|
|
cv.deprecated(CONF_DEFAULT_COLOR, invalidation_version="0.118"),
|
|
|
|
cv.deprecated(CONF_EFFECT_LIST, invalidation_version="0.118"),
|
|
|
|
PLATFORM_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_HOST): cv.string,
|
|
|
|
vol.Required(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
|
|
|
vol.Optional(CONF_DEFAULT_COLOR, default=DEFAULT_COLOR): vol.All(
|
|
|
|
list,
|
|
|
|
vol.Length(min=3, max=3),
|
|
|
|
[vol.All(vol.Coerce(int), vol.Range(min=0, max=255))],
|
|
|
|
),
|
|
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
|
|
vol.Optional(CONF_PRIORITY, default=DEFAULT_PRIORITY): cv.positive_int,
|
|
|
|
vol.Optional(
|
|
|
|
CONF_HDMI_PRIORITY, default=DEFAULT_HDMI_PRIORITY
|
|
|
|
): cv.positive_int,
|
|
|
|
vol.Optional(CONF_EFFECT_LIST, default=DEFAULT_EFFECT_LIST): vol.All(
|
|
|
|
cv.ensure_list, [cv.string]
|
|
|
|
),
|
|
|
|
}
|
|
|
|
),
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
ICON_LIGHTBULB = "mdi:lightbulb"
|
|
|
|
ICON_EFFECT = "mdi:lava-lamp"
|
2020-10-21 09:00:19 +00:00
|
|
|
ICON_EXTERNAL_SOURCE = "mdi:television-ambient-light"
|
2020-09-24 19:37:34 +00:00
|
|
|
|
2016-09-11 07:24:25 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2017-05-01 03:10:08 +00:00
|
|
|
"""Set up a Hyperion server remote."""
|
2019-03-23 21:05:47 +00:00
|
|
|
name = config[CONF_NAME]
|
|
|
|
host = config[CONF_HOST]
|
|
|
|
port = config[CONF_PORT]
|
|
|
|
priority = config[CONF_PRIORITY]
|
2016-09-11 07:24:25 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
hyperion_client = client.HyperionClient(host, port)
|
|
|
|
|
|
|
|
if not await hyperion_client.async_client_connect():
|
|
|
|
raise PlatformNotReady
|
2016-09-11 07:24:25 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
async_add_entities([Hyperion(name, priority, hyperion_client)])
|
2015-10-17 17:36:52 +00:00
|
|
|
|
|
|
|
|
2020-04-26 16:49:41 +00:00
|
|
|
class Hyperion(LightEntity):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Representation of a Hyperion remote."""
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
def __init__(self, name, priority, hyperion_client):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Initialize the light."""
|
2016-04-19 15:19:27 +00:00
|
|
|
self._name = name
|
2017-10-30 20:48:42 +00:00
|
|
|
self._priority = priority
|
2020-09-24 19:37:34 +00:00
|
|
|
self._client = hyperion_client
|
|
|
|
|
|
|
|
# Active state representing the Hyperion instance.
|
|
|
|
self._set_internal_state(
|
|
|
|
brightness=255, rgb_color=DEFAULT_COLOR, effect=KEY_EFFECT_SOLID
|
|
|
|
)
|
|
|
|
self._effect_list = []
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
"""Return whether or not this entity should be polled."""
|
|
|
|
return False
|
2015-10-17 17:36:52 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
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
|
|
|
|
def brightness(self):
|
|
|
|
"""Return the brightness of this light between 0..255."""
|
|
|
|
return self._brightness
|
|
|
|
|
2015-10-17 17:36:52 +00:00
|
|
|
@property
|
2018-03-18 22:00:29 +00:00
|
|
|
def hs_color(self):
|
|
|
|
"""Return last color value set."""
|
|
|
|
return color_util.color_RGB_to_hs(*self._rgb_color)
|
2015-10-17 17:36:52 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-07-28 04:11:12 +00:00
|
|
|
"""Return true if not black."""
|
2020-09-24 19:37:34 +00:00
|
|
|
return self._client.is_on()
|
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
|
|
|
|
def icon(self):
|
|
|
|
"""Return state specific icon."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
|
|
|
def effect(self):
|
|
|
|
"""Return the current effect."""
|
|
|
|
return self._effect
|
|
|
|
|
|
|
|
@property
|
|
|
|
def effect_list(self):
|
|
|
|
"""Return the list of supported effects."""
|
2020-09-24 19:37:34 +00:00
|
|
|
return (
|
|
|
|
self._effect_list
|
|
|
|
+ const.KEY_COMPONENTID_EXTERNAL_SOURCES
|
|
|
|
+ [KEY_EFFECT_SOLID]
|
|
|
|
)
|
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
|
|
|
|
2016-08-16 06:07:07 +00:00
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_HYPERION
|
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Return server availability."""
|
|
|
|
return self._client.has_loaded_state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return a unique id for this instance."""
|
|
|
|
return self._client.id
|
|
|
|
|
|
|
|
async def async_turn_on(self, **kwargs):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Turn the lights on."""
|
2020-09-24 19:37:34 +00:00
|
|
|
# == Turn device on ==
|
|
|
|
# Turn on both ALL (Hyperion itself) and LEDDEVICE. It would be
|
|
|
|
# preferable to enable LEDDEVICE after the settings (e.g. brightness,
|
|
|
|
# color, effect), but this is not possible due to:
|
|
|
|
# https://github.com/hyperion-project/hyperion.ng/issues/967
|
|
|
|
if not self.is_on:
|
|
|
|
if not await self._client.async_send_set_component(
|
|
|
|
**{
|
|
|
|
const.KEY_COMPONENTSTATE: {
|
|
|
|
const.KEY_COMPONENT: const.KEY_COMPONENTID_ALL,
|
|
|
|
const.KEY_STATE: True,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
):
|
|
|
|
return
|
|
|
|
|
|
|
|
if not await self._client.async_send_set_component(
|
|
|
|
**{
|
|
|
|
const.KEY_COMPONENTSTATE: {
|
|
|
|
const.KEY_COMPONENT: const.KEY_COMPONENTID_LEDDEVICE,
|
|
|
|
const.KEY_STATE: True,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
):
|
|
|
|
return
|
|
|
|
|
|
|
|
# == Get key parameters ==
|
|
|
|
brightness = kwargs.get(ATTR_BRIGHTNESS, self._brightness)
|
|
|
|
effect = kwargs.get(ATTR_EFFECT, self._effect)
|
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 ==
|
|
|
|
if self._brightness != brightness:
|
|
|
|
if not await self._client.async_send_set_adjustment(
|
|
|
|
**{
|
|
|
|
const.KEY_ADJUSTMENT: {
|
|
|
|
const.KEY_BRIGHTNESS: int(
|
|
|
|
round((float(brightness) * 100) / 255)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
):
|
|
|
|
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 external source
|
|
|
|
if effect and effect in const.KEY_COMPONENTID_EXTERNAL_SOURCES:
|
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
|
|
|
# Clear any color/effect.
|
|
|
|
if not await self._client.async_send_clear(
|
|
|
|
**{const.KEY_PRIORITY: self._priority}
|
|
|
|
):
|
|
|
|
return
|
|
|
|
|
|
|
|
# Turn off all external sources, except the intended.
|
|
|
|
for key in const.KEY_COMPONENTID_EXTERNAL_SOURCES:
|
|
|
|
if not await self._client.async_send_set_component(
|
|
|
|
**{
|
|
|
|
const.KEY_COMPONENTSTATE: {
|
|
|
|
const.KEY_COMPONENT: key,
|
|
|
|
const.KEY_STATE: effect == key,
|
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
}
|
2020-09-24 19:37:34 +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
|
|
|
|
elif effect and effect != KEY_EFFECT_SOLID:
|
|
|
|
# This call should not be necessary, but without it there is no priorities-update issued:
|
|
|
|
# https://github.com/hyperion-project/hyperion.ng/issues/992
|
|
|
|
if not await self._client.async_send_clear(
|
|
|
|
**{const.KEY_PRIORITY: self._priority}
|
|
|
|
):
|
|
|
|
return
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
if not await self._client.async_send_set_effect(
|
|
|
|
**{
|
|
|
|
const.KEY_PRIORITY: self._priority,
|
|
|
|
const.KEY_EFFECT: {const.KEY_NAME: effect},
|
|
|
|
const.KEY_ORIGIN: DEFAULT_ORIGIN,
|
|
|
|
}
|
|
|
|
):
|
|
|
|
return
|
|
|
|
# == Set a color
|
|
|
|
else:
|
|
|
|
if not await self._client.async_send_set_color(
|
|
|
|
**{
|
|
|
|
const.KEY_PRIORITY: self._priority,
|
|
|
|
const.KEY_COLOR: rgb_color,
|
|
|
|
const.KEY_ORIGIN: DEFAULT_ORIGIN,
|
|
|
|
}
|
|
|
|
):
|
|
|
|
return
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
async def async_turn_off(self, **kwargs):
|
|
|
|
"""Disable the LED output component."""
|
|
|
|
if not await self._client.async_send_set_component(
|
|
|
|
**{
|
|
|
|
const.KEY_COMPONENTSTATE: {
|
|
|
|
const.KEY_COMPONENT: const.KEY_COMPONENTID_LEDDEVICE,
|
|
|
|
const.KEY_STATE: False,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
):
|
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
|
2015-10-17 17:36:52 +00:00
|
|
|
|
2020-09-24 19:37:34 +00:00
|
|
|
def _set_internal_state(self, brightness=None, rgb_color=None, effect=None):
|
|
|
|
"""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
|
|
|
|
if effect == KEY_EFFECT_SOLID:
|
|
|
|
self._icon = ICON_LIGHTBULB
|
|
|
|
elif effect in const.KEY_COMPONENTID_EXTERNAL_SOURCES:
|
|
|
|
self._icon = ICON_EXTERNAL_SOURCE
|
2015-10-17 17:36:52 +00:00
|
|
|
else:
|
2020-09-24 19:37:34 +00:00
|
|
|
self._icon = ICON_EFFECT
|
|
|
|
|
|
|
|
def _update_components(self, _=None):
|
|
|
|
"""Update Hyperion components."""
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
|
|
|
def _update_adjustment(self, _=None):
|
|
|
|
"""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()
|
|
|
|
|
|
|
|
def _update_priorities(self, _=None):
|
|
|
|
"""Update Hyperion priorities."""
|
|
|
|
visible_priority = self._client.visible_priority
|
|
|
|
if visible_priority:
|
|
|
|
componentid = visible_priority.get(const.KEY_COMPONENTID)
|
|
|
|
if componentid in const.KEY_COMPONENTID_EXTERNAL_SOURCES:
|
|
|
|
self._set_internal_state(rgb_color=DEFAULT_COLOR, effect=componentid)
|
|
|
|
elif componentid == const.KEY_COMPONENTID_EFFECT:
|
|
|
|
# Owner is the effect name.
|
|
|
|
# See: https://docs.hyperion-project.org/en/json/ServerInfo.html#priorities
|
|
|
|
self._set_internal_state(
|
|
|
|
rgb_color=DEFAULT_COLOR, effect=visible_priority[const.KEY_OWNER]
|
|
|
|
)
|
|
|
|
elif componentid == const.KEY_COMPONENTID_COLOR:
|
|
|
|
self._set_internal_state(
|
|
|
|
rgb_color=visible_priority[const.KEY_VALUE][const.KEY_RGB],
|
|
|
|
effect=KEY_EFFECT_SOLID,
|
|
|
|
)
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
|
|
|
def _update_effect_list(self, _=None):
|
|
|
|
"""Update Hyperion effects."""
|
|
|
|
if not self._client.effects:
|
|
|
|
return
|
|
|
|
effect_list = []
|
|
|
|
for effect in self._client.effects or []:
|
|
|
|
if const.KEY_NAME in effect:
|
|
|
|
effect_list.append(effect[const.KEY_NAME])
|
|
|
|
if effect_list:
|
|
|
|
self._effect_list = effect_list
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
|
|
|
def _update_full_state(self):
|
|
|
|
"""Update full Hyperion state."""
|
|
|
|
self._update_adjustment()
|
|
|
|
self._update_priorities()
|
|
|
|
self._update_effect_list()
|
|
|
|
|
|
|
|
_LOGGER.debug(
|
|
|
|
"Hyperion full state update: On=%s,Brightness=%i,Effect=%s "
|
|
|
|
"(%i effects total),Color=%s",
|
|
|
|
self.is_on,
|
|
|
|
self._brightness,
|
|
|
|
self._effect,
|
|
|
|
len(self._effect_list),
|
|
|
|
self._rgb_color,
|
|
|
|
)
|
|
|
|
|
|
|
|
def _update_client(self, json):
|
|
|
|
"""Update client connection state."""
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
|
|
|
async def async_added_to_hass(self):
|
|
|
|
"""Register callbacks when entity added to hass."""
|
|
|
|
self._client.set_callbacks(
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Load initial state.
|
|
|
|
self._update_full_state()
|
|
|
|
return True
|