diff --git a/script/hassfest/model.py b/script/hassfest/model.py index 6b500daa9b3..fa1580b0317 100644 --- a/script/hassfest/model.py +++ b/script/hassfest/model.py @@ -55,7 +55,13 @@ class Brand: return brands path: pathlib.Path = attr.ib() - brand: dict[str, Any] | None = attr.ib(default=None) + _brand: dict[str, Any] | None = attr.ib(default=None) + + @property + def brand(self) -> dict[str, Any]: + """Guarded access to brand.""" + assert self._brand is not None, "brand has not been loaded" + return self._brand @property def domain(self) -> str: @@ -65,19 +71,16 @@ class Brand: @property def name(self) -> str | None: """Return name of the integration.""" - assert self.brand is not None, "brand has not been loaded" return self.brand.get("name") @property def integrations(self) -> list[str]: """Return the sub integrations of this brand.""" - assert self.brand is not None, "brand has not been loaded" return self.brand.get("integrations", []) @property def iot_standards(self) -> list[str]: """Return list of supported IoT standards.""" - assert self.brand is not None, "brand has not been loaded" return self.brand.get("iot_standards", []) def load_brand(self, config: Config) -> None: @@ -94,7 +97,7 @@ class Brand: ) return - self.brand = brand + self._brand = brand @attr.s @@ -127,11 +130,17 @@ class Integration: return integrations path: pathlib.Path = attr.ib() - manifest: dict[str, Any] | None = attr.ib(default=None) + _manifest: dict[str, Any] | None = attr.ib(default=None) errors: list[Error] = attr.ib(factory=list) warnings: list[Error] = attr.ib(factory=list) translated_name: bool = attr.ib(default=False) + @property + def manifest(self) -> dict[str, Any]: + """Guarded access to manifest.""" + assert self._manifest is not None, "manifest has not been loaded" + return self._manifest + @property def domain(self) -> str: """Integration domain.""" @@ -145,62 +154,52 @@ class Integration: @property def disabled(self) -> str | None: """Return if integration is disabled.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("disabled") @property def name(self) -> str: """Return name of the integration.""" - assert self.manifest is not None, "manifest has not been loaded" name: str = self.manifest["name"] return name @property def quality_scale(self) -> str | None: """Return quality scale of the integration.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("quality_scale") @property def config_flow(self) -> bool: """Return if the integration has a config flow.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("config_flow", False) @property def requirements(self) -> list[str]: """List of requirements.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("requirements", []) @property def dependencies(self) -> list[str]: """List of dependencies.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("dependencies", []) @property def supported_by(self) -> str: """Return the integration supported by this virtual integration.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("supported_by", {}) @property def integration_type(self) -> str: """Get integration_type.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("integration_type", "hub") @property def iot_class(self) -> str | None: """Return the integration IoT Class.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("iot_class") @property def iot_standards(self) -> list[str]: """Return the IoT standard supported by this virtual integration.""" - assert self.manifest is not None, "manifest has not been loaded" return self.manifest.get("iot_standards", []) def add_error(self, *args: Any, **kwargs: Any) -> None: @@ -224,4 +223,4 @@ class Integration: self.add_error("model", f"Manifest contains invalid JSON: {err}") return - self.manifest = manifest + self._manifest = manifest diff --git a/tests/hassfest/test_version.py b/tests/hassfest/test_version.py index 7f12fb83fd7..eee184404b8 100644 --- a/tests/hassfest/test_version.py +++ b/tests/hassfest/test_version.py @@ -13,7 +13,7 @@ from script.hassfest.model import Integration def integration(): """Fixture for hassfest integration model.""" integration = Integration("") - integration.manifest = { + integration._manifest = { "domain": "test", "documentation": "https://example.com", "name": "test",