Skip to content

Commit

Permalink
feat: remove unique_id from config_flow
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Nov 23, 2024
1 parent 852f0dc commit 1172e22
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 29 deletions.
4 changes: 0 additions & 4 deletions custom_components/powercalc/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
from .power_profile.library import ModelInfo, ProfileLibrary
from .power_profile.power_profile import DOMAIN_DEVICE_TYPE, DeviceType, PowerProfile
from .sensors.daily_energy import DEFAULT_DAILY_UPDATE_FREQUENCY
from .sensors.group.factory import generate_unique_id
from .strategy.factory import PowerCalculatorStrategyFactory
from .strategy.wled import CONFIG_SCHEMA as SCHEMA_POWER_WLED

Expand Down Expand Up @@ -1381,9 +1380,6 @@ async def async_step_subtract_group(self, user_input: dict[str, Any] | None = No
async def async_handle_group_creation(self) -> FlowResult:
"""Handle the group creation."""
self.selected_sensor_type = SensorType.GROUP
unique_id = generate_unique_id(self.sensor_config)
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured()

if self.sensor_config.get(CONF_CREATE_UTILITY_METERS):
return await self.async_step_utility_meter_options()
Expand Down
15 changes: 0 additions & 15 deletions custom_components/powercalc/sensors/group/factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_UNIQUE_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import ConfigType
Expand Down Expand Up @@ -48,17 +47,3 @@ async def create_group_sensors(
)

raise SensorConfigurationError(f"Group type {group_type} invalid") # pragma: no cover


def generate_unique_id(sensor_config: ConfigType) -> str:
"""Generate a unique ID for a group sensor."""
if CONF_UNIQUE_ID in sensor_config:
return str(sensor_config[CONF_UNIQUE_ID])

group_type: GroupType = sensor_config.get(CONF_GROUP_TYPE, GroupType.CUSTOM)
if group_type == GroupType.DOMAIN:
return domain_group.generate_unique_id(sensor_config)
if group_type == GroupType.SUBTRACT:
return subtract_group.generate_unique_id(sensor_config)

return custom_group.generate_unique_id(sensor_config)
11 changes: 3 additions & 8 deletions custom_components/powercalc/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"name": "Name",
"on_time": "On time",
"start_time": "Start time",
"unique_id": "Unique id",
"unit_of_measurement": "Unit of measurement",
"update_frequency": "Update frequency",
"value": "Value",
Expand Down Expand Up @@ -123,8 +122,7 @@
"hide_members": "Hide members",
"include_non_powercalc_sensors": "Include non powercalc sensors",
"name": "Name",
"sub_groups": "Sub groups",
"unique_id": "Unique id"
"sub_groups": "Sub groups"
},
"data_description": {
"area": "Adds all power sensors from the specified area",
Expand Down Expand Up @@ -263,7 +261,6 @@
"create_utility_meters": "Create utility meters",
"entity_id": "Base entity",
"name": "Name",
"unique_id": "Unique id",
"subtract_entities": "Subtract entities"
},
"data_description": {
Expand Down Expand Up @@ -326,17 +323,15 @@
"group": "Add to group",
"mode": "Calculation strategy",
"name": "Name",
"standby_power": "Standby power",
"unique_id": "Unique id"
"standby_power": "Standby power"
},
"data_description": {
"create_energy_sensor": "Whether powercalc needs to create a kWh sensor",
"create_utility_meters": "Let powercalc create utility meters, which cycle daily, hourly etc.",
"entity_id": "entity the virtual power is based on, the power sensor will listen to state changes of this entity to be updated",
"group": "Fill in a custom group name to create a new group",
"name": "Leaving blank will take the name from the source entity",
"standby_power": "Define the amount of power the device is consuming when in an OFF state",
"unique_id": "Specify a unique_id. This will allow to setup multiple power sensors for the same entity. When not specified it will take the unique_id of the source entity"
"standby_power": "Define the amount of power the device is consuming when in an OFF state"
},
"description": "See the readme for more information about the possible strategies and configuration options. Either source entity or name is required, or both.",
"title": "Create a virtual power sensor"
Expand Down
2 changes: 0 additions & 2 deletions tests/config_flow/test_group_subtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ async def test_subtract_group_flow(hass: HomeAssistant) -> None:
user_input,
)
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
config_entry: ConfigEntry = result["result"]
assert config_entry.unique_id == "pc_subtract_sensor.outlet_power"
assert result["data"] == {
CONF_SENSOR_TYPE: SensorType.GROUP,
CONF_GROUP_TYPE: GroupType.SUBTRACT,
Expand Down

0 comments on commit 1172e22

Please sign in to comment.