217 files

This commit is contained in:
Home Assistant Version Control
2026-07-30 23:59:38 +00:00
parent d43a63ad29
commit 7b5e46e702
217 changed files with 15978 additions and 3912 deletions
@@ -14,6 +14,7 @@ from homeassistant.helpers.condition import ConditionCheckerType
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import TrackTemplate
from homeassistant.helpers.template import Template
from homeassistant.helpers.typing import ConfigType
import voluptuous as vol
from custom_components.powercalc.const import (
@@ -189,23 +190,30 @@ class CompositeStrategy(PowerCalculationStrategyInterface):
total = Decimal(0)
for sub_strategy in self.strategies:
strategy = sub_strategy.strategy
if sub_strategy.condition and not self._condition_matches(sub_strategy.condition, entity_state):
value = await self._calculate_sub_strategy(sub_strategy, entity_state)
if value is None:
continue
if isinstance(strategy, PlaybookStrategy):
await self.activate_playbook(strategy)
if entity_state.state != STATE_OFF or strategy.can_calculate_standby():
value = await strategy.calculate(entity_state)
if value is not None:
if self.mode == CompositeMode.STOP_AT_FIRST:
return value
total += value
if self.mode == CompositeMode.STOP_AT_FIRST:
return value
total += value
return total if self.mode == CompositeMode.SUM_ALL else None
async def _calculate_sub_strategy(self, sub_strategy: SubStrategy, entity_state: State) -> Decimal | None:
"""Calculate the power for a single sub strategy. Returns None when the sub strategy must be skipped."""
strategy = sub_strategy.strategy
if sub_strategy.condition and not self._condition_matches(sub_strategy.condition, entity_state):
return None
if isinstance(strategy, PlaybookStrategy):
await self.activate_playbook(strategy)
if entity_state.state == STATE_OFF and not strategy.can_calculate_standby():
return None
return await strategy.calculate(entity_state)
def _condition_matches(self, condition: ConditionCheckerType, entity_state: State) -> bool:
try:
return condition(self.hass, {"state": entity_state})
@@ -265,7 +273,7 @@ class CompositeStrategy(PowerCalculationStrategyInterface):
def resolve_track_templates_from_condition(
self,
condition_config: dict,
condition_config: ConfigType,
templates: list[str | TrackTemplate],
) -> None:
"""Resolve track templates from condition config."""
@@ -282,6 +290,6 @@ class CompositeStrategy(PowerCalculationStrategyInterface):
@dataclass
class SubStrategy:
condition_config: dict | None
condition_config: ConfigType | None
condition: ConditionCheckerType | None
strategy: PowerCalculationStrategyInterface