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
@@ -15,8 +15,8 @@ from homeassistant.helpers import selector
from homeassistant.helpers.schema_config_entry_flow import SchemaFlowError
import voluptuous as vol
from custom_components.powercalc import CONF_CREATE_UTILITY_METERS
from custom_components.powercalc.const import (
CONF_CREATE_UTILITY_METERS,
CONF_DAILY_ENERGY_VALUE,
CONF_DAILY_FIXED_ENERGY,
CONF_GROUP,
@@ -11,7 +11,6 @@ from homeassistant.helpers.schema_config_entry_flow import SchemaFlowError
from homeassistant.helpers.typing import ConfigType
import voluptuous as vol
from custom_components.powercalc import DeviceType
from custom_components.powercalc.const import (
CONF_APPLY_TO_ALL,
CONF_CREATE_COST_SENSOR,
@@ -63,6 +62,7 @@ from custom_components.powercalc.flow_helper.schema import (
SECTION_COST_NAMING,
SECTION_COST_PRICING,
)
from custom_components.powercalc.power_profile.power_profile import DeviceType
from custom_components.powercalc.service.gui_configuration import apply_field_to_config_entries
if TYPE_CHECKING:
@@ -6,10 +6,6 @@ from homeassistant.config_entries import ConfigFlowResult
from homeassistant.helpers import selector, translation
import voluptuous as vol
from custom_components.powercalc import (
DOMAIN,
DeviceType,
)
from custom_components.powercalc.const import (
CONF_AVAILABILITY_ENTITY,
CONF_FIXED,
@@ -20,6 +16,7 @@ from custom_components.powercalc.const import (
CONF_SELF_USAGE_INCLUDED,
CONF_SUB_PROFILE,
CONF_VARIABLES,
DOMAIN,
DUMMY_ENTITY_ID,
LIBRARY_URL,
CalculationStrategy,
@@ -44,6 +41,7 @@ from custom_components.powercalc.power_profile.library import ModelInfo, Profile
from custom_components.powercalc.power_profile.power_profile import (
DEVICE_TYPE_DOMAIN,
DOMAIN_DEVICE_TYPE_MAPPING,
DeviceType,
DiscoveryBy,
PowerProfile,
)
@@ -193,45 +191,55 @@ class LibraryFlow:
if not self.flow.selected_profile:
return self.flow.async_abort(reason="model_not_supported") # pragma: no cover
if Step.LIBRARY_CUSTOM_FIELDS not in self.flow.handled_steps and self.flow.selected_profile.has_custom_fields:
profile_step = await self._async_next_profile_step(self.flow.selected_profile)
if profile_step:
return profile_step
strategy_step = await self._async_next_strategy_step(self.flow.selected_profile)
if strategy_step:
return strategy_step
return await self.flow.flow_handlers[FlowType.GROUP].async_step_assign_groups() # type: ignore[no-any-return]
async def _async_next_profile_step(self, profile: PowerProfile) -> ConfigFlowResult | None:
"""Return the next step needed to complete the profile itself, or None when nothing is left to ask."""
handled_steps = self.flow.handled_steps
if Step.LIBRARY_CUSTOM_FIELDS not in handled_steps and profile.has_custom_fields:
return await self.async_step_library_custom_fields()
if (
Step.AVAILABILITY_ENTITY not in self.flow.handled_steps
and self.flow.selected_profile.discovery_by == DiscoveryBy.DEVICE
):
if Step.AVAILABILITY_ENTITY not in handled_steps and profile.discovery_by == DiscoveryBy.DEVICE:
result = await self.async_step_availability_entity()
if result:
return result
if (
Step.SUB_PROFILE not in self.flow.handled_steps
and await self.flow.selected_profile.requires_manual_sub_profile_selection
):
if Step.SUB_PROFILE not in handled_steps and await profile.requires_manual_sub_profile_selection:
return await self.async_step_sub_profile()
return None
async def _async_next_strategy_step(self, profile: PowerProfile) -> ConfigFlowResult | None:
"""Return the next step needed to configure the calculation strategy, or None when nothing is left to ask."""
handled_steps = self.flow.handled_steps
virtual_power_flow = self.flow.flow_handlers[FlowType.VIRTUAL_POWER]
if (
Step.SMART_SWITCH not in self.flow.handled_steps
and self.flow.selected_profile.device_type == DeviceType.SMART_SWITCH
and self.flow.selected_profile.calculation_strategy == CalculationStrategy.FIXED
Step.SMART_SWITCH not in handled_steps
and profile.device_type == DeviceType.SMART_SWITCH
and profile.calculation_strategy == CalculationStrategy.FIXED
):
return await self.async_step_smart_switch()
if (
Step.FIXED not in self.flow.handled_steps and self.flow.selected_profile.needs_fixed_config
): # pragma: no cover
return await self.flow.flow_handlers[FlowType.VIRTUAL_POWER].async_step_fixed() # type: ignore[no-any-return]
if Step.FIXED not in handled_steps and profile.needs_fixed_config: # pragma: no cover
return await virtual_power_flow.async_step_fixed() # type: ignore[no-any-return]
if Step.LINEAR not in self.flow.handled_steps and self.flow.selected_profile.needs_linear_config:
return await self.flow.flow_handlers[FlowType.VIRTUAL_POWER].async_step_linear() # type: ignore[no-any-return]
if Step.LINEAR not in handled_steps and profile.needs_linear_config:
return await virtual_power_flow.async_step_linear() # type: ignore[no-any-return]
if (
Step.MULTI_SWITCH not in self.flow.handled_steps
and self.flow.selected_profile.calculation_strategy == CalculationStrategy.MULTI_SWITCH
):
return await self.flow.flow_handlers[FlowType.VIRTUAL_POWER].async_step_multi_switch() # type: ignore[no-any-return]
if Step.MULTI_SWITCH not in handled_steps and profile.calculation_strategy == CalculationStrategy.MULTI_SWITCH:
return await virtual_power_flow.async_step_multi_switch() # type: ignore[no-any-return]
return await self.flow.flow_handlers[FlowType.GROUP].async_step_assign_groups() # type: ignore[no-any-return]
return None
async def async_step_library_custom_fields(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
"""Handle the flow for custom fields."""
@@ -10,7 +10,7 @@ from homeassistant.const import CONF_DEVICE, CONF_ENTITY_ID, CONF_NAME
from homeassistant.helpers import selector
import voluptuous as vol
from custom_components.powercalc import SensorType
from custom_components.powercalc.const import SensorType
from custom_components.powercalc.flow_helper.common import PowercalcFormStep, Step
from custom_components.powercalc.flow_helper.schema import SCHEMA_UTILITY_METER_TOGGLE