Replace attrs with dataclasses in hassfest (#84475)

This commit is contained in:
Franck Nijhof 2022-12-23 15:46:00 +01:00 committed by GitHub
parent 94755a5773
commit 139dd22ce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 24 deletions

View File

@ -1,44 +1,43 @@
"""Models for manifest validator."""
from __future__ import annotations
from dataclasses import dataclass, field
import json
import pathlib
from typing import Any
import attr
@attr.s
@dataclass
class Error:
"""Error validating an integration."""
plugin: str = attr.ib()
error: str = attr.ib()
fixable: bool = attr.ib(default=False)
plugin: str
error: str
fixable: bool = False
def __str__(self) -> str:
"""Represent error as string."""
return f"[{self.plugin.upper()}] {self.error}"
@attr.s
@dataclass
class Config:
"""Config for the run."""
specific_integrations: list[pathlib.Path] | None = attr.ib()
root: pathlib.Path = attr.ib()
action: str = attr.ib()
requirements: bool = attr.ib()
errors: list[Error] = attr.ib(factory=list)
cache: dict[str, Any] = attr.ib(factory=dict)
plugins: set[str] = attr.ib(factory=set)
specific_integrations: list[pathlib.Path] | None
root: pathlib.Path
action: str
requirements: bool
errors: list[Error] = field(default_factory=list)
cache: dict[str, Any] = field(default_factory=dict)
plugins: set[str] = field(default_factory=set)
def add_error(self, *args: Any, **kwargs: Any) -> None:
"""Add an error."""
self.errors.append(Error(*args, **kwargs))
@attr.s
@dataclass
class Brand:
"""Represent a brand in our validator."""
@ -54,8 +53,8 @@ class Brand:
return brands
path: pathlib.Path = attr.ib()
_brand: dict[str, Any] | None = attr.ib(default=None)
path: pathlib.Path
_brand: dict[str, Any] | None = None
@property
def brand(self) -> dict[str, Any]:
@ -100,7 +99,7 @@ class Brand:
self._brand = brand
@attr.s
@dataclass
class Integration:
"""Represent an integration in our validator."""
@ -129,11 +128,11 @@ class Integration:
return integrations
path: pathlib.Path = attr.ib()
_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)
path: pathlib.Path
_manifest: dict[str, Any] | None = None
errors: list[Error] = field(default_factory=list)
warnings: list[Error] = field(default_factory=list)
translated_name: bool = False
@property
def manifest(self) -> dict[str, Any]:

View File

@ -12,7 +12,7 @@ def integration():
"""Fixture for hassfest integration model."""
integration = Integration(
path=Path("homeassistant/components/test"),
manifest={
_manifest={
"domain": "test",
"documentation": "https://example.com",
"name": "test",