From c8b0a3b6672ab0267c4d3c563aea11690b0535be Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 2 Dec 2021 23:19:08 +0100 Subject: [PATCH] Revert "Move Platform StrEnum to const" (#60875) --- homeassistant/components/wled/__init__.py | 2 +- homeassistant/const.py | 38 ----------------------- homeassistant/helpers/entity_platform.py | 36 +++++++++++++++++++++ homeassistant/setup.py | 30 ++++++++++++++++-- homeassistant/util/dt.py | 4 ++- script/hassfest/dependencies.py | 7 +++-- 6 files changed, 73 insertions(+), 44 deletions(-) diff --git a/homeassistant/components/wled/__init__.py b/homeassistant/components/wled/__init__.py index 659df1baad9..0518bd736d0 100644 --- a/homeassistant/components/wled/__init__.py +++ b/homeassistant/components/wled/__init__.py @@ -2,8 +2,8 @@ from __future__ import annotations from homeassistant.config_entries import ConfigEntry -from homeassistant.const import Platform from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import Platform from .const import DOMAIN from .coordinator import WLEDDataUpdateCoordinator diff --git a/homeassistant/const.py b/homeassistant/const.py index 59532b84c54..fb8dfc6089a 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -3,8 +3,6 @@ from __future__ import annotations from typing import Final -from homeassistant.util.enum import StrEnum - MAJOR_VERSION: Final = 2021 MINOR_VERSION: Final = 12 PATCH_VERSION: Final = "0.dev0" @@ -18,42 +16,6 @@ REQUIRED_NEXT_PYTHON_HA_RELEASE: Final = "2022.1" # Format for platform files PLATFORM_FORMAT: Final = "{platform}.{domain}" - -class Platform(StrEnum): - """Available entity platforms.""" - - AIR_QUALITY = "air_quality" - ALARM_CONTROL_PANEL = "alarm_control_panel" - BINARY_SENSOR = "binary_sensor" - BUTTON = "button" - CALENDAR = "calendar" - CAMERA = "camera" - CLIMATE = "climate" - COVER = "cover" - DEVICE_TRACKER = "device_tracker" - FAN = "fan" - GEO_LOCATION = "geo_location" - HUMIDIFIER = "humidifier" - IMAGE_PROCESSING = "image_processing" - LIGHT = "light" - LOCK = "lock" - MAILBOX = "mailbox" - MEDIA_PLAYER = "media_player" - NOTIFY = "notify" - NUMBER = "number" - REMOTE = "remote" - SCENE = "scene" - SELECT = "select" - SENSOR = "sensor" - SIREN = "siren" - SST = "sst" - SWITCH = "switch" - TTS = "tts" - VACUUM = "vacuum" - WATER_HEATER = "water_heater" - WEATHER = "weather" - - # Can be used to specify a catch all when registering state or event listeners. MATCH_ALL: Final = "*" diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index d8cb8477f11..45795a44c42 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -34,6 +34,7 @@ from homeassistant.exceptions import ( ) from homeassistant.setup import async_start_setup from homeassistant.util.async_ import run_callback_threadsafe +from homeassistant.util.enum import StrEnum from . import ( config_validation as cv, @@ -62,6 +63,41 @@ PLATFORM_NOT_READY_BASE_WAIT_TIME = 30 # seconds _LOGGER = getLogger(__name__) +class Platform(StrEnum): + """Available platforms.""" + + AIR_QUALITY = "air_quality" + ALARM_CONTROL_PANEL = "alarm_control_panel" + BINARY_SENSOR = "binary_sensor" + BUTTON = "button" + CALENDAR = "calendar" + CAMERA = "camera" + CLIMATE = "climate" + COVER = "cover" + DEVICE_TRACKER = "device_tracker" + FAN = "fan" + GEO_LOCATION = "geo_location" + HUMIDIFIER = "humidifier" + IMAGE_PROCESSING = "image_processing" + LIGHT = "light" + LOCK = "lock" + MAILBOX = "mailbox" + MEDIA_PLAYER = "media_player" + NOTIFY = "notify" + NUMBER = "number" + REMOTE = "remote" + SCENE = "scene" + SELECT = "select" + SENSOR = "sensor" + SIREN = "siren" + SST = "sst" + SWITCH = "switch" + TTS = "tts" + VACUUM = "vacuum" + WATER_HEATER = "water_heater" + WEATHER = "weather" + + class AddEntitiesCallback(Protocol): """Protocol type for EntityPlatform.add_entities callback.""" diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 3e6db28a194..67740c54254 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -14,7 +14,6 @@ from homeassistant.const import ( EVENT_COMPONENT_LOADED, EVENT_HOMEASSISTANT_START, PLATFORM_FORMAT, - Platform, ) from homeassistant.core import CALLBACK_TYPE from homeassistant.exceptions import HomeAssistantError @@ -27,7 +26,34 @@ _LOGGER = logging.getLogger(__name__) ATTR_COMPONENT = "component" -BASE_PLATFORMS = {platform.value for platform in Platform} +BASE_PLATFORMS = { + "air_quality", + "alarm_control_panel", + "binary_sensor", + "camera", + "calendar", + "climate", + "cover", + "device_tracker", + "fan", + "humidifier", + "image_processing", + "light", + "lock", + "media_player", + "notify", + "number", + "remote", + "scene", + "select", + "sensor", + "siren", + "switch", + "tts", + "vacuum", + "water_heater", + "weather", +} DATA_SETUP_DONE = "setup_done" DATA_SETUP_STARTED = "setup_started" diff --git a/homeassistant/util/dt.py b/homeassistant/util/dt.py index 0c8a1cd9aad..39f8a63e53f 100644 --- a/homeassistant/util/dt.py +++ b/homeassistant/util/dt.py @@ -10,6 +10,8 @@ from typing import Any, cast import ciso8601 +from homeassistant.const import MATCH_ALL + if sys.version_info[:2] >= (3, 9): import zoneinfo else: @@ -213,7 +215,7 @@ def get_age(date: dt.datetime) -> str: def parse_time_expression(parameter: Any, min_value: int, max_value: int) -> list[int]: """Parse the time expression part and return a list of times to match.""" - if parameter is None or parameter == "*": + if parameter is None or parameter == MATCH_ALL: res = list(range(min_value, max_value + 1)) elif isinstance(parameter, str): if parameter.startswith("/"): diff --git a/script/hassfest/dependencies.py b/script/hassfest/dependencies.py index c52a926e4e1..3f0bd9c1236 100644 --- a/script/hassfest/dependencies.py +++ b/script/hassfest/dependencies.py @@ -4,8 +4,8 @@ from __future__ import annotations import ast from pathlib import Path -from homeassistant.const import Platform from homeassistant.requirements import DISCOVERY_INTEGRATIONS +from homeassistant.setup import BASE_PLATFORMS from .model import Integration @@ -91,11 +91,12 @@ class ImportCollector(ast.NodeVisitor): ALLOWED_USED_COMPONENTS = { - *{platform.value for platform in Platform}, # Internal integrations "alert", "automation", + "button", "conversation", + "button", "device_automation", "frontend", "group", @@ -118,6 +119,8 @@ ALLOWED_USED_COMPONENTS = { "webhook", "websocket_api", "zone", + # Entity integrations with platforms + *BASE_PLATFORMS, # Other "mjpeg", # base class, has no reqs or component to load. "stream", # Stream cannot install on all systems, can be imported without reqs.