Skip to content

Fix: evse_current in Evse.__init__ initialisieren#3327

Open
s0170071 wants to merge 1 commit intoopenWB:masterfrom
s0170071:fix/evse-current-init
Open

Fix: evse_current in Evse.__init__ initialisieren#3327
s0170071 wants to merge 1 commit intoopenWB:masterfrom
s0170071:fix/evse-current-init

Conversation

@s0170071
Copy link
Copy Markdown

@s0170071 s0170071 commented Apr 25, 2026

Problem

Das Attribut self.evse_current wird in Evse.__init__ nicht initialisiert. Es wird erst beim ersten Aufruf von get_plug_charge_state() gesetzt (Zeile 55).

set_current() liest self.evse_current jedoch direkt in seiner Guard-Bedingung:

if self.evse_current != formatted_current:

Wird set_current() aufgerufen, bevor get_plug_charge_state() mindestens einmal gelaufen ist, kommt es zu einem AttributeError.

Auswirkung

Der Ladevorgang kann nicht gestartet werden, wenn die Steuerungsschleife set_current() vor dem ersten State-Polling aufruft. Das ist z.B. möglich, wenn direkt nach der Initialisierung ein Strom gesetzt werden soll.

Lösung

self.evse_current = 0 wird am Ende von __init__ gesetzt. Der Wert 0 sorgt dafür, dass der erste set_current()-Aufruf immer einen Modbus-Write auslöst (es sei denn, der Sollstrom ist ebenfalls 0 — in dem Fall ist kein Write nötig).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an AttributeError in the EVSE Modbus client by ensuring Evse.evse_current is initialized during construction, so set_current() can be called safely before the first state poll.

Changes:

  • Initialize self.evse_current to 0 in Evse.__init__ to prevent access to an unset attribute in set_current().

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

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.

3 participants