Skip to content

Commit c8d882f

Browse files
committed
fix: correctness bugs
1 parent 3717d24 commit c8d882f

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

custom_components/powercalc/flow_helper/dynamic_field_builder.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@ def build_dynamic_field_schema(
2323
else:
2424
key = vol.Required(field.key, description=field_description)
2525

26+
field_selector = field.selector
2627
if "entity" in field.selector and source_entity and source_entity.device_entry:
2728
entity_reg = er.async_get(hass)
28-
field.selector["entity"]["include_entities"] = [
29-
entity.entity_id
30-
for entity in entity_reg.entities.get_entries_for_device_id(source_entity.device_entry.id)
31-
]
29+
# Build a new selector dict instead of mutating field.selector, which is a reference
30+
# into the (potentially cached) profile json_data.
31+
field_selector = {
32+
**field.selector,
33+
"entity": {
34+
**field.selector["entity"],
35+
"include_entities": [
36+
entity.entity_id
37+
for entity in entity_reg.entities.get_entries_for_device_id(source_entity.device_entry.id)
38+
],
39+
},
40+
}
3241

33-
schema[key] = selector(field.selector)
42+
schema[key] = selector(field_selector)
3443
return vol.Schema(schema)

custom_components/powercalc/sensors/group/config_entry_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def remove_power_sensor_from_associated_groups(
2828
group_entries = get_groups_having_member(hass, config_entry)
2929

3030
for group_entry in group_entries:
31-
member_sensors = group_entry.data.get(CONF_GROUP_MEMBER_SENSORS) or []
31+
# Copy the list so we don't mutate the config entry's data in place, which would make
32+
# async_update_entry's change detection see no change and skip persisting/reloading.
33+
member_sensors = list(group_entry.data.get(CONF_GROUP_MEMBER_SENSORS) or [])
3234
member_sensors.remove(config_entry.entry_id)
3335

3436
hass.config_entries.async_update_entry(

0 commit comments

Comments
 (0)