From 9ac5bdc83261b026358bdf0be27f444ef59d4b35 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 6 Oct 2023 20:04:44 +0200 Subject: [PATCH] Use modern naming for WLED (#100233) --- homeassistant/components/wled/config_flow.py | 6 +-- homeassistant/components/wled/const.py | 4 +- homeassistant/components/wled/coordinator.py | 16 +++---- homeassistant/components/wled/light.py | 46 ++++++++++---------- homeassistant/components/wled/strings.json | 2 +- tests/components/wled/test_config_flow.py | 6 +-- tests/components/wled/test_light.py | 4 +- 7 files changed, 42 insertions(+), 42 deletions(-) diff --git a/homeassistant/components/wled/config_flow.py b/homeassistant/components/wled/config_flow.py index 1dda368a2b0..cbb78545e2b 100644 --- a/homeassistant/components/wled/config_flow.py +++ b/homeassistant/components/wled/config_flow.py @@ -13,7 +13,7 @@ from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession -from .const import CONF_KEEP_MASTER_LIGHT, DEFAULT_KEEP_MASTER_LIGHT, DOMAIN +from .const import CONF_KEEP_MAIN_LIGHT, DEFAULT_KEEP_MAIN_LIGHT, DOMAIN class WLEDFlowHandler(ConfigFlow, domain=DOMAIN): @@ -136,9 +136,9 @@ class WLEDOptionsFlowHandler(OptionsFlow): data_schema=vol.Schema( { vol.Optional( - CONF_KEEP_MASTER_LIGHT, + CONF_KEEP_MAIN_LIGHT, default=self.config_entry.options.get( - CONF_KEEP_MASTER_LIGHT, DEFAULT_KEEP_MASTER_LIGHT + CONF_KEEP_MAIN_LIGHT, DEFAULT_KEEP_MAIN_LIGHT ), ): bool, } diff --git a/homeassistant/components/wled/const.py b/homeassistant/components/wled/const.py index 40f831772bc..cee9984a3f6 100644 --- a/homeassistant/components/wled/const.py +++ b/homeassistant/components/wled/const.py @@ -9,8 +9,8 @@ LOGGER = logging.getLogger(__package__) SCAN_INTERVAL = timedelta(seconds=10) # Options -CONF_KEEP_MASTER_LIGHT = "keep_master_light" -DEFAULT_KEEP_MASTER_LIGHT = False +CONF_KEEP_MAIN_LIGHT = "keep_master_light" +DEFAULT_KEEP_MAIN_LIGHT = False # Attributes ATTR_COLOR_PRIMARY = "color_primary" diff --git a/homeassistant/components/wled/coordinator.py b/homeassistant/components/wled/coordinator.py index 6f3bae03bfa..6bbcb1747f0 100644 --- a/homeassistant/components/wled/coordinator.py +++ b/homeassistant/components/wled/coordinator.py @@ -10,8 +10,8 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import ( - CONF_KEEP_MASTER_LIGHT, - DEFAULT_KEEP_MASTER_LIGHT, + CONF_KEEP_MAIN_LIGHT, + DEFAULT_KEEP_MAIN_LIGHT, DOMAIN, LOGGER, SCAN_INTERVAL, @@ -21,7 +21,7 @@ from .const import ( class WLEDDataUpdateCoordinator(DataUpdateCoordinator[WLEDDevice]): """Class to manage fetching WLED data from single endpoint.""" - keep_master_light: bool + keep_main_light: bool config_entry: ConfigEntry def __init__( @@ -31,8 +31,8 @@ class WLEDDataUpdateCoordinator(DataUpdateCoordinator[WLEDDevice]): entry: ConfigEntry, ) -> None: """Initialize global WLED data updater.""" - self.keep_master_light = entry.options.get( - CONF_KEEP_MASTER_LIGHT, DEFAULT_KEEP_MASTER_LIGHT + self.keep_main_light = entry.options.get( + CONF_KEEP_MAIN_LIGHT, DEFAULT_KEEP_MAIN_LIGHT ) self.wled = WLED(entry.data[CONF_HOST], session=async_get_clientsession(hass)) self.unsub: CALLBACK_TYPE | None = None @@ -45,9 +45,9 @@ class WLEDDataUpdateCoordinator(DataUpdateCoordinator[WLEDDevice]): ) @property - def has_master_light(self) -> bool: - """Return if the coordinated device has a master light.""" - return self.keep_master_light or ( + def has_main_light(self) -> bool: + """Return if the coordinated device has a main light.""" + return self.keep_main_light or ( self.data is not None and len(self.data.state.segments) > 1 ) diff --git a/homeassistant/components/wled/light.py b/homeassistant/components/wled/light.py index 6675118e565..b793654c886 100644 --- a/homeassistant/components/wled/light.py +++ b/homeassistant/components/wled/light.py @@ -33,8 +33,8 @@ async def async_setup_entry( ) -> None: """Set up WLED light based on a config entry.""" coordinator: WLEDDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - if coordinator.keep_master_light: - async_add_entities([WLEDMasterLight(coordinator=coordinator)]) + if coordinator.keep_main_light: + async_add_entities([WLEDMainLight(coordinator=coordinator)]) update_segments = partial( async_update_segments, @@ -47,8 +47,8 @@ async def async_setup_entry( update_segments() -class WLEDMasterLight(WLEDEntity, LightEntity): - """Defines a WLED master light.""" +class WLEDMainLight(WLEDEntity, LightEntity): + """Defines a WLED main light.""" _attr_color_mode = ColorMode.BRIGHTNESS _attr_icon = "mdi:led-strip-variant" @@ -57,7 +57,7 @@ class WLEDMasterLight(WLEDEntity, LightEntity): _attr_supported_color_modes = {ColorMode.BRIGHTNESS} def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None: - """Initialize WLED master light.""" + """Initialize WLED main light.""" super().__init__(coordinator=coordinator) self._attr_unique_id = coordinator.data.info.mac_address @@ -73,8 +73,8 @@ class WLEDMasterLight(WLEDEntity, LightEntity): @property def available(self) -> bool: - """Return if this master light is available or not.""" - return self.coordinator.has_master_light and super().available + """Return if this main light is available or not.""" + return self.coordinator.has_main_light and super().available @wled_exception_handler async def async_turn_off(self, **kwargs: Any) -> None: @@ -167,8 +167,8 @@ class WLEDSegmentLight(WLEDEntity, LightEntity): state = self.coordinator.data.state # If this is the one and only segment, calculate brightness based - # on the master and segment brightness - if not self.coordinator.has_master_light: + # on the main and segment brightness + if not self.coordinator.has_main_light: return int( (state.segments[self._segment].brightness * state.brightness) / 255 ) @@ -185,9 +185,9 @@ class WLEDSegmentLight(WLEDEntity, LightEntity): """Return the state of the light.""" state = self.coordinator.data.state - # If there is no master, we take the master state into account + # If there is no main, we take the main state into account # on the segment level. - if not self.coordinator.has_master_light and not state.on: + if not self.coordinator.has_main_light and not state.on: return False return bool(state.segments[self._segment].on) @@ -200,8 +200,8 @@ class WLEDSegmentLight(WLEDEntity, LightEntity): # WLED uses 100ms per unit, so 10 = 1 second. transition = round(kwargs[ATTR_TRANSITION] * 10) - # If there is no master control, and only 1 segment, handle the master - if not self.coordinator.has_master_light: + # If there is no main control, and only 1 segment, handle the main + if not self.coordinator.has_main_light: await self.coordinator.wled.master(on=False, transition=transition) return @@ -233,19 +233,19 @@ class WLEDSegmentLight(WLEDEntity, LightEntity): if ATTR_EFFECT in kwargs: data[ATTR_EFFECT] = kwargs[ATTR_EFFECT] - # If there is no master control, and only 1 segment, handle the master - if not self.coordinator.has_master_light: - master_data = {ATTR_ON: True} + # If there is no main control, and only 1 segment, handle the main + if not self.coordinator.has_main_light: + main_data = {ATTR_ON: True} if ATTR_BRIGHTNESS in data: - master_data[ATTR_BRIGHTNESS] = data[ATTR_BRIGHTNESS] + main_data[ATTR_BRIGHTNESS] = data[ATTR_BRIGHTNESS] data[ATTR_BRIGHTNESS] = 255 if ATTR_TRANSITION in data: - master_data[ATTR_TRANSITION] = data[ATTR_TRANSITION] + main_data[ATTR_TRANSITION] = data[ATTR_TRANSITION] del data[ATTR_TRANSITION] await self.coordinator.wled.segment(**data) - await self.coordinator.wled.master(**master_data) + await self.coordinator.wled.master(**main_data) return await self.coordinator.wled.segment(**data) @@ -259,13 +259,13 @@ def async_update_segments( ) -> None: """Update segments.""" segment_ids = {light.segment_id for light in coordinator.data.state.segments} - new_entities: list[WLEDMasterLight | WLEDSegmentLight] = [] + new_entities: list[WLEDMainLight | WLEDSegmentLight] = [] - # More than 1 segment now? No master? Add master controls - if not coordinator.keep_master_light and ( + # More than 1 segment now? No main? Add main controls + if not coordinator.keep_main_light and ( len(current_ids) < 2 and len(segment_ids) > 1 ): - new_entities.append(WLEDMasterLight(coordinator)) + new_entities.append(WLEDMainLight(coordinator)) # Process new segments, add them to Home Assistant for segment_id in segment_ids - current_ids: diff --git a/homeassistant/components/wled/strings.json b/homeassistant/components/wled/strings.json index 5791732dfbe..61b9cc450fe 100644 --- a/homeassistant/components/wled/strings.json +++ b/homeassistant/components/wled/strings.json @@ -26,7 +26,7 @@ "step": { "init": { "data": { - "keep_master_light": "Keep master light, even with 1 LED segment." + "keep_master_light": "Keep main light, even with 1 LED segment." } } } diff --git a/tests/components/wled/test_config_flow.py b/tests/components/wled/test_config_flow.py index de01510adb3..949916aaccc 100644 --- a/tests/components/wled/test_config_flow.py +++ b/tests/components/wled/test_config_flow.py @@ -6,7 +6,7 @@ import pytest from wled import WLEDConnectionError from homeassistant.components import zeroconf -from homeassistant.components.wled.const import CONF_KEEP_MASTER_LIGHT, DOMAIN +from homeassistant.components.wled.const import CONF_KEEP_MAIN_LIGHT, DOMAIN from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME from homeassistant.core import HomeAssistant @@ -271,10 +271,10 @@ async def test_options_flow( result2 = await hass.config_entries.options.async_configure( result["flow_id"], - user_input={CONF_KEEP_MASTER_LIGHT: True}, + user_input={CONF_KEEP_MAIN_LIGHT: True}, ) assert result2.get("type") == FlowResultType.CREATE_ENTRY assert result2.get("data") == { - CONF_KEEP_MASTER_LIGHT: True, + CONF_KEEP_MAIN_LIGHT: True, } diff --git a/tests/components/wled/test_light.py b/tests/components/wled/test_light.py index ab8330293ba..2594c228eda 100644 --- a/tests/components/wled/test_light.py +++ b/tests/components/wled/test_light.py @@ -15,7 +15,7 @@ from homeassistant.components.light import ( ATTR_TRANSITION, DOMAIN as LIGHT_DOMAIN, ) -from homeassistant.components.wled.const import CONF_KEEP_MASTER_LIGHT, SCAN_INTERVAL +from homeassistant.components.wled.const import CONF_KEEP_MAIN_LIGHT, SCAN_INTERVAL from homeassistant.const import ( ATTR_ENTITY_ID, ATTR_ICON, @@ -355,7 +355,7 @@ async def test_single_segment_with_keep_main_light( assert not hass.states.get("light.wled_rgb_light_main") hass.config_entries.async_update_entry( - init_integration, options={CONF_KEEP_MASTER_LIGHT: True} + init_integration, options={CONF_KEEP_MAIN_LIGHT: True} ) await hass.async_block_till_done()