Initil after Upgrade
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
import re
|
||||
from typing import Any, NamedTuple, Protocol
|
||||
from typing import NamedTuple, Protocol
|
||||
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
|
||||
@@ -79,7 +79,13 @@ class SubProfileSelectConfig(NamedTuple):
|
||||
|
||||
class SubProfileMatcher(Protocol):
|
||||
@classmethod
|
||||
def from_config(cls, config: dict, **kwargs: Any) -> SubProfileMatcher: # noqa: ANN401
|
||||
def from_config(
|
||||
cls,
|
||||
config: dict,
|
||||
*,
|
||||
hass: HomeAssistant | None = None,
|
||||
source_entity: SourceEntity | None = None,
|
||||
) -> SubProfileMatcher:
|
||||
"""Create a matcher from a config dict."""
|
||||
|
||||
def match(self, entity_state: State, source_entity: SourceEntity) -> str | None:
|
||||
@@ -114,8 +120,15 @@ class EntityStateMatcher(SubProfileMatcher):
|
||||
return self._mapping.get(state.state)
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config: dict, **kwargs: Any) -> EntityStateMatcher: # noqa: ANN401
|
||||
return cls(kwargs["hass"], kwargs["source_entity"], config["entity_id"], config["map"])
|
||||
def from_config(
|
||||
cls,
|
||||
config: dict,
|
||||
*,
|
||||
hass: HomeAssistant | None = None,
|
||||
source_entity: SourceEntity | None = None,
|
||||
) -> EntityStateMatcher:
|
||||
assert hass is not None
|
||||
return cls(hass, source_entity, config["entity_id"], config["map"])
|
||||
|
||||
def get_tracking_entities(self) -> list[str]:
|
||||
return [self._entity_id]
|
||||
@@ -134,7 +147,13 @@ class AttributeMatcher(SubProfileMatcher):
|
||||
return self._mapping.get(val)
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config: dict, **kwargs: Any) -> AttributeMatcher: # noqa: ANN401
|
||||
def from_config(
|
||||
cls,
|
||||
config: dict,
|
||||
*,
|
||||
hass: HomeAssistant | None = None,
|
||||
source_entity: SourceEntity | None = None,
|
||||
) -> AttributeMatcher:
|
||||
return cls(config["attribute"], config["map"])
|
||||
|
||||
def get_tracking_entities(self) -> list[str]:
|
||||
@@ -153,7 +172,13 @@ class EntityIdMatcher(SubProfileMatcher):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config: dict, **kwargs: Any) -> EntityIdMatcher: # noqa: ANN401
|
||||
def from_config(
|
||||
cls,
|
||||
config: dict,
|
||||
*,
|
||||
hass: HomeAssistant | None = None,
|
||||
source_entity: SourceEntity | None = None,
|
||||
) -> EntityIdMatcher:
|
||||
return cls(config["pattern"], config["profile"])
|
||||
|
||||
def get_tracking_entities(self) -> list[str]:
|
||||
@@ -176,7 +201,13 @@ class IntegrationMatcher(SubProfileMatcher):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config: dict, **kwargs: Any) -> IntegrationMatcher: # noqa: ANN401
|
||||
def from_config(
|
||||
cls,
|
||||
config: dict,
|
||||
*,
|
||||
hass: HomeAssistant | None = None,
|
||||
source_entity: SourceEntity | None = None,
|
||||
) -> IntegrationMatcher:
|
||||
return cls(config["integration"], config["profile"])
|
||||
|
||||
def get_tracking_entities(self) -> list[str]:
|
||||
@@ -204,7 +235,13 @@ class EntityRegistryMatcher(SubProfileMatcher):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config: dict, **kwargs: Any) -> EntityRegistryMatcher: # noqa: ANN401
|
||||
def from_config(
|
||||
cls,
|
||||
config: dict,
|
||||
*,
|
||||
hass: HomeAssistant | None = None,
|
||||
source_entity: SourceEntity | None = None,
|
||||
) -> EntityRegistryMatcher:
|
||||
return cls(config["property"], config["value"], config["profile"])
|
||||
|
||||
def get_tracking_entities(self) -> list[str]:
|
||||
@@ -236,7 +273,13 @@ class ModelIdMatcher(SubProfileMatcher):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config: dict, **kwargs: Any) -> ModelIdMatcher: # noqa: ANN401
|
||||
def from_config(
|
||||
cls,
|
||||
config: dict,
|
||||
*,
|
||||
hass: HomeAssistant | None = None,
|
||||
source_entity: SourceEntity | None = None,
|
||||
) -> ModelIdMatcher:
|
||||
return cls(config["model_id"], config["profile"])
|
||||
|
||||
def get_tracking_entities(self) -> list[str]:
|
||||
|
||||
Reference in New Issue
Block a user