Repository navigation
Consumer: show values on connected phases of the EVU like counters - #4334
seaspotter wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/modules/common/store/_consumer.py" line_range="16-17" />
<code_context>
+ ab der gewählten Phase 1 haben Werte. Module liefern die Werte in der Reihenfolge der eigenen Phasen.
+ Module, die nur die Gesamtleistung liefern, bekommen von ConsumerState 230 V und 0 A/0 W auf allen drei
+ Phasen, diese werden zuerst auf die angeschlossenen Phasen verteilt."""
+ if any(values is not None and len(values) != 3 for values in (state.voltages, state.currents, state.powers)):
+ # nutzerdefinierte Module können Listen mit anderer Länge liefern, diese bleiben unverändert
+ return
+ if state.voltages == [230.0]*3:
</code_context>
<issue_to_address>
**Custom phase currents stay misaligned**
When a consumer reports a voltage list of unexpected length, valid three-element currents, and `phase_1` other than 1, a consumer with a non-three-element voltage list and valid three-element currents skips all phase conversion in `_to_evu_phases`. `_set_current_left` then treats those unconverted currents as EVU-phase values, so load management subtracts the consumer’s load from the wrong phases.
Convert each valid three-element phase array independently, leaving only malformed arrays unchanged.
Also at `packages/control/counter.py:216`.
</issue_to_address>
### Comment 2
<location path="packages/modules/common/store/_consumer.py" line_range="20-28" />
<code_context>
+ # nutzerdefinierte Module können Listen mit anderer Länge liefern, diese bleiben unverändert
+ return
+ if state.voltages == [230.0]*3:
+ state.voltages = [230.0 if i < connected_phases else 0.0 for i in range(3)]
+ if state.power and state.currents == [0.0]*3 and (state.powers is None or state.powers == [0.0]*3):
+ state.powers = [state.power / connected_phases if i < connected_phases else 0.0 for i in range(3)]
+ state.currents = [power / voltage if voltage else 0.0 for power, voltage in zip(state.powers, state.voltages)]
+ state.voltages = convert_cp_currents_to_evu_currents(phase_1, state.voltages)
+ if state.currents is not None:
+ state.currents = convert_cp_currents_to_evu_currents(phase_1, state.currents)
+ if state.powers is not None:
+ state.powers = convert_cp_currents_to_evu_currents(phase_1, state.powers)
+
+
</code_context>
<issue_to_address>
**Mixed phase values during publication**
When a module poll calls `set` while the publisher calls `update` on the same store, `ConsumerValueStoreBroker.set` exposes the state before `_to_evu_phases` finishes rewriting its arrays, so a concurrent `update` can publish unrotated or partially rotated voltages, currents, and powers as one measurement. The status page and load management then see inconsistent phases.
Transform a private copy before exposing it as `self.state`, and synchronize state replacement with publication.
</issue_to_address>
### Comment 3
<location path="packages/modules/common/store/_consumer.py" line_range="24-28" />
<code_context>
+ if state.power and state.currents == [0.0]*3 and (state.powers is None or state.powers == [0.0]*3):
+ state.powers = [state.power / connected_phases if i < connected_phases else 0.0 for i in range(3)]
+ state.currents = [power / voltage if voltage else 0.0 for power, voltage in zip(state.powers, state.voltages)]
+ state.voltages = convert_cp_currents_to_evu_currents(phase_1, state.voltages)
+ if state.currents is not None:
+ state.currents = convert_cp_currents_to_evu_currents(phase_1, state.currents)
+ if state.powers is not None:
+ state.powers = convert_cp_currents_to_evu_currents(phase_1, state.powers)
+
+
</code_context>
<issue_to_address>
**Disconnected phases show phantom load**
When a consumer module supplies readings on phases beyond its configured connected-phase count, `_to_evu_phases` rotates module-provided arrays but does not clear readings beyond `connected_phases`, so `ConsumerValueStoreBroker.update` publishes values on disconnected phases and the status page shows phantom load.
Clear entries beyond `connected_phases` in every module-provided per-phase array before publishing.
</issue_to_address>
### Comment 4
<location path="packages/modules/common/store/_consumer.py" line_range="20" />
<code_context>
+ # nutzerdefinierte Module können Listen mit anderer Länge liefern, diese bleiben unverändert
+ return
+ if state.voltages == [230.0]*3:
+ state.voltages = [230.0 if i < connected_phases else 0.0 for i in range(3)]
+ if state.power and state.currents == [0.0]*3 and (state.powers is None or state.powers == [0.0]*3):
+ state.powers = [state.power / connected_phases if i < connected_phases else 0.0 for i in range(3)]
</code_context>
<issue_to_address>
**Unknown phase loses voltages**
When a consumer has `phase_1=0` and default voltages, `phase_1` is 0, so `_to_evu_phases` first replaces the default voltages with `[230, 0, 0]`, then phase conversion raises `KeyError` and `set` swallows it. The state is published with altered voltages instead of the unchanged values expected for an unknown phase.
Validate `phase_1` before mutating the state, or restore the original values if phase conversion fails.
</issue_to_address>
LKuemmel
left a comment
There was a problem hiding this comment.
Die Drehung der Phasen beim Publishen soll nicht verändert werden. Die Drehung erfolgt nur im Lastmanagement, die Werte selbst werden so gepublished wie sie am Gerät oder Ladepunkt ausgelesen werden, also immer auf Phase 1.
| state.powers = [state.power / connected_phases if i < connected_phases else 0.0 for i in range(3)] | ||
| state.currents = [power / voltage if voltage else 0.0 for power, voltage in zip(state.powers, state.voltages)] |
There was a problem hiding this comment.
Das wird aktuell in der consumers.py gemacht, aber nicht gepublished. Inhaltlich gehört die Änderung in die ConsumerState-Klasse, wo bisher nur die Phasenwerte ggf berechnet werden, aber nicht anhand der Gesamtleistung. Dann sind alle Berechnungen an einem Ort.
Die Berechnung in der consumers.py kann dann entfallen.
There was a problem hiding this comment.
Umgesetzt: Drehung beim Publishen entfernt (Lastmanagement unverändert), Verteilung der Gesamtleistung jetzt in ConsumerState.distribute_total_power, Berechnung in consumer.py entfällt. Da ConsumerState connected_phases nicht kennt, ruft der Store die Methode mit dem Wert aus der Konfiguration auf, statt allen ~30 Modulen einen Parameter mitzugeben. Falls Du es anders möchtest, sag Bescheid
Verbraucher, deren Modul nur die Gesamtleistung liefert (z. B. my-PV AC•THOR), zeigten auf der Statusseite immer 230 V / 0 A / 0 kW auf allen drei Phasen, unabhängig von "Anzahl angeschlossener Phasen" und "Phase 1 des Verbraucheranschlusses".
Änderungen
Summary by Sourcery
Publish consumer and Tasmota measurements only on the phases where they are connected or measured.
New Features:
Bug Fixes:
Tests: