Use the action field enums in openrgb (#196054)

This commit is contained in:
epenet
2026-12-02 09:50:41 -05:00
committed by GitHub
parent a2c0aeebdc
commit f13114a25d
+9 -10
View File
@@ -7,13 +7,11 @@ from openrgb.orgb import Device
from openrgb.utils import ModeColors, ModeData, RGBColor
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_EFFECT,
ATTR_RGB_COLOR,
EFFECT_OFF,
ColorMode,
LightEntity,
LightEntityFeature,
LightServiceArgument,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
@@ -319,8 +317,8 @@ class OpenRGBLight(CoordinatorEntity[OpenRGBCoordinator], LightEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""
mode = None
if ATTR_EFFECT in kwargs:
effect = kwargs[ATTR_EFFECT]
if LightServiceArgument.EFFECT in kwargs:
effect = kwargs[LightServiceArgument.EFFECT]
if self._attr_effect_list is None or effect not in self._attr_effect_list:
raise ServiceValidationError(
translation_domain=DOMAIN,
@@ -348,7 +346,8 @@ class OpenRGBLight(CoordinatorEntity[OpenRGBCoordinator], LightEntity):
mode_supports_color = mode in self._supports_color_modes
color_or_brightness_requested = (
ATTR_RGB_COLOR in kwargs or ATTR_BRIGHTNESS in kwargs
LightServiceArgument.RGB_COLOR in kwargs
or LightServiceArgument.BRIGHTNESS in kwargs
)
if color_or_brightness_requested and not mode_supports_color:
raise ServiceValidationError(
@@ -378,8 +377,8 @@ class OpenRGBLight(CoordinatorEntity[OpenRGBCoordinator], LightEntity):
if need_to_apply_color:
brightness = None
if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS]
if LightServiceArgument.BRIGHTNESS in kwargs:
brightness = kwargs[LightServiceArgument.BRIGHTNESS]
elif self._attr_brightness is None:
# Restore previous brightness when turning on
brightness = self._previous_brightness
@@ -388,8 +387,8 @@ class OpenRGBLight(CoordinatorEntity[OpenRGBCoordinator], LightEntity):
brightness = self._attr_brightness or DEFAULT_BRIGHTNESS
color = None
if ATTR_RGB_COLOR in kwargs:
color = kwargs[ATTR_RGB_COLOR]
if LightServiceArgument.RGB_COLOR in kwargs:
color = kwargs[LightServiceArgument.RGB_COLOR]
elif self._attr_rgb_color is None:
# Restore previous color when turning on
color = self._previous_rgb_color