mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-16 16:54:04 +02:00
Merge branch 'main' into correctly-fix-timers
This commit is contained in:
commit
36e588e2a6
5 changed files with 112 additions and 19 deletions
|
|
@ -6,7 +6,6 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|||
from homeassistant.const import CONF_SOURCE
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.reload import async_setup_reload_service
|
||||
import voluptuous as vol
|
||||
|
||||
from .const import (
|
||||
|
|
@ -36,10 +35,13 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
)
|
||||
|
||||
|
||||
async def reload_configuration_yaml(event: dict, hass: HomeAssistant):
|
||||
"""Reload configuration.yaml."""
|
||||
await hass.services.async_call("homeassistant", "check_config", {})
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict[str, Any]):
|
||||
"""Import integration from config."""
|
||||
# This will reload any changes the user made to any YAML configurations.
|
||||
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
|
||||
|
||||
if DOMAIN in config:
|
||||
for entry in config[DOMAIN]:
|
||||
|
|
@ -55,6 +57,10 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
|||
"""Set up the component."""
|
||||
data = hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
# This will reload any changes the user made to any YAML configurations.
|
||||
# Called during 'quick reload' or hass.reload_config_entry
|
||||
hass.bus.async_listen("hass.config.entry_updated", reload_configuration_yaml)
|
||||
|
||||
undo_listener = config_entry.add_update_listener(async_update_options)
|
||||
data[config_entry.entry_id] = {UNDO_UPDATE_LISTENER: undo_listener}
|
||||
for platform in PLATFORMS:
|
||||
|
|
|
|||
|
|
@ -155,12 +155,13 @@ from .const import (
|
|||
)
|
||||
|
||||
_SUPPORT_OPTS = {
|
||||
"brightness": SUPPORT_BRIGHTNESS,
|
||||
"color_temp": SUPPORT_COLOR_TEMP,
|
||||
"color": SUPPORT_COLOR,
|
||||
"transition": SUPPORT_TRANSITION,
|
||||
COLOR_MODE_BRIGHTNESS: SUPPORT_BRIGHTNESS,
|
||||
COLOR_MODE_COLOR_TEMP: SUPPORT_COLOR_TEMP,
|
||||
CONST_COLOR: SUPPORT_COLOR,
|
||||
ATTR_TRANSITION: SUPPORT_TRANSITION,
|
||||
}
|
||||
|
||||
|
||||
VALID_COLOR_MODES = {
|
||||
COLOR_MODE_BRIGHTNESS: ATTR_BRIGHTNESS,
|
||||
COLOR_MODE_COLOR_TEMP: ATTR_COLOR_TEMP_KELVIN,
|
||||
|
|
@ -642,16 +643,18 @@ def _expand_light_groups(hass: HomeAssistant, lights: list[str]) -> list[str]:
|
|||
def _supported_to_attributes(supported):
|
||||
supported_attributes = {}
|
||||
supports_colors = False
|
||||
for mode, attr in VALID_COLOR_MODES.items():
|
||||
if mode not in supported:
|
||||
continue
|
||||
supported_attributes[attr] = True
|
||||
if (
|
||||
not supports_colors
|
||||
and mode != COLOR_MODE_BRIGHTNESS
|
||||
and mode != COLOR_MODE_COLOR_TEMP
|
||||
):
|
||||
supports_colors = True
|
||||
for mode in supported:
|
||||
attr = VALID_COLOR_MODES.get(mode)
|
||||
if attr:
|
||||
supported_attributes[attr] = True
|
||||
if attr in COLOR_ATTRS:
|
||||
supports_colors = True
|
||||
# ATTR_SUPPORTED_FEATURES only
|
||||
elif mode in _SUPPORT_OPTS:
|
||||
supported_attributes[mode] = True
|
||||
if CONST_COLOR in supported_attributes:
|
||||
supports_colors = True
|
||||
supported_attributes.pop(CONST_COLOR)
|
||||
return supported_attributes, supports_colors
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue