mirror of
https://github.com/home-assistant/core.git
synced 2025-12-20 02:48:57 +00:00
Automatically generate entity platform enum (#152193)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
{
|
||||
"entity_component": {
|
||||
"_": {
|
||||
"default": "mdi:forum-outline"
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"process": {
|
||||
"service": "mdi:message-processing"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"codeowners": ["@home-assistant/core", "@synesthesiam", "@arturpragacz"],
|
||||
"dependencies": ["http", "intent"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/conversation",
|
||||
"integration_type": "system",
|
||||
"integration_type": "entity",
|
||||
"quality_scale": "internal",
|
||||
"requirements": ["hassil==3.2.0", "home-assistant-intents==2025.9.3"]
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ from enum import StrEnum
|
||||
from functools import partial
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from .generated.entity_platforms import EntityPlatforms
|
||||
from .helpers.deprecation import (
|
||||
DeprecatedConstant,
|
||||
DeprecatedConstantEnum,
|
||||
@@ -36,54 +37,8 @@ REQUIRED_NEXT_PYTHON_HA_RELEASE: Final = ""
|
||||
# Format for platform files
|
||||
PLATFORM_FORMAT: Final = "{platform}.{domain}"
|
||||
|
||||
|
||||
class Platform(StrEnum):
|
||||
"""Available entity platforms."""
|
||||
|
||||
AI_TASK = "ai_task"
|
||||
AIR_QUALITY = "air_quality"
|
||||
ALARM_CONTROL_PANEL = "alarm_control_panel"
|
||||
ASSIST_SATELLITE = "assist_satellite"
|
||||
BINARY_SENSOR = "binary_sensor"
|
||||
BUTTON = "button"
|
||||
CALENDAR = "calendar"
|
||||
CAMERA = "camera"
|
||||
CLIMATE = "climate"
|
||||
CONVERSATION = "conversation"
|
||||
COVER = "cover"
|
||||
DATE = "date"
|
||||
DATETIME = "datetime"
|
||||
DEVICE_TRACKER = "device_tracker"
|
||||
EVENT = "event"
|
||||
FAN = "fan"
|
||||
GEO_LOCATION = "geo_location"
|
||||
HUMIDIFIER = "humidifier"
|
||||
IMAGE = "image"
|
||||
IMAGE_PROCESSING = "image_processing"
|
||||
LAWN_MOWER = "lawn_mower"
|
||||
LIGHT = "light"
|
||||
LOCK = "lock"
|
||||
MEDIA_PLAYER = "media_player"
|
||||
NOTIFY = "notify"
|
||||
NUMBER = "number"
|
||||
REMOTE = "remote"
|
||||
SCENE = "scene"
|
||||
SELECT = "select"
|
||||
SENSOR = "sensor"
|
||||
SIREN = "siren"
|
||||
STT = "stt"
|
||||
SWITCH = "switch"
|
||||
TEXT = "text"
|
||||
TIME = "time"
|
||||
TODO = "todo"
|
||||
TTS = "tts"
|
||||
UPDATE = "update"
|
||||
VACUUM = "vacuum"
|
||||
VALVE = "valve"
|
||||
WAKE_WORD = "wake_word"
|
||||
WATER_HEATER = "water_heater"
|
||||
WEATHER = "weather"
|
||||
|
||||
# Type alias to avoid 1000 MyPy errors
|
||||
Platform = EntityPlatforms
|
||||
|
||||
BASE_PLATFORMS: Final = {platform.value for platform in Platform}
|
||||
|
||||
|
||||
54
homeassistant/generated/entity_platforms.py
generated
Normal file
54
homeassistant/generated/entity_platforms.py
generated
Normal file
@@ -0,0 +1,54 @@
|
||||
"""Automatically generated file.
|
||||
|
||||
To update, run python3 -m script.hassfest
|
||||
"""
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class EntityPlatforms(StrEnum):
|
||||
"""Available entity platforms."""
|
||||
|
||||
AI_TASK = "ai_task"
|
||||
AIR_QUALITY = "air_quality"
|
||||
ALARM_CONTROL_PANEL = "alarm_control_panel"
|
||||
ASSIST_SATELLITE = "assist_satellite"
|
||||
BINARY_SENSOR = "binary_sensor"
|
||||
BUTTON = "button"
|
||||
CALENDAR = "calendar"
|
||||
CAMERA = "camera"
|
||||
CLIMATE = "climate"
|
||||
CONVERSATION = "conversation"
|
||||
COVER = "cover"
|
||||
DATE = "date"
|
||||
DATETIME = "datetime"
|
||||
DEVICE_TRACKER = "device_tracker"
|
||||
EVENT = "event"
|
||||
FAN = "fan"
|
||||
GEO_LOCATION = "geo_location"
|
||||
HUMIDIFIER = "humidifier"
|
||||
IMAGE = "image"
|
||||
IMAGE_PROCESSING = "image_processing"
|
||||
LAWN_MOWER = "lawn_mower"
|
||||
LIGHT = "light"
|
||||
LOCK = "lock"
|
||||
MEDIA_PLAYER = "media_player"
|
||||
NOTIFY = "notify"
|
||||
NUMBER = "number"
|
||||
REMOTE = "remote"
|
||||
SCENE = "scene"
|
||||
SELECT = "select"
|
||||
SENSOR = "sensor"
|
||||
SIREN = "siren"
|
||||
STT = "stt"
|
||||
SWITCH = "switch"
|
||||
TEXT = "text"
|
||||
TIME = "time"
|
||||
TODO = "todo"
|
||||
TTS = "tts"
|
||||
UPDATE = "update"
|
||||
VACUUM = "vacuum"
|
||||
VALVE = "valve"
|
||||
WAKE_WORD = "wake_word"
|
||||
WATER_HEATER = "water_heater"
|
||||
WEATHER = "weather"
|
||||
@@ -19,6 +19,7 @@ from . import (
|
||||
dhcp,
|
||||
docker,
|
||||
icons,
|
||||
integration_info,
|
||||
json,
|
||||
manifest,
|
||||
metadata,
|
||||
@@ -44,6 +45,7 @@ INTEGRATION_PLUGINS = [
|
||||
dependencies,
|
||||
dhcp,
|
||||
icons,
|
||||
integration_info,
|
||||
json,
|
||||
manifest,
|
||||
mqtt,
|
||||
|
||||
42
script/hassfest/integration_info.py
Normal file
42
script/hassfest/integration_info.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Write integration constants."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .model import Config, Integration
|
||||
from .serializer import format_python
|
||||
|
||||
|
||||
def validate(integrations: dict[str, Integration], config: Config) -> None:
|
||||
"""Validate integrations file."""
|
||||
|
||||
if config.specific_integrations:
|
||||
return
|
||||
|
||||
int_type = "entity"
|
||||
|
||||
domains = [
|
||||
integration.domain
|
||||
for integration in integrations.values()
|
||||
if integration.manifest.get("integration_type") == int_type
|
||||
# Tag is type "entity" but has no entity platform
|
||||
and integration.domain != "tag"
|
||||
]
|
||||
|
||||
code = [
|
||||
"from enum import StrEnum",
|
||||
"class EntityPlatforms(StrEnum):",
|
||||
f' """Available {int_type} platforms."""',
|
||||
]
|
||||
code.extend([f' {domain.upper()} = "{domain}"' for domain in sorted(domains)])
|
||||
|
||||
config.cache[f"integrations_{int_type}"] = format_python(
|
||||
"\n".join(code), generator="script.hassfest"
|
||||
)
|
||||
|
||||
|
||||
def generate(integrations: dict[str, Integration], config: Config) -> None:
|
||||
"""Generate integration file."""
|
||||
int_type = "entity"
|
||||
filename = "entity_platforms"
|
||||
platform_path = config.root / f"homeassistant/generated/{filename}.py"
|
||||
platform_path.write_text(config.cache[f"integrations_{int_type}"])
|
||||
@@ -88,7 +88,7 @@ async def test_create_entity_error(
|
||||
assert res["success"], res
|
||||
assert not res["result"]["success"]
|
||||
assert res["result"]["errors"][0]["path"] == ["platform"]
|
||||
assert res["result"]["error_base"].startswith("expected Platform or one of")
|
||||
assert res["result"]["error_base"].startswith("expected EntityPlatforms or one of")
|
||||
|
||||
# create entity with unsupported platform
|
||||
await client.send_json_auto_id(
|
||||
|
||||
Reference in New Issue
Block a user