diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 1a848232128..60ea34cc754 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -5,8 +5,6 @@ from __future__ import annotations from collections.abc import Iterable import csv import dataclasses -from datetime import timedelta -from enum import IntFlag, StrEnum from functools import partial import logging import os @@ -37,24 +35,22 @@ from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.typing import ConfigType, VolDictType from homeassistant.loader import bind_hass import homeassistant.util.color as color_util -from homeassistant.util.hass_dict import HassKey -DOMAIN = "light" -DATA_COMPONENT: HassKey[EntityComponent[LightEntity]] = HassKey(DOMAIN) +from .const import ( # noqa: F401 + COLOR_MODES_BRIGHTNESS, + COLOR_MODES_COLOR, + DATA_COMPONENT, + DATA_PROFILES, + DOMAIN, + SCAN_INTERVAL, + VALID_COLOR_MODES, + ColorMode, + LightEntityFeature, +) + ENTITY_ID_FORMAT = DOMAIN + ".{}" PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE -SCAN_INTERVAL = timedelta(seconds=30) - -DATA_PROFILES: HassKey[Profiles] = HassKey(f"{DOMAIN}_profiles") - - -class LightEntityFeature(IntFlag): - """Supported features of the light entity.""" - - EFFECT = 4 - FLASH = 8 - TRANSITION = 32 # These SUPPORT_* constants are deprecated as of Home Assistant 2022.5. @@ -83,26 +79,6 @@ ATTR_COLOR_MODE = "color_mode" # List of color modes supported by the light ATTR_SUPPORTED_COLOR_MODES = "supported_color_modes" - -class ColorMode(StrEnum): - """Possible light color modes.""" - - UNKNOWN = "unknown" - """Ambiguous color mode""" - ONOFF = "onoff" - """Must be the only supported mode""" - BRIGHTNESS = "brightness" - """Must be the only supported mode""" - COLOR_TEMP = "color_temp" - HS = "hs" - XY = "xy" - RGB = "rgb" - RGBW = "rgbw" - RGBWW = "rgbww" - WHITE = "white" - """Must *NOT* be the only supported mode""" - - # These COLOR_MODE_* constants are deprecated as of Home Assistant 2022.5. # Please use the LightEntityFeature enum instead. _DEPRECATED_COLOR_MODE_UNKNOWN: Final = DeprecatedConstantEnum( @@ -122,25 +98,6 @@ _DEPRECATED_COLOR_MODE_RGBW: Final = DeprecatedConstantEnum(ColorMode.RGBW, "202 _DEPRECATED_COLOR_MODE_RGBWW: Final = DeprecatedConstantEnum(ColorMode.RGBWW, "2026.1") _DEPRECATED_COLOR_MODE_WHITE: Final = DeprecatedConstantEnum(ColorMode.WHITE, "2026.1") -VALID_COLOR_MODES = { - ColorMode.ONOFF, - ColorMode.BRIGHTNESS, - ColorMode.COLOR_TEMP, - ColorMode.HS, - ColorMode.XY, - ColorMode.RGB, - ColorMode.RGBW, - ColorMode.RGBWW, - ColorMode.WHITE, -} -COLOR_MODES_BRIGHTNESS = VALID_COLOR_MODES - {ColorMode.ONOFF} -COLOR_MODES_COLOR = { - ColorMode.HS, - ColorMode.RGB, - ColorMode.RGBW, - ColorMode.RGBWW, - ColorMode.XY, -} # mypy: disallow-any-generics diff --git a/homeassistant/components/light/const.py b/homeassistant/components/light/const.py new file mode 100644 index 00000000000..19b8734038e --- /dev/null +++ b/homeassistant/components/light/const.py @@ -0,0 +1,68 @@ +"""Provides constants for lights.""" + +from __future__ import annotations + +from datetime import timedelta +from enum import IntFlag, StrEnum +from typing import TYPE_CHECKING + +from homeassistant.util.hass_dict import HassKey + +if TYPE_CHECKING: + from homeassistant.helpers.entity_component import EntityComponent + + from . import LightEntity, Profiles + +DOMAIN = "light" +DATA_COMPONENT: HassKey[EntityComponent[LightEntity]] = HassKey(DOMAIN) +SCAN_INTERVAL = timedelta(seconds=30) + +DATA_PROFILES: HassKey[Profiles] = HassKey(f"{DOMAIN}_profiles") + + +class LightEntityFeature(IntFlag): + """Supported features of the light entity.""" + + EFFECT = 4 + FLASH = 8 + TRANSITION = 32 + + +class ColorMode(StrEnum): + """Possible light color modes.""" + + UNKNOWN = "unknown" + """Ambiguous color mode""" + ONOFF = "onoff" + """Must be the only supported mode""" + BRIGHTNESS = "brightness" + """Must be the only supported mode""" + COLOR_TEMP = "color_temp" + HS = "hs" + XY = "xy" + RGB = "rgb" + RGBW = "rgbw" + RGBWW = "rgbww" + WHITE = "white" + """Must *NOT* be the only supported mode""" + + +VALID_COLOR_MODES = { + ColorMode.ONOFF, + ColorMode.BRIGHTNESS, + ColorMode.COLOR_TEMP, + ColorMode.HS, + ColorMode.XY, + ColorMode.RGB, + ColorMode.RGBW, + ColorMode.RGBWW, + ColorMode.WHITE, +} +COLOR_MODES_BRIGHTNESS = VALID_COLOR_MODES - {ColorMode.ONOFF} +COLOR_MODES_COLOR = { + ColorMode.HS, + ColorMode.RGB, + ColorMode.RGBW, + ColorMode.RGBWW, + ColorMode.XY, +} diff --git a/homeassistant/components/light/device_action.py b/homeassistant/components/light/device_action.py index 45e9731c5b8..56bf7485e68 100644 --- a/homeassistant/components/light/device_action.py +++ b/homeassistant/components/light/device_action.py @@ -27,14 +27,13 @@ from . import ( ATTR_BRIGHTNESS_PCT, ATTR_BRIGHTNESS_STEP_PCT, ATTR_FLASH, - DOMAIN, FLASH_SHORT, VALID_BRIGHTNESS_PCT, VALID_FLASH, - LightEntityFeature, brightness_supported, get_supported_color_modes, ) +from .const import DOMAIN, LightEntityFeature # mypy: disallow-any-generics diff --git a/homeassistant/components/light/device_condition.py b/homeassistant/components/light/device_condition.py index f9bb7c30bd7..6dc702f8551 100644 --- a/homeassistant/components/light/device_condition.py +++ b/homeassistant/components/light/device_condition.py @@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.condition import ConditionCheckerType from homeassistant.helpers.typing import ConfigType -from . import DOMAIN +from .const import DOMAIN # mypy: disallow-any-generics diff --git a/homeassistant/components/light/device_trigger.py b/homeassistant/components/light/device_trigger.py index 033ea75357e..1f6bfdbe6e9 100644 --- a/homeassistant/components/light/device_trigger.py +++ b/homeassistant/components/light/device_trigger.py @@ -10,7 +10,7 @@ from homeassistant.core import CALLBACK_TYPE, HomeAssistant from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo from homeassistant.helpers.typing import ConfigType -from . import DOMAIN +from .const import DOMAIN TRIGGER_SCHEMA = vol.All( toggle_entity.TRIGGER_SCHEMA, diff --git a/homeassistant/components/light/intent.py b/homeassistant/components/light/intent.py index 458dbbde770..e496255029a 100644 --- a/homeassistant/components/light/intent.py +++ b/homeassistant/components/light/intent.py @@ -11,7 +11,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv, intent import homeassistant.util.color as color_util -from . import ATTR_BRIGHTNESS_PCT, ATTR_COLOR_TEMP_KELVIN, ATTR_RGB_COLOR, DOMAIN +from . import ATTR_BRIGHTNESS_PCT, ATTR_COLOR_TEMP_KELVIN, ATTR_RGB_COLOR +from .const import DOMAIN _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/light/reproduce_state.py b/homeassistant/components/light/reproduce_state.py index 4024f2f84ba..c933b517ccc 100644 --- a/homeassistant/components/light/reproduce_state.py +++ b/homeassistant/components/light/reproduce_state.py @@ -28,9 +28,8 @@ from . import ( ATTR_TRANSITION, ATTR_WHITE, ATTR_XY_COLOR, - DOMAIN, - ColorMode, ) +from .const import DOMAIN, ColorMode _LOGGER = logging.getLogger(__name__)