File tree Expand file tree Collapse file tree
custom_components/powercalc Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments