mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Split scaffolding script (#26832)
* Add scaffolding split * Add second config flow method
This commit is contained in:
committed by
Aaron Bach
parent
2e4cc7e5a0
commit
5a4a3e17cc
@ -1,6 +1,11 @@
|
||||
"""Models for scaffolding."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import attr
|
||||
|
||||
from .const import COMPONENT_DIR, TESTS_DIR
|
||||
|
||||
|
||||
@attr.s
|
||||
class Info:
|
||||
@ -8,5 +13,49 @@ class Info:
|
||||
|
||||
domain: str = attr.ib()
|
||||
name: str = attr.ib()
|
||||
codeowner: str = attr.ib()
|
||||
requirement: str = attr.ib()
|
||||
codeowner: str = attr.ib(default=None)
|
||||
requirement: str = attr.ib(default=None)
|
||||
authentication: str = attr.ib(default=None)
|
||||
discoverable: str = attr.ib(default=None)
|
||||
|
||||
@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))
|
||||
|
Reference in New Issue
Block a user