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": {
|
"services": {
|
||||||
"process": {
|
"process": {
|
||||||
"service": "mdi:message-processing"
|
"service": "mdi:message-processing"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"codeowners": ["@home-assistant/core", "@synesthesiam", "@arturpragacz"],
|
"codeowners": ["@home-assistant/core", "@synesthesiam", "@arturpragacz"],
|
||||||
"dependencies": ["http", "intent"],
|
"dependencies": ["http", "intent"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/conversation",
|
"documentation": "https://www.home-assistant.io/integrations/conversation",
|
||||||
"integration_type": "system",
|
"integration_type": "entity",
|
||||||
"quality_scale": "internal",
|
"quality_scale": "internal",
|
||||||
"requirements": ["hassil==3.2.0", "home-assistant-intents==2025.9.3"]
|
"requirements": ["hassil==3.2.0", "home-assistant-intents==2025.9.3"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from enum import StrEnum
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import TYPE_CHECKING, Final
|
from typing import TYPE_CHECKING, Final
|
||||||
|
|
||||||
|
from .generated.entity_platforms import EntityPlatforms
|
||||||
from .helpers.deprecation import (
|
from .helpers.deprecation import (
|
||||||
DeprecatedConstant,
|
DeprecatedConstant,
|
||||||
DeprecatedConstantEnum,
|
DeprecatedConstantEnum,
|
||||||
@@ -36,54 +37,8 @@ REQUIRED_NEXT_PYTHON_HA_RELEASE: Final = ""
|
|||||||
# Format for platform files
|
# Format for platform files
|
||||||
PLATFORM_FORMAT: Final = "{platform}.{domain}"
|
PLATFORM_FORMAT: Final = "{platform}.{domain}"
|
||||||
|
|
||||||
|
# Type alias to avoid 1000 MyPy errors
|
||||||
class Platform(StrEnum):
|
Platform = EntityPlatforms
|
||||||
"""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"
|
|
||||||
|
|
||||||
|
|
||||||
BASE_PLATFORMS: Final = {platform.value for platform in Platform}
|
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,
|
dhcp,
|
||||||
docker,
|
docker,
|
||||||
icons,
|
icons,
|
||||||
|
integration_info,
|
||||||
json,
|
json,
|
||||||
manifest,
|
manifest,
|
||||||
metadata,
|
metadata,
|
||||||
@@ -44,6 +45,7 @@ INTEGRATION_PLUGINS = [
|
|||||||
dependencies,
|
dependencies,
|
||||||
dhcp,
|
dhcp,
|
||||||
icons,
|
icons,
|
||||||
|
integration_info,
|
||||||
json,
|
json,
|
||||||
manifest,
|
manifest,
|
||||||
mqtt,
|
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 res["success"], res
|
||||||
assert not res["result"]["success"]
|
assert not res["result"]["success"]
|
||||||
assert res["result"]["errors"][0]["path"] == ["platform"]
|
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
|
# create entity with unsupported platform
|
||||||
await client.send_json_auto_id(
|
await client.send_json_auto_id(
|
||||||
|
|||||||
Reference in New Issue
Block a user