Revert "Move Platform StrEnum to const" (#60875)

This commit is contained in:
Franck Nijhof 2021-12-02 23:19:08 +01:00 committed by GitHub
parent 6e220d5d17
commit c8b0a3b667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 44 deletions

View File

@ -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

View File

@ -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 = "*"

View File

@ -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."""

View File

@ -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"

View File

@ -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("/"):

View File

@ -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.