forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_info.py
More file actions
40 lines (30 loc) · 1.25 KB
/
Copy pathintegration_info.py
File metadata and controls
40 lines (30 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Write integration constants."""
from .model import Config, Integration, IntegrationType
from .serializer import format_python
def validate(integrations: dict[str, Integration], config: Config) -> None:
"""Validate integrations file."""
if config.specific_integrations:
return
int_type = IntegrationType.ENTITY
domains = [
integration.domain
for integration in integrations.values()
if integration.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 = IntegrationType.ENTITY
filename = "entity_platforms"
platform_path = config.root / f"homeassistant/generated/{filename}.py"
platform_path.write_text(config.cache[f"integrations_{int_type}"])