Migrate yeelight to use HassKey for shared custom effects (#169268)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
epenet
2026-04-27 11:31:35 +02:00
committed by GitHub
parent 86af61d7b5
commit 605eea6274
3 changed files with 10 additions and 12 deletions
@@ -37,7 +37,7 @@ from .const import (
CONF_NIGHTLIGHT_SWITCH_TYPE,
CONF_SAVE_ON_CHANGE,
CONF_TRANSITION,
DATA_CUSTOM_EFFECTS,
DATA_CUSTOM_EFFECTS_KEY,
DEFAULT_MODE_MUSIC,
DEFAULT_NAME,
DEFAULT_NIGHTLIGHT_SWITCH,
@@ -116,10 +116,7 @@ CONFIG_SCHEMA = vol.Schema(
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Yeelight bulbs."""
conf = config.get(DOMAIN, {})
# pylint: disable-next=hass-use-runtime-data
hass.data[DOMAIN] = {
DATA_CUSTOM_EFFECTS: conf.get(CONF_CUSTOM_EFFECTS, {}),
}
hass.data[DATA_CUSTOM_EFFECTS_KEY] = conf.get(CONF_CUSTOM_EFFECTS, [])
# Make sure the scanner is always started in case we are
# going to retry via ConfigEntryNotReady and the bulb has changed
# ip
+3 -2
View File
@@ -1,10 +1,13 @@
"""Support for Xiaomi Yeelight WiFi color bulb."""
from datetime import timedelta
from typing import Any
from homeassistant.const import Platform
from homeassistant.util.hass_dict import HassKey
DOMAIN = "yeelight"
DATA_CUSTOM_EFFECTS_KEY: HassKey[list[dict[str, Any]]] = HassKey(DOMAIN)
STATE_CHANGE_TIME = 0.40 # seconds
@@ -43,8 +46,6 @@ CONF_CUSTOM_EFFECTS = "custom_effects"
CONF_NIGHTLIGHT_SWITCH_TYPE = "nightlight_switch_type"
CONF_NIGHTLIGHT_SWITCH = "nightlight_switch"
DATA_CUSTOM_EFFECTS = "custom_effects"
ATTR_COUNT = "count"
ATTR_ACTION = "action"
ATTR_TRANSITIONS = "transitions"
+5 -5
View File
@@ -51,9 +51,8 @@ from .const import (
CONF_NIGHTLIGHT_SWITCH,
CONF_SAVE_ON_CHANGE,
CONF_TRANSITION,
DATA_CUSTOM_EFFECTS,
DATA_CUSTOM_EFFECTS_KEY,
DATA_UPDATED,
DOMAIN,
MODELS_WITH_DELAYED_ON_TRANSITION,
POWER_STATE_CHANGE_TIME,
)
@@ -218,7 +217,9 @@ def _transitions_config_parser(transitions):
@callback
def _parse_custom_effects(effects_config) -> dict[str, dict[str, Any]]:
def _parse_custom_effects(
effects_config: list[dict[str, Any]],
) -> dict[str, dict[str, Any]]:
effects = {}
for config in effects_config:
params = config[CONF_FLOW_PARAMS]
@@ -280,8 +281,7 @@ async def async_setup_entry(
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up Yeelight from a config entry."""
# pylint: disable-next=hass-use-runtime-data
custom_effects = _parse_custom_effects(hass.data[DOMAIN][DATA_CUSTOM_EFFECTS])
custom_effects = _parse_custom_effects(hass.data[DATA_CUSTOM_EFFECTS_KEY])
device = config_entry.runtime_data
_LOGGER.debug("Adding %s", device.name)