Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move StrEnum to homeassistant.backports and move Platform to homeassistant.const #60880

Merged
merged 4 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/backports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Backports from newer Python versions."""
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Enum related utilities."""
"""Enum backports from standard lib."""
from __future__ import annotations

from enum import Enum
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
Expand All @@ -18,7 +19,6 @@
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType, StateType
from homeassistant.util.enum import StrEnum

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/button/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.config_validation import ( # noqa: F401
Expand All @@ -19,7 +20,6 @@
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import dt as dt_util
from homeassistant.util.enum import StrEnum

from .const import DOMAIN, SERVICE_PRESS

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
SERVICE_CLOSE_COVER,
Expand All @@ -34,7 +35,6 @@
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.loader import bind_hass
from homeassistant.util.enum import StrEnum

# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/humidifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_MODE,
Expand All @@ -26,7 +27,6 @@
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass
from homeassistant.util.enum import StrEnum

from .const import ( # noqa: F401
ATTR_AVAILABLE_MODES,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/media_player/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import voluptuous as vol
from yarl import URL

from homeassistant.backports.enum import StrEnum
from homeassistant.components import websocket_api
from homeassistant.components.http import KEY_AUTHENTICATED, HomeAssistantView
from homeassistant.components.websocket_api.const import (
Expand Down Expand Up @@ -63,7 +64,6 @@
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.network import get_url
from homeassistant.loader import bind_hass
from homeassistant.util.enum import StrEnum

from .const import (
ATTR_APP_ID,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_MODE
from homeassistant.core import HomeAssistant, ServiceCall
Expand All @@ -18,7 +19,6 @@
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.enum import StrEnum

from .const import (
ATTR_MAX,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ciso8601
import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( # noqa: F401
DEVICE_CLASS_AQI,
Expand Down Expand Up @@ -53,7 +54,6 @@
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType, StateType
from homeassistant.util.enum import StrEnum

from .const import CONF_STATE_CLASS # noqa: F401

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
SERVICE_TOGGLE,
Expand All @@ -24,7 +25,6 @@
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass
from homeassistant.util.enum import StrEnum

DOMAIN = "switch"
SCAN_INTERVAL = timedelta(seconds=30)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wled/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from typing import Final

from homeassistant.backports.enum import StrEnum

MAJOR_VERSION: Final = 2021
MINOR_VERSION: Final = 12
PATCH_VERSION: Final = "0.dev0"
Expand All @@ -16,6 +18,42 @@
# 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"
STT = "stt"
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 = "*"

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/device_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import attr

from homeassistant.backports.enum import StrEnum
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.exceptions import RequiredParameterMissing
from homeassistant.helpers import storage
from homeassistant.helpers.frame import report
from homeassistant.loader import bind_hass
from homeassistant.util.enum import StrEnum
import homeassistant.util.uuid as uuid_util

from .debounce import Debouncer
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.config import DATA_CUSTOMIZE
from homeassistant.const import (
ATTR_ASSUMED_STATE,
Expand Down Expand Up @@ -43,7 +44,6 @@
from homeassistant.helpers.typing import StateType
from homeassistant.loader import bind_hass
from homeassistant.util import dt as dt_util, ensure_unique_string, slugify
from homeassistant.util.enum import StrEnum

_LOGGER = logging.getLogger(__name__)
SLOW_UPDATE_WARNING = 10
Expand Down
36 changes: 0 additions & 36 deletions homeassistant/helpers/entity_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
)
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,
Expand Down Expand Up @@ -63,41 +62,6 @@
_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."""

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/entity_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import attr
import voluptuous as vol

from homeassistant.backports.enum import StrEnum
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_FRIENDLY_NAME,
Expand All @@ -42,7 +43,6 @@
from homeassistant.helpers.frame import report
from homeassistant.loader import bind_hass
from homeassistant.util import slugify, uuid as uuid_util
from homeassistant.util.enum import StrEnum
from homeassistant.util.yaml import load_yaml

from .typing import UNDEFINED, UndefinedType
Expand Down
30 changes: 2 additions & 28 deletions homeassistant/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
EVENT_COMPONENT_LOADED,
EVENT_HOMEASSISTANT_START,
PLATFORM_FORMAT,
Platform,
)
from homeassistant.core import CALLBACK_TYPE
from homeassistant.exceptions import HomeAssistantError
Expand All @@ -26,34 +27,7 @@

ATTR_COMPONENT = "component"

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",
}
BASE_PLATFORMS = {platform.value for platform in Platform}

DATA_SETUP_DONE = "setup_done"
DATA_SETUP_STARTED = "setup_started"
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/util/dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import ciso8601

from homeassistant.const import MATCH_ALL

if sys.version_info[:2] >= (3, 9):
import zoneinfo
else:
Expand Down Expand Up @@ -215,7 +213,7 @@ def formatn(number: int, unit: str) -> 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 == MATCH_ALL:
if parameter is None or parameter == "*":
res = list(range(min_value, max_value + 1))
elif isinstance(parameter, str):
if parameter.startswith("/"):
Expand Down
7 changes: 2 additions & 5 deletions script/hassfest/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
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

Expand Down Expand Up @@ -91,12 +91,11 @@ def visit_Attribute(self, node):


ALLOWED_USED_COMPONENTS = {
*{platform.value for platform in Platform},
# Internal integrations
"alert",
"automation",
"button",
"conversation",
"button",
"device_automation",
"frontend",
"group",
Expand All @@ -119,8 +118,6 @@ def visit_Attribute(self, node):
"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.
Expand Down
1 change: 1 addition & 0 deletions tests/backports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The tests for the backports."""
Loading