58 files
This commit is contained in:
@@ -38,6 +38,7 @@ from .const import (
|
||||
CONF_POWER,
|
||||
CONF_SENSOR_TYPE,
|
||||
CONF_STANDBY_POWER,
|
||||
DISCOVERY_INTEGRATION_NAME,
|
||||
DISCOVERY_POWER_PROFILES,
|
||||
DISCOVERY_SOURCE_ENTITY,
|
||||
DOMAIN,
|
||||
@@ -400,6 +401,7 @@ class PowercalcConfigFlow(PowercalcCommonFlow, ConfigFlow, domain=DOMAIN):
|
||||
|
||||
self.source_entity_id = self.source_entity.entity_id
|
||||
self.name = self.source_entity.name
|
||||
integration_name = discovery_info.pop(DISCOVERY_INTEGRATION_NAME, None)
|
||||
|
||||
power_profiles: list[PowerProfile] = []
|
||||
if DISCOVERY_POWER_PROFILES in discovery_info:
|
||||
@@ -410,7 +412,7 @@ class PowercalcConfigFlow(PowercalcCommonFlow, ConfigFlow, domain=DOMAIN):
|
||||
self.sensor_config = discovery_info.copy()
|
||||
|
||||
self.context["title_placeholders"] = {
|
||||
"name": self.name or "",
|
||||
"name": f"{self.name} - {integration_name}" if integration_name else self.name or "",
|
||||
"manufacturer": str(self.sensor_config.get(CONF_MANUFACTURER)),
|
||||
"model": str(self.sensor_config.get(CONF_MODEL)),
|
||||
}
|
||||
@@ -549,12 +551,7 @@ class PowercalcOptionsFlow(PowercalcCommonFlow, OptionsFlow):
|
||||
|
||||
menu = [Step.BASIC_OPTIONS]
|
||||
if self.selected_sensor_type == SensorType.VIRTUAL_POWER:
|
||||
if self.strategy and self.should_add_strategy_option_to_menu():
|
||||
strategy_step = STRATEGY_STEP_MAPPING[self.strategy]
|
||||
menu.append(strategy_step)
|
||||
if self.selected_profile:
|
||||
menu.append(Step.LIBRARY_OPTIONS)
|
||||
menu.append(Step.ADVANCED_OPTIONS)
|
||||
menu.extend(self.build_virtual_power_menu())
|
||||
if self.selected_sensor_type == SensorType.DAILY_ENERGY:
|
||||
menu.append(Step.DAILY_ENERGY)
|
||||
if self.selected_sensor_type == SensorType.REAL_POWER:
|
||||
@@ -570,6 +567,32 @@ class PowercalcOptionsFlow(PowercalcCommonFlow, OptionsFlow):
|
||||
|
||||
return menu
|
||||
|
||||
def build_virtual_power_menu(self) -> list[Step]:
|
||||
"""Build the options menu entries specific to virtual power sensors."""
|
||||
menu: list[Step] = []
|
||||
if self.strategy and self.should_add_strategy_option_to_menu():
|
||||
menu.append(STRATEGY_STEP_MAPPING[self.strategy])
|
||||
if self.selected_profile:
|
||||
menu.append(Step.LIBRARY_OPTIONS)
|
||||
if self.should_add_select_device_to_menu():
|
||||
menu.append(Step.SELECT_DEVICE)
|
||||
menu.append(Step.ADVANCED_OPTIONS)
|
||||
return menu
|
||||
|
||||
def should_add_select_device_to_menu(self) -> bool:
|
||||
"""Check whether the device selection should be added to the menu."""
|
||||
if not self.selected_profile or self.selected_profile.discovery_by not in [
|
||||
DiscoveryBy.DEVICE,
|
||||
DiscoveryBy.CONFIG_ENTRY,
|
||||
]:
|
||||
return False
|
||||
|
||||
if self.selected_profile.discovery_by == DiscoveryBy.CONFIG_ENTRY:
|
||||
# Only devices of the source config entry are selectable, so there must be something to choose from.
|
||||
return len(self.flow_handlers[FlowType.LIBRARY].get_selectable_devices()) > 1
|
||||
|
||||
return True
|
||||
|
||||
def should_add_strategy_option_to_menu(self) -> bool:
|
||||
"""Check whether the strategy option should be added to the menu."""
|
||||
if not self.strategy or self.strategy not in STRATEGY_STEP_MAPPING:
|
||||
|
||||
Reference in New Issue
Block a user