Skip to content

Commit d0545ff

Browse files
committed
fixup! Make main light the primary entity when keep_main_light is enabled in WLED
1 parent d32107b commit d0545ff

17 files changed

Lines changed: 776 additions & 508 deletions

homeassistant/components/wled/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from homeassistant.helpers.typing import ConfigType
1212
from homeassistant.util.hass_dict import HassKey
1313

14-
from .const import DOMAIN
14+
from .const import CONF_KEEP_MAIN_LIGHT, DOMAIN
1515
from .coordinator import (
1616
WLEDConfigEntry,
1717
WLEDDataUpdateCoordinator,
@@ -127,6 +127,14 @@ async def async_migrate_entry(
127127
version=1,
128128
minor_version=2,
129129
)
130+
if config_entry.minor_version < 3:
131+
# 1.3: Keep existing behavior for users upgrading — new installs default to True.
132+
hass.config_entries.async_update_entry(
133+
config_entry,
134+
options={CONF_KEEP_MAIN_LIGHT: False} | config_entry.options,
135+
version=1,
136+
minor_version=3,
137+
)
130138

131139
_LOGGER.debug(
132140
"Migration to configuration version %s.%s successful",

homeassistant/components/wled/config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class WLEDFlowHandler(ConfigFlow, domain=DOMAIN):
3636
"""Handle a WLED config flow."""
3737

3838
VERSION = 1
39-
MINOR_VERSION = 2
39+
MINOR_VERSION = 3
4040
discovered_host: str
4141
discovered_device: Device
4242

homeassistant/components/wled/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Options
1818
CONF_KEEP_MAIN_LIGHT = "keep_master_light"
19-
DEFAULT_KEEP_MAIN_LIGHT = False
19+
DEFAULT_KEEP_MAIN_LIGHT = True
2020

2121
# Attributes
2222
ATTR_CCT = "cct"

homeassistant/components/wled/light.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def __init__(
124124
super().__init__(coordinator=coordinator)
125125
self._segment = segment
126126

127-
# Segment 0 uses a simpler name, which is more natural for when using
128-
# a single segment / using WLED with one big LED strip.
127+
# With keep_main_light disabled, a single-segment setup uses segment 0
128+
# as the primary entity — it drops the "Segment N" qualifier.
129129
if segment == 0 and not coordinator.keep_main_light:
130130
self._attr_name = None
131131
else:

homeassistant/components/wled/number.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ def __init__(
8484
super().__init__(coordinator=coordinator)
8585
self.entity_description = description
8686

87-
# Segment 0 uses a simpler name, which is more natural for when using
88-
# a single segment / using WLED with one big LED strip.
89-
if segment != 0 or coordinator.keep_main_light:
87+
# With keep_main_light disabled, a single-segment setup uses segment 0
88+
# as the primary entity — it drops the "Segment N" qualifier.
89+
if segment == 0 and not coordinator.keep_main_light:
90+
self._attr_translation_key = description.translation_key
91+
else:
9092
self._attr_translation_key = description.segment_translation_key
9193
self._attr_translation_placeholders = {"segment": str(segment)}
9294

homeassistant/components/wled/select.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ def __init__(self, coordinator: WLEDDataUpdateCoordinator, segment: int) -> None
159159
"""Initialize WLED ."""
160160
super().__init__(coordinator=coordinator)
161161

162-
# Segment 0 uses a simpler name, which is more natural for when using
163-
# a single segment / using WLED with one big LED strip.
162+
# With keep_main_light disabled, a single-segment setup uses segment 0
163+
# as the primary entity — it drops the "Segment N" qualifier.
164164
if segment != 0 or coordinator.keep_main_light:
165165
self._attr_translation_key = "segment_color_palette"
166166
self._attr_translation_placeholders = {"segment": str(segment)}

homeassistant/components/wled/switch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ def __init__(
194194
self.entity_description = description
195195
self._segment = segment
196196

197-
# Segment 0 uses a simpler name, which is more natural for when using
198-
# a single segment / using WLED with one big LED strip.
199-
if segment != 0 or coordinator.keep_main_light:
197+
# With keep_main_light disabled, a single-segment setup uses segment 0
198+
# as the primary entity — it drops the "Segment N" qualifier.
199+
if segment == 0 and not coordinator.keep_main_light:
200+
self._attr_translation_key = description.translation_key
201+
else:
200202
self._attr_translation_key = description.segment_translation_key
201203
self._attr_translation_placeholders = {"segment": str(segment)}
202-
else:
203-
self._attr_translation_key = description.translation_key
204204

205205
self._attr_unique_id = (
206206
f"{coordinator.data.info.mac_address}_{description.key}_{segment}"

tests/components/wled/conftest.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
from wled import Device as WLEDDevice, Releases
99

10+
from homeassistant.components.wled.config_flow import CONF_KEEP_MAIN_LIGHT
1011
from homeassistant.components.wled.const import DOMAIN
1112
from homeassistant.const import CONF_HOST
1213
from homeassistant.core import HomeAssistant
@@ -22,7 +23,7 @@ def mock_config_entry() -> MockConfigEntry:
2223
domain=DOMAIN,
2324
data={CONF_HOST: "192.168.1.123"},
2425
unique_id="aabbccddeeff",
25-
minor_version=2,
26+
minor_version=3,
2627
)
2728

2829

@@ -89,12 +90,19 @@ def mock_wled(
8990
yield wled
9091

9192

93+
@pytest.fixture
94+
def opt_keep_main_light() -> bool | None:
95+
"""Return the conf_keep_main_light option."""
96+
return None
97+
98+
9299
@pytest.fixture
93100
async def init_integration(
94101
hass: HomeAssistant,
95102
freezer: FrozenDateTimeFactory,
96103
mock_config_entry: MockConfigEntry,
97104
mock_wled: MagicMock,
105+
opt_keep_main_light: bool | None,
98106
) -> MockConfigEntry:
99107
"""Set up the WLED integration for testing."""
100108
mock_config_entry.add_to_hass(hass)
@@ -106,4 +114,11 @@ async def init_integration(
106114
# time by SCAN_INTERVAL
107115
freezer.tick(1)
108116

117+
if opt_keep_main_light is not None:
118+
hass.config_entries.async_update_entry(
119+
mock_config_entry, options={CONF_KEEP_MAIN_LIGHT: opt_keep_main_light}
120+
)
121+
await hass.config_entries.async_reload(mock_config_entry.entry_id)
122+
await hass.async_block_till_done()
123+
109124
return mock_config_entry

0 commit comments

Comments
 (0)