1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-12 06:50:00 +00:00
Files
.devcontainer
.github
.vscode
docs
homeassistant
machine
pylint
rootfs
script
hassfest
scaffold
templates
__init__.py
__main__.py
const.py
docs.py
error.py
gather_info.py
generate.py
model.py
translations
__init__.py
bootstrap
check_dirty
check_format
gen_requirements_all.py
inspect_schemas.py
lazytox.py
lint
monkeytype
release
run-in-env.sh
server
setup
update
version_bump.py
tests
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hadolint.yaml
.ignore
.pre-commit-config.yaml
.prettierignore
.readthedocs.yml
.strict-typing
.yamllint
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
azure-pipelines-ci.yml
azure-pipelines-translation.yml
azure-pipelines-wheels.yml
build.json
codecov.yml
mypy.ini
pyproject.toml
requirements.txt
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
setup.cfg
setup.py
tox.ini
core/script/scaffold/model.py
Paulus Schoutsen 9f8e683ae3 Ask for IoT class during scaffold ()
Co-authored-by: Milan Meulemans <milan.meulemans@live.be>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-04-25 12:13:22 +02:00

71 lines
2.1 KiB
Python

"""Models for scaffolding."""
from __future__ import annotations
import json
from pathlib import Path
import attr
from .const import COMPONENT_DIR, TESTS_DIR
@attr.s
class Info:
"""Info about new integration."""
domain: str = attr.ib()
name: str = attr.ib()
is_new: bool = attr.ib()
codeowner: str = attr.ib(default=None)
requirement: str = attr.ib(default=None)
iot_class: str = attr.ib(default=None)
authentication: str = attr.ib(default=None)
discoverable: str = attr.ib(default=None)
oauth2: str = attr.ib(default=None)
files_added: set[Path] = attr.ib(factory=set)
tests_added: set[Path] = attr.ib(factory=set)
examples_added: set[Path] = attr.ib(factory=set)
@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))