2019-09-21 00:02:18 +00:00
|
|
|
"""Models for scaffolding."""
|
2021-03-18 21:58:19 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2019-09-23 03:46:50 +00:00
|
|
|
import json
|
|
|
|
from pathlib import Path
|
|
|
|
|
2019-09-21 00:02:18 +00:00
|
|
|
import attr
|
|
|
|
|
2019-09-23 03:46:50 +00:00
|
|
|
from .const import COMPONENT_DIR, TESTS_DIR
|
|
|
|
|
2019-09-21 00:02:18 +00:00
|
|
|
|
|
|
|
@attr.s
|
|
|
|
class Info:
|
|
|
|
"""Info about new integration."""
|
|
|
|
|
|
|
|
domain: str = attr.ib()
|
|
|
|
name: str = attr.ib()
|
2019-10-30 03:34:03 +00:00
|
|
|
is_new: bool = attr.ib()
|
2019-09-23 03:46:50 +00:00
|
|
|
codeowner: str = attr.ib(default=None)
|
|
|
|
requirement: str = attr.ib(default=None)
|
2021-04-25 10:13:22 +00:00
|
|
|
iot_class: str = attr.ib(default=None)
|
2019-09-23 03:46:50 +00:00
|
|
|
authentication: str = attr.ib(default=None)
|
|
|
|
discoverable: str = attr.ib(default=None)
|
2019-10-30 03:34:03 +00:00
|
|
|
oauth2: str = attr.ib(default=None)
|
|
|
|
|
2021-03-18 21:58:19 +00:00
|
|
|
files_added: set[Path] = attr.ib(factory=set)
|
|
|
|
tests_added: set[Path] = attr.ib(factory=set)
|
|
|
|
examples_added: set[Path] = attr.ib(factory=set)
|
2019-09-23 03:46:50 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def integration_dir(self) -> Path:
|
|
|
|
"""Return directory if integration."""
|
|
|
|
return COMPONENT_DIR / self.domain
|
|
|
|
|
|
|
|
@property
|
|
|
|
def tests_dir(self) -> Path:
|
|
|
|
"""Return test directory."""
|
|
|
|
return TESTS_DIR / self.domain
|
|
|
|
|
|
|
|
@property
|
|
|
|
def manifest_path(self) -> Path:
|
|
|
|
"""Path to the manifest."""
|
|
|
|
return COMPONENT_DIR / self.domain / "manifest.json"
|
|
|
|
|
|
|
|
def manifest(self) -> dict:
|
|
|
|
"""Return integration manifest."""
|
|
|
|
return json.loads(self.manifest_path.read_text())
|
|
|
|
|
|
|
|
def update_manifest(self, **kwargs) -> None:
|
|
|
|
"""Update the integration manifest."""
|
|
|
|
print(f"Updating {self.domain} manifest: {kwargs}")
|
|
|
|
self.manifest_path.write_text(
|
|
|
|
json.dumps({**self.manifest(), **kwargs}, indent=2)
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def strings_path(self) -> Path:
|
|
|
|
"""Path to the strings."""
|
|
|
|
return COMPONENT_DIR / self.domain / "strings.json"
|
|
|
|
|
|
|
|
def strings(self) -> dict:
|
|
|
|
"""Return integration strings."""
|
|
|
|
if not self.strings_path.exists():
|
|
|
|
return {}
|
|
|
|
return json.loads(self.strings_path.read_text())
|
|
|
|
|
|
|
|
def update_strings(self, **kwargs) -> None:
|
|
|
|
"""Update the integration strings."""
|
|
|
|
print(f"Updating {self.domain} strings: {list(kwargs)}")
|
|
|
|
self.strings_path.write_text(json.dumps({**self.strings(), **kwargs}, indent=2))
|