From 09ded3eded89bdfd9a5055c812a3451d6ce68cdc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 27 Nov 2026 09:09:28 +0100 Subject: [PATCH] Use the action field enums in wilight (#194932) --- homeassistant/components/wilight/cover.py | 4 +-- homeassistant/components/wilight/light.py | 42 ++++++++++++++--------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/wilight/cover.py b/homeassistant/components/wilight/cover.py index 18927f4a484d..e633e9f286ad 100644 --- a/homeassistant/components/wilight/cover.py +++ b/homeassistant/components/wilight/cover.py @@ -13,7 +13,7 @@ from pywilight.const import ( WL_STOPPED, ) -from homeassistant.components.cover import ATTR_POSITION, CoverEntity +from homeassistant.components.cover import CoverEntity, CoverServiceArgument from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -110,7 +110,7 @@ class WiLightCover(WiLightDevice, CoverEntity): @override async def async_set_cover_position(self, **kwargs: Any) -> None: """Move the cover to a specific position.""" - position = hass_to_wilight_position(kwargs[ATTR_POSITION]) + position = hass_to_wilight_position(kwargs[CoverServiceArgument.POSITION]) await self._client.set_cover_position(self._index, position) @override diff --git a/homeassistant/components/wilight/light.py b/homeassistant/components/wilight/light.py index 58b221a2310d..702631941cba 100644 --- a/homeassistant/components/wilight/light.py +++ b/homeassistant/components/wilight/light.py @@ -5,12 +5,7 @@ from typing import Any, override from pywilight.const import ITEM_LIGHT, LIGHT_COLOR, LIGHT_DIMMER, LIGHT_ON_OFF from pywilight.wilight_device import PyWiLightDevice -from homeassistant.components.light import ( - ATTR_BRIGHTNESS, - ATTR_HS_COLOR, - ColorMode, - LightEntity, -) +from homeassistant.components.light import ColorMode, LightEntity, LightServiceArgument from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -98,8 +93,8 @@ class WiLightLightDimmer(WiLightDevice, LightEntity): """Turn the device on,set brightness if needed.""" # Dimmer switches use a range of [0, 255] to control # brightness. Level 255 might mean to set it to previous value - if ATTR_BRIGHTNESS in kwargs: - brightness = kwargs[ATTR_BRIGHTNESS] + if LightServiceArgument.BRIGHTNESS in kwargs: + brightness = kwargs[LightServiceArgument.BRIGHTNESS] await self._client.set_brightness(self._index, brightness) else: await self._client.turn_on(self._index) @@ -164,17 +159,30 @@ class WiLightLightColor(WiLightDevice, LightEntity): # Brightness use a range of [0, 255] to control # Hue use a range of [0, 360] to control # Saturation use a range of [0, 100] to control - if ATTR_BRIGHTNESS in kwargs and ATTR_HS_COLOR in kwargs: - brightness = kwargs[ATTR_BRIGHTNESS] - hue = hass_to_wilight_hue(kwargs[ATTR_HS_COLOR][0]) - saturation = hass_to_wilight_saturation(kwargs[ATTR_HS_COLOR][1]) + if ( + LightServiceArgument.BRIGHTNESS in kwargs + and LightServiceArgument.HS_COLOR in kwargs + ): + brightness = kwargs[LightServiceArgument.BRIGHTNESS] + hue = hass_to_wilight_hue(kwargs[LightServiceArgument.HS_COLOR][0]) + saturation = hass_to_wilight_saturation( + kwargs[LightServiceArgument.HS_COLOR][1] + ) await self._client.set_hsb_color(self._index, hue, saturation, brightness) - elif ATTR_BRIGHTNESS in kwargs and ATTR_HS_COLOR not in kwargs: - brightness = kwargs[ATTR_BRIGHTNESS] + elif ( + LightServiceArgument.BRIGHTNESS in kwargs + and LightServiceArgument.HS_COLOR not in kwargs + ): + brightness = kwargs[LightServiceArgument.BRIGHTNESS] await self._client.set_brightness(self._index, brightness) - elif ATTR_BRIGHTNESS not in kwargs and ATTR_HS_COLOR in kwargs: - hue = hass_to_wilight_hue(kwargs[ATTR_HS_COLOR][0]) - saturation = hass_to_wilight_saturation(kwargs[ATTR_HS_COLOR][1]) + elif ( + LightServiceArgument.BRIGHTNESS not in kwargs + and LightServiceArgument.HS_COLOR in kwargs + ): + hue = hass_to_wilight_hue(kwargs[LightServiceArgument.HS_COLOR][0]) + saturation = hass_to_wilight_saturation( + kwargs[LightServiceArgument.HS_COLOR][1] + ) await self._client.set_hs_color(self._index, hue, saturation) else: await self._client.turn_on(self._index)