diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 29955d0a..037bd083 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -16,7 +16,6 @@ import voluptuous as vol from homeassistant.components.light import ( ATTR_BRIGHTNESS, - ATTR_COLOR_TEMP, ATTR_COLOR_TEMP_KELVIN, ATTR_EFFECT, ATTR_FLASH, @@ -24,17 +23,8 @@ ATTR_SUPPORTED_COLOR_MODES, ATTR_TRANSITION, ATTR_XY_COLOR, - COLOR_MODE_BRIGHTNESS, - COLOR_MODE_COLOR_TEMP, - COLOR_MODE_HS, - COLOR_MODE_RGB, - COLOR_MODE_RGBW, - COLOR_MODE_RGBWW, - COLOR_MODE_XY, - SUPPORT_BRIGHTNESS, - SUPPORT_COLOR, - SUPPORT_COLOR_TEMP, - SUPPORT_TRANSITION, + ColorMode, + LightEntityFeature, is_on, preprocess_turn_on_alternatives, ) @@ -179,13 +169,6 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.helpers.entity_platform import AddEntitiesCallback -_SUPPORT_OPTS = { - "brightness": SUPPORT_BRIGHTNESS, - "color_temp": SUPPORT_COLOR_TEMP, - "color": SUPPORT_COLOR, - "transition": SUPPORT_TRANSITION, -} - _LOGGER = logging.getLogger(__name__) @@ -651,17 +634,19 @@ def _supported_features(hass: HomeAssistant, light: str) -> set[str]: assert state is not None supported_features = state.attributes.get(ATTR_SUPPORTED_FEATURES, 0) assert isinstance(supported_features, int) - supported = { - key for key, value in _SUPPORT_OPTS.items() if supported_features & value - } + + supported = set() + + if supported_features & LightEntityFeature.TRANSITION: + supported.add("transition") supported_color_modes = state.attributes.get(ATTR_SUPPORTED_COLOR_MODES, set()) color_modes = { - COLOR_MODE_RGB, - COLOR_MODE_RGBW, - COLOR_MODE_RGBWW, - COLOR_MODE_XY, - COLOR_MODE_HS, + ColorMode.RGB, + ColorMode.RGBW, + ColorMode.RGBWW, + ColorMode.XY, + ColorMode.HS, } # Adding brightness when color mode is supported, see @@ -672,10 +657,10 @@ def _supported_features(hass: HomeAssistant, light: str) -> set[str]: supported.update({"color", "brightness"}) break - if COLOR_MODE_COLOR_TEMP in supported_color_modes: + if ColorMode.COLOR_TEMP in supported_color_modes: supported.update({"color_temp", "brightness"}) - if COLOR_MODE_BRIGHTNESS in supported_color_modes: + if ColorMode.BRIGHTNESS in supported_color_modes: supported.add("brightness") return supported @@ -2009,12 +1994,6 @@ def modify_service_data(service_data, entity_ids): context.id, ) service_data = {ATTR_ENTITY_ID: skipped, **service_data_copy[CONF_PARAMS]} - if ( - ATTR_COLOR_TEMP in service_data - and ATTR_COLOR_TEMP_KELVIN in service_data - ): - # ATTR_COLOR_TEMP and ATTR_COLOR_TEMP_KELVIN are mutually exclusive - del service_data[ATTR_COLOR_TEMP] await self.hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_ON,