Repository navigation
Conversation
…, Prioritätensteuerung-Korrektur
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/control/counter_all/loadmanagement_prio.py" line_range="26-27" />
<code_context>
+ },
+ }
+
+ self._remove_obsolete_entries(self.data.get.loadmanagement_prios, valid_ids)
+ self._add_missing_entries(self.data.get.loadmanagement_prios, valid_ids)
+
+ except Exception:
</code_context>
<issue_to_address>
**Priority repairs are discarded**
When periodic validation adds or removes a priority entry, `validate_loadmanagement_prios()` changes only the copied priority list without publishing it to `SubData`; the next `copy_data()` reloads the stale list, so callers keep seeing old priorities and the repairs are lost.
Publish the updated priority list to `SubData` whenever validation changes it.
Also at `packages/control/counter_all/loadmanagement_prio.py:43`, `packages/control/counter_all/loadmanagement_prio.py:53`, `packages/main.py:195`.
</issue_to_address>
### Comment 2
<location path="packages/control/counter_all/loadmanagement_prio.py" line_range="37" />
<code_context>
+ if entry["type"] == "group":
+ children = entry["children"]
+ had_children = bool(children)
+ self._remove_obsolete_entries(children)
+ if had_children and not children:
+ entries.remove(entry)
</code_context>
<issue_to_address>
**Groups stop priority validation**
When the priority list contains a group, `_remove_obsolete_entries()` requires `valid_ids`, but the recursive call omits it and raises `TypeError`; `validate_loadmanagement_prios()` catches the exception and exits before completing cleanup or adding missing entries, leaving the list unsynchronized.
Pass `valid_ids` to the recursive `_remove_obsolete_entries()` call.
</issue_to_address>
### Comment 3
<location path="packages/main.py" line_range="195" />
<code_context>
data.data.general_data.grid_protection()
data.data.optional_data.ocpp_transfer_meter_values()
data.data.counter_all_data.validate_hierarchy()
+ data.data.counter_all_data.validate_loadmanagement_prios()
data.data.optional_data.remove_outdated_prices()
loadvars_.ep_get_prices()
</code_context>
<issue_to_address>
**Transient copy failures erase priority groups**
When a transient copy error leaves either component dictionary incomplete during the five-minute handler, `copy_data()` can leave `ev_data` or `consumer_data` partially populated after logging and swallowing a copy exception; validation then removes entries it cannot see and deletes groups that become empty. When the data recovers, missing entries are appended flat, so users lose their configured priority grouping.
Make data copying atomic or return a success status, and skip priority validation unless the component snapshot completed successfully.
</issue_to_address>
### Comment 4
<location path="packages/control/counter_all/loadmanagement_prio.py" line_range="19-21" />
<code_context>
+ def validate_loadmanagement_prios(self: LoadmanagementPrioProtocol) -> None:
+ try:
+ valid_ids = {
+ ComponentType.VEHICLE: {vehicle.num for vehicle in data.data.ev_data.values()},
+ ComponentType.CONSUMER: {
+ consumer.num for consumer in data.data.consumer_data.values()
+ if consumer.data.usage.type not in NOT_CONTROLLED
+ },
</code_context>
<issue_to_address>
**New priorities get arbitrary order**
When multiple valid IDs are missing from the list, `_add_missing_entries` iterates these sets and appends each missing item to the priority list, so newly discovered vehicles and consumers receive an order unrelated to their source order; that list order determines charging priority, so users can see unexpected prioritization.
Preserve a defined order for IDs (for example, source order or sorted IDs) when adding missing entries.
</issue_to_address>
### Comment 5
<location path="packages/control/counter_all/loadmanagement_prio.py" line_range="36-39" />
<code_context>
+ for entry in entries.copy():
+ if entry["type"] == "group":
+ children = entry["children"]
+ had_children = bool(children)
+ self._remove_obsolete_entries(children)
+ if had_children and not children:
+ entries.remove(entry)
+ else:
+ for type_name, ids in valid_ids.items():
</code_context>
<issue_to_address>
**Empty priority groups remain**
When the priority list contains an empty group before validation, or a nested empty group, `_remove_obsolete_entries` skips removal when a group starts empty, so pre-existing empty groups—and empty nested groups—remain in the priority list after validation and are still shown to callers.
Remove a group whenever its children are empty after recursive cleanup, including when it was empty before validation.
</issue_to_address>| self._remove_obsolete_entries(self.data.get.loadmanagement_prios, valid_ids) | ||
| self._add_missing_entries(self.data.get.loadmanagement_prios, valid_ids) |
There was a problem hiding this comment.
🟠 High · Priority repairs are discarded
When periodic validation adds or removes a priority entry, validate_loadmanagement_prios() changes only the copied priority list without publishing it to SubData; the next copy_data() reloads the stale list, so callers keep seeing old priorities and the repairs are lost.
Publish the updated priority list to SubData whenever validation changes it.
Also at packages/control/counter_all/loadmanagement_prio.py:43, packages/control/counter_all/loadmanagement_prio.py:53, packages/main.py:195.
Prompt for AI agents
In `packages/control/counter_all/loadmanagement_prio.py` at lines 26-27:
**Priority repairs are discarded**
When periodic validation adds or removes a priority entry, `validate_loadmanagement_prios()` changes only the copied priority list without publishing it to `SubData`; the next `copy_data()` reloads the stale list, so callers keep seeing old priorities and the repairs are lost.
Publish the updated priority list to `SubData` whenever validation changes it.
Also at `packages/control/counter_all/loadmanagement_prio.py:43`, `packages/control/counter_all/loadmanagement_prio.py:53`, `packages/main.py:195`.| data.data.general_data.grid_protection() | ||
| data.data.optional_data.ocpp_transfer_meter_values() | ||
| data.data.counter_all_data.validate_hierarchy() | ||
| data.data.counter_all_data.validate_loadmanagement_prios() |
There was a problem hiding this comment.
🟡 Medium · Transient copy failures erase priority groups
When a transient copy error leaves either component dictionary incomplete during the five-minute handler, copy_data() can leave ev_data or consumer_data partially populated after logging and swallowing a copy exception; validation then removes entries it cannot see and deletes groups that become empty. When the data recovers, missing entries are appended flat, so users lose their configured priority grouping.
Make data copying atomic or return a success status, and skip priority validation unless the component snapshot completed successfully.
Prompt for AI agents
In `packages/main.py` at line 195:
**Transient copy failures erase priority groups**
When a transient copy error leaves either component dictionary incomplete during the five-minute handler, `copy_data()` can leave `ev_data` or `consumer_data` partially populated after logging and swallowing a copy exception; validation then removes entries it cannot see and deletes groups that become empty. When the data recovers, missing entries are appended flat, so users lose their configured priority grouping.
Make data copying atomic or return a success status, and skip priority validation unless the component snapshot completed successfully.| ComponentType.VEHICLE: {vehicle.num for vehicle in data.data.ev_data.values()}, | ||
| ComponentType.CONSUMER: { | ||
| consumer.num for consumer in data.data.consumer_data.values() |
There was a problem hiding this comment.
🟡 Medium · New priorities get arbitrary order
When multiple valid IDs are missing from the list, _add_missing_entries iterates these sets and appends each missing item to the priority list, so newly discovered vehicles and consumers receive an order unrelated to their source order; that list order determines charging priority, so users can see unexpected prioritization.
Preserve a defined order for IDs (for example, source order or sorted IDs) when adding missing entries.
Prompt for AI agents
In `packages/control/counter_all/loadmanagement_prio.py` at lines 19-21:
**New priorities get arbitrary order**
When multiple valid IDs are missing from the list, `_add_missing_entries` iterates these sets and appends each missing item to the priority list, so newly discovered vehicles and consumers receive an order unrelated to their source order; that list order determines charging priority, so users can see unexpected prioritization.
Preserve a defined order for IDs (for example, source order or sorted IDs) when adding missing entries.| had_children = bool(children) | ||
| self._remove_obsolete_entries(children) | ||
| if had_children and not children: | ||
| entries.remove(entry) |
There was a problem hiding this comment.
⚪ Low · Empty priority groups remain
When the priority list contains an empty group before validation, or a nested empty group, _remove_obsolete_entries skips removal when a group starts empty, so pre-existing empty groups—and empty nested groups—remain in the priority list after validation and are still shown to callers.
Remove a group whenever its children are empty after recursive cleanup, including when it was empty before validation.
Prompt for AI agents
In `packages/control/counter_all/loadmanagement_prio.py` at lines 36-39:
**Empty priority groups remain**
When the priority list contains an empty group before validation, or a nested empty group, `_remove_obsolete_entries` skips removal when a group starts empty, so pre-existing empty groups—and empty nested groups—remain in the priority list after validation and are still shown to callers.
Remove a group whenever its children are empty after recursive cleanup, including when it was empty before validation.There was a problem hiding this comment.
🟡 Changes recommended
Active moderate and critical findings remain in the priority-list cleanup and ordering logic, leaving obsolete groups and making restored priorities nondeterministic.
2 open issues
What changed in this PR
This PR synchronizes load-management priorities with currently valid and controllable vehicles and consumers, including automatic cleanup and restoration during the five-minute control cycle.
Changes:
- Validates priorities periodically and removes obsolete or non-controllable entries.
- Restores missing entries for valid controllable vehicles and consumers.
- Corrects consumer creation handling and adds coverage for priority synchronization and usage types.
| File | Description |
|---|---|
| packages/main.py | Runs load-management priority validation during the five-minute control cycle. |
| packages/helpermodules/command.py | Uses the consumer's default usage type when updating priorities during creation. |
| packages/helpermodules/command_test.py | Tests priority behavior for all consumer usage types. |
| packages/control/counter_all/loadmanagement_prio.py | Implements priority validation, cleanup, restoration, and consumer usage updates. |
| packages/control/counter_all/loadmanagement_prio_test.py | Adds test coverage for priority synchronization, cleanup, grouping, and consumer priority updates. |
| packages/control/counter_all/counter_all_data.py | Extends the priority-management protocol with validation helper methods. |
Review effort: Lite
| for type_name, ids in valid_ids.items(): | ||
| for id in ids: | ||
| if not self._has_loadmanagement_prio_item(type_name, id, entries): | ||
| self.add_loadmanagement_prio_item(type_name, id) |
There was a problem hiding this comment.
Reihenfolge muss der Kunde sowieso nach seinen Wünschen anpassen, er bekommt eine Meldung dazu.
| had_children = bool(children) | ||
| self._remove_obsolete_loadmanagement_prio_entries(children, valid_ids) | ||
| if had_children and not children: | ||
| entries.remove(entry) |
There was a problem hiding this comment.
Gewollt, könnte ein Platzhalter sein.


Summary by Sourcery
Keep priority control synchronized with configured, controllable vehicles and consumers.
New Features:
Bug Fixes:
Enhancements:
Tests: