Updated apps

This commit is contained in:
2026-07-20 22:52:35 -04:00
parent 28a8cb98f6
commit a0c3271743
1164 changed files with 94781 additions and 6892 deletions
@@ -53,23 +53,30 @@ class SubProfileSelector:
def _create_matcher(self, matcher_config: dict) -> SubProfileMatcher:
"""Create a matcher from json config. Can be extended for more matchers in the future."""
matcher_type: SubProfileMatcherType = matcher_config["type"]
matcher_classes: dict[SubProfileMatcherType, type[SubProfileMatcher]] = {
SubProfileMatcherType.ATTRIBUTE: AttributeMatcher,
SubProfileMatcherType.ENTITY_STATE: EntityStateMatcher,
SubProfileMatcherType.ENTITY_ID: EntityIdMatcher,
SubProfileMatcherType.ENTITY_REGISTRY: EntityRegistryMatcher,
SubProfileMatcherType.INTEGRATION: IntegrationMatcher,
SubProfileMatcherType.MODEL_ID: ModelIdMatcher,
}
if matcher_type not in matcher_classes:
raise PowercalcSetupError(f"Unknown sub profile matcher type: {matcher_type}")
return matcher_classes[matcher_type].from_config(
matcher_config,
hass=self._hass,
source_entity=self._source_entity,
)
match matcher_type:
case SubProfileMatcherType.ATTRIBUTE:
return AttributeMatcher(matcher_config["attribute"], matcher_config["map"])
case SubProfileMatcherType.ENTITY_STATE:
return EntityStateMatcher(
self._hass,
self._source_entity,
matcher_config["entity_id"],
matcher_config["map"],
)
case SubProfileMatcherType.ENTITY_ID:
return EntityIdMatcher(matcher_config["pattern"], matcher_config["profile"])
case SubProfileMatcherType.ENTITY_REGISTRY:
return EntityRegistryMatcher(
matcher_config["property"],
matcher_config["value"],
matcher_config["profile"],
)
case SubProfileMatcherType.INTEGRATION:
return IntegrationMatcher(matcher_config["integration"], matcher_config["profile"])
case SubProfileMatcherType.MODEL_ID:
return ModelIdMatcher(matcher_config["model_id"], matcher_config["profile"])
case _:
raise PowercalcSetupError(f"Unknown sub profile matcher type: {matcher_type}")
class SubProfileSelectConfig(NamedTuple):
@@ -78,21 +85,12 @@ class SubProfileSelectConfig(NamedTuple):
class SubProfileMatcher(Protocol):
@classmethod
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:
"""Returns a sub profile."""
def get_tracking_entities(self) -> list[str]:
"""Get extra entities to track for state changes."""
return []
class EntityStateMatcher(SubProfileMatcher):
@@ -119,17 +117,6 @@ class EntityStateMatcher(SubProfileMatcher):
return self._mapping.get(state.state)
@classmethod
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]
@@ -146,19 +133,6 @@ class AttributeMatcher(SubProfileMatcher):
return self._mapping.get(val)
@classmethod
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]:
return []
class EntityIdMatcher(SubProfileMatcher):
def __init__(self, pattern: str, profile: str) -> None:
@@ -171,19 +145,6 @@ class EntityIdMatcher(SubProfileMatcher):
return None
@classmethod
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]:
return []
class IntegrationMatcher(SubProfileMatcher):
def __init__(self, integration: str, profile: str) -> None:
@@ -200,19 +161,6 @@ class IntegrationMatcher(SubProfileMatcher):
return None
@classmethod
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]:
return []
class EntityRegistryMatcher(SubProfileMatcher):
def __init__(self, property_name: str, value: object, profile: str) -> None:
@@ -234,19 +182,6 @@ class EntityRegistryMatcher(SubProfileMatcher):
return None
@classmethod
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]:
return []
def _matches_registry_value(self, registry_value: object) -> bool:
if registry_value == self._value:
return True
@@ -271,16 +206,3 @@ class ModelIdMatcher(SubProfileMatcher):
return self._profile
return None
@classmethod
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]:
return []