Skip to content

fix command timing problem - #3271

Merged
LKuemmel merged 3 commits into
openWB:masterfrom
LKuemmel:fix_command
Jun 10, 2026
Merged

LKuemmel merged 3 commits into
openWB:masterfrom
LKuemmel:fix_command

Conversation

@LKuemmel

@LKuemmel LKuemmel commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor
  • Ladepunkt zur leeren Hierarchie hinzufügen (Fehlermeldung)
  • Ladepunkt zur Hierarchie hinzufügen
  • Ladepunkt aus Hierarchie löschen
  • Ladepunkt-Vorlage kopieren
  • Ladepunkt-Vorlage mit Autolock-Plänen kopieren
  • kopierte Ladepunkt-Vorlage mit Autolock-Plänen kopieren
  • Autolock-Plan hinzufügen
  • Autolock-Plan kopieren
  • Autolock-Plan löschen
  • Ladeprofil kopieren
  • Ziellade-Plan in Einstellungsseite hinzufügen
  • Ziellade-Plan in Theme hinzufügen
  • Zähler zur leeren Hierarchie hinzufügen
  • Zähler zur Hierarchie hinzufügen
  • Zähler aus Hierarchie löschen
  • Fahrzeug-Profil kopieren

@LKuemmel LKuemmel mentioned this pull request Apr 7, 2026
@LKuemmel
LKuemmel marked this pull request as draft April 8, 2026 07:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the command handling to avoid timing/staleness issues by reading and mutating the live SubData structures (instead of control.data.data) when creating/removing hierarchy items and when copying templates/plans.

Changes:

  • Switch multiple command paths from data.data.* to SubData.* (hierarchy, chargepoint templates, EV templates, charge templates).
  • Adjust chargepoint-template copy behavior to reassign autolock plan IDs and publish an updated autolock max-id.
  • Update charge-template source resolution when changes come from the theme (chargepoint-local template vs persistent vehicle template).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/helpermodules/command.py Outdated
SubData.cp_template_data[f'cpt{payload["data"]["template"]}'].data.autolock.plans.remove(plan)
break
Pub().pub(
f'openWB/chargepoint/template/{payload["data"]["template"]}',

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This publishes the updated template to openWB/chargepoint/template/<id> (without the set/ prefix), while other mutations (e.g. addAutolockPlan, addChargepointTemplate) publish to openWB/set/chargepoint/template/<id>. If openWB/set/... is the intended write-path, this will bypass it and may not persist/update consistently; publish to the same openWB/set/chargepoint/template/<id> topic here as well.

Suggested change
f'openWB/chargepoint/template/{payload["data"]["template"]}',
f'openWB/set/chargepoint/template/{payload["data"]["template"]}',

Copilot uses AI. Check for mistakes.
Comment on lines 492 to 498
self.max_id_charge_template = new_id
# check if "payload" contains "data.copy"
if "data" in payload and "copy" in payload["data"]:
new_charge_template = copy.deepcopy(data.data.ev_charge_template_data[f'ct{payload["data"]["copy"]}'].data)
new_charge_template = copy.deepcopy(SubData.ev_charge_template_data[f'ct{payload["data"]["copy"]}'].data)
new_charge_template.name = f'Kopie von {new_charge_template.name}'
for plan in new_charge_template.chargemode.scheduled_charging.plans:
plan.id = self.max_id_charge_template_scheduled_plan + 1

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When copying a charge template, the code updates plan.id values by incrementing self.max_id_charge_template_scheduled_plan / self.max_id_charge_template_time_charging_plan, but later publishes the broker topics openWB/set/command/max_id/charge_template_scheduled_plan and .../charge_template_time_charging_plan with new_id (the charge template id). This desynchronizes the max-id topics from the actual plan ids and can lead to id collisions when creating the next plan; publish the updated plan max-ids instead.

Copilot uses AI. Check for mistakes.
Comment thread packages/helpermodules/command.py Outdated
ProcessBrokerBranch(f'chargepoint/{cp_id}/').remove_topics()
data.data.counter_all_data.hierarchy_remove_item(cp_id, ComponentType.CHARGEPOINT)
Pub().pub("openWB/set/counter/get/hierarchy", data.data.counter_all_data.data.get.hierarchy)
SubData.counter_all_data.hierarchy_remove_item(cp_id, ComponentType.CHARGEPOINT)

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hierarchy_remove_item is defined as (id_to_find: int, keep_children: bool = True), but this call passes ComponentType.CHARGEPOINT as the second argument. That works only incidentally (truthy enum) and is misleading; pass an explicit boolean (or omit the second argument to use the default).

Suggested change
SubData.counter_all_data.hierarchy_remove_item(cp_id, ComponentType.CHARGEPOINT)
SubData.counter_all_data.hierarchy_remove_item(cp_id, True)

Copilot uses AI. Check for mistakes.
Comment on lines +409 to +414
# if copying a template, increase id of autolock plans
if "data" in payload and "copy" in payload["data"]:
for plan in new_chargepoint_template["autolock"]["plans"]:
plan["id"] = self.max_id_autolock_plan + 1
self.max_id_autolock_plan += 1
Pub().pub("openWB/set/command/max_id/autolock_plan", self.max_id_autolock_plan)

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new copy-path mutates autolock plan IDs and publishes an updated max_id/autolock_plan. There’s existing pytest coverage for Command (see packages/helpermodules/command_test.py), but no test currently exercises this copy behavior; adding a unit test for addChargepointTemplate that asserts (1) copied plans get new unique IDs and (2) the published max-id matches the highest assigned plan id would help prevent regressions.

Copilot uses AI. Check for mistakes.
@LKuemmel
LKuemmel marked this pull request as ready for review April 9, 2026 06:28
@LKuemmel LKuemmel added this to the 2.2.1 milestone May 19, 2026
@LKuemmel
LKuemmel merged commit 488fb0f into openWB:master Jun 10, 2026
1 check passed
@LKuemmel
LKuemmel deleted the fix_command branch June 10, 2026 10:45
ndrsnhs pushed a commit to ndrsnhs/core that referenced this pull request Aug 24, 2026
* fix timing problem

* review

* flake8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants