Replace attrs with dataclasses in hassfest (#84475)
This commit is contained in:
parent
94755a5773
commit
139dd22ce6
2 changed files with 23 additions and 24 deletions
|
@ -1,44 +1,43 @@
|
||||||
"""Models for manifest validator."""
|
"""Models for manifest validator."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import attr
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
@attr.s
|
|
||||||
class Error:
|
class Error:
|
||||||
"""Error validating an integration."""
|
"""Error validating an integration."""
|
||||||
|
|
||||||
plugin: str = attr.ib()
|
plugin: str
|
||||||
error: str = attr.ib()
|
error: str
|
||||||
fixable: bool = attr.ib(default=False)
|
fixable: bool = False
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Represent error as string."""
|
"""Represent error as string."""
|
||||||
return f"[{self.plugin.upper()}] {self.error}"
|
return f"[{self.plugin.upper()}] {self.error}"
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@dataclass
|
||||||
class Config:
|
class Config:
|
||||||
"""Config for the run."""
|
"""Config for the run."""
|
||||||
|
|
||||||
specific_integrations: list[pathlib.Path] | None = attr.ib()
|
specific_integrations: list[pathlib.Path] | None
|
||||||
root: pathlib.Path = attr.ib()
|
root: pathlib.Path
|
||||||
action: str = attr.ib()
|
action: str
|
||||||
requirements: bool = attr.ib()
|
requirements: bool
|
||||||
errors: list[Error] = attr.ib(factory=list)
|
errors: list[Error] = field(default_factory=list)
|
||||||
cache: dict[str, Any] = attr.ib(factory=dict)
|
cache: dict[str, Any] = field(default_factory=dict)
|
||||||
plugins: set[str] = attr.ib(factory=set)
|
plugins: set[str] = field(default_factory=set)
|
||||||
|
|
||||||
def add_error(self, *args: Any, **kwargs: Any) -> None:
|
def add_error(self, *args: Any, **kwargs: Any) -> None:
|
||||||
"""Add an error."""
|
"""Add an error."""
|
||||||
self.errors.append(Error(*args, **kwargs))
|
self.errors.append(Error(*args, **kwargs))
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@dataclass
|
||||||
class Brand:
|
class Brand:
|
||||||
"""Represent a brand in our validator."""
|
"""Represent a brand in our validator."""
|
||||||
|
|
||||||
|
@ -54,8 +53,8 @@ class Brand:
|
||||||
|
|
||||||
return brands
|
return brands
|
||||||
|
|
||||||
path: pathlib.Path = attr.ib()
|
path: pathlib.Path
|
||||||
_brand: dict[str, Any] | None = attr.ib(default=None)
|
_brand: dict[str, Any] | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brand(self) -> dict[str, Any]:
|
def brand(self) -> dict[str, Any]:
|
||||||
|
@ -100,7 +99,7 @@ class Brand:
|
||||||
self._brand = brand
|
self._brand = brand
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@dataclass
|
||||||
class Integration:
|
class Integration:
|
||||||
"""Represent an integration in our validator."""
|
"""Represent an integration in our validator."""
|
||||||
|
|
||||||
|
@ -129,11 +128,11 @@ class Integration:
|
||||||
|
|
||||||
return integrations
|
return integrations
|
||||||
|
|
||||||
path: pathlib.Path = attr.ib()
|
path: pathlib.Path
|
||||||
_manifest: dict[str, Any] | None = attr.ib(default=None)
|
_manifest: dict[str, Any] | None = None
|
||||||
errors: list[Error] = attr.ib(factory=list)
|
errors: list[Error] = field(default_factory=list)
|
||||||
warnings: list[Error] = attr.ib(factory=list)
|
warnings: list[Error] = field(default_factory=list)
|
||||||
translated_name: bool = attr.ib(default=False)
|
translated_name: bool = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def manifest(self) -> dict[str, Any]:
|
def manifest(self) -> dict[str, Any]:
|
||||||
|
|
|
@ -12,7 +12,7 @@ def integration():
|
||||||
"""Fixture for hassfest integration model."""
|
"""Fixture for hassfest integration model."""
|
||||||
integration = Integration(
|
integration = Integration(
|
||||||
path=Path("homeassistant/components/test"),
|
path=Path("homeassistant/components/test"),
|
||||||
manifest={
|
_manifest={
|
||||||
"domain": "test",
|
"domain": "test",
|
||||||
"documentation": "https://example.com",
|
"documentation": "https://example.com",
|
||||||
"name": "test",
|
"name": "test",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue