393 files
This commit is contained in:
@@ -300,7 +300,11 @@ class PowerCalculatorStrategyFactory:
|
||||
def _create_multi_switch(self, config: ConfigType, power_profile: PowerProfile | None) -> MultiSwitchStrategy:
|
||||
"""Create instance of multi switch strategy."""
|
||||
multi_switch_config: ConfigType = {}
|
||||
if power_profile and power_profile.multi_switch_config:
|
||||
if (
|
||||
power_profile
|
||||
and power_profile.is_strategy_supported(CalculationStrategy.MULTI_SWITCH)
|
||||
and power_profile.multi_switch_config
|
||||
):
|
||||
# Copy to avoid mutating the (potentially cached) profile config with the user's config below.
|
||||
multi_switch_config = dict(power_profile.multi_switch_config)
|
||||
multi_switch_config.update(config.get(CONF_MULTI_SWITCH, {}))
|
||||
@@ -319,7 +323,7 @@ class PowerCalculatorStrategyFactory:
|
||||
self._hass,
|
||||
entities,
|
||||
on_power=Decimal(on_power),
|
||||
off_power=Decimal(off_power) if off_power else None,
|
||||
off_power=Decimal(off_power) if off_power is not None else None,
|
||||
)
|
||||
|
||||
def _resolve_template(self, value: Any) -> Any: # noqa: ANN401
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from homeassistant.const import STATE_OFF
|
||||
from homeassistant.core import State
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import TrackTemplate
|
||||
@@ -77,3 +78,7 @@ class FixedStrategy(PowerCalculationStrategyInterface):
|
||||
)
|
||||
|
||||
return track_templates
|
||||
|
||||
def can_calculate_standby(self) -> bool:
|
||||
"""Return whether an explicit off-state power value is configured."""
|
||||
return self._per_state_power is not None and STATE_OFF in self._per_state_power
|
||||
|
||||
@@ -41,10 +41,12 @@ class MultiSwitchStrategy(PowerCalculationStrategyInterface):
|
||||
|
||||
async def calculate(self, entity_state: State) -> Decimal | None:
|
||||
if self.known_states is None:
|
||||
self.known_states = {
|
||||
entity_id: (state.state if (state := self.hass.states.get(entity_id)) else STATE_UNAVAILABLE)
|
||||
for entity_id in self.switch_entities
|
||||
}
|
||||
self.known_states = dict.fromkeys(self.switch_entities, STATE_UNAVAILABLE)
|
||||
|
||||
for entity_id in self.switch_entities:
|
||||
state = self.hass.states.get(entity_id)
|
||||
if state is not None:
|
||||
self.known_states[entity_id] = state.state
|
||||
|
||||
if entity_state.entity_id != DUMMY_ENTITY_ID and entity_state.entity_id in self.switch_entities:
|
||||
self.known_states[entity_state.entity_id] = entity_state.state
|
||||
|
||||
Reference in New Issue
Block a user