Skip to content

Commit 66d7afa

Browse files
epenetclaude
andauthored
Migrate flux_led to use HassKey for FLUX_LED_DISCOVERY (home-assistant#168872)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 51fcdaf commit 66d7afa

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

homeassistant/components/flux_led/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def async_wifi_bulb_for_host(
8787

8888
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
8989
"""Set up the flux_led component."""
90-
domain_data = hass.data.setdefault(DOMAIN, {})
91-
domain_data[FLUX_LED_DISCOVERY] = []
90+
hass.data[FLUX_LED_DISCOVERY] = []
9291

9392
@callback
9493
def _async_start_background_discovery(*_: Any) -> None:

homeassistant/components/flux_led/const.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
COLOR_MODE_RGBW as FLUX_COLOR_MODE_RGBW,
1010
COLOR_MODE_RGBWW as FLUX_COLOR_MODE_RGBWW,
1111
)
12+
from flux_led.scanner import FluxLEDDiscovery
1213

1314
from homeassistant.components.light import ColorMode
15+
from homeassistant.util.hass_dict import HassKey
1416

1517
DOMAIN: Final = "flux_led"
1618

@@ -34,7 +36,7 @@
3436
DEFAULT_SCAN_INTERVAL: Final = 5
3537
DEFAULT_EFFECT_SPEED: Final = 50
3638

37-
FLUX_LED_DISCOVERY: Final = "flux_led_discovery"
39+
FLUX_LED_DISCOVERY: HassKey[list[FluxLEDDiscovery]] = HassKey(DOMAIN)
3840

3941
FLUX_LED_EXCEPTIONS: Final = (
4042
TimeoutError,

homeassistant/components/flux_led/discovery.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""The Flux LED/MagicLight integration discovery."""
2-
# pylint: disable=hass-use-runtime-data # Uses legacy hass.data[DOMAIN] pattern
32

43
from __future__ import annotations
54

@@ -154,8 +153,7 @@ def async_update_entry_from_discovery(
154153
@callback
155154
def async_get_discovery(hass: HomeAssistant, host: str) -> FluxLEDDiscovery | None:
156155
"""Check if a device was already discovered via a broadcast discovery."""
157-
discoveries: list[FluxLEDDiscovery] = hass.data[DOMAIN][FLUX_LED_DISCOVERY]
158-
for discovery in discoveries:
156+
for discovery in hass.data[FLUX_LED_DISCOVERY]:
159157
if discovery[ATTR_IPADDR] == host:
160158
return discovery
161159
return None
@@ -164,10 +162,10 @@ def async_get_discovery(hass: HomeAssistant, host: str) -> FluxLEDDiscovery | No
164162
@callback
165163
def async_clear_discovery_cache(hass: HomeAssistant, host: str) -> None:
166164
"""Clear the host from the discovery cache."""
167-
domain_data = hass.data[DOMAIN]
168-
discoveries: list[FluxLEDDiscovery] = domain_data[FLUX_LED_DISCOVERY]
169-
domain_data[FLUX_LED_DISCOVERY] = [
170-
discovery for discovery in discoveries if discovery[ATTR_IPADDR] != host
165+
hass.data[FLUX_LED_DISCOVERY] = [
166+
discovery
167+
for discovery in hass.data[FLUX_LED_DISCOVERY]
168+
if discovery[ATTR_IPADDR] != host
171169
]
172170

173171

0 commit comments

Comments
 (0)