WARP1: don't report zero phase currents on power-only meters (#32090)

This commit is contained in:
andig 2026-07-23 17:26:14 +02:00 • committed by GitHub
parent 02a66252ca
commit 2b7aaeaa37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 10 deletions

View file

@ -49,8 +49,9 @@ type WarpWS struct {
maxCurrent int64 // input from evcc
// meter
meter warp.MeterValues
meterMap map[int]int
meter warp.MeterValues
meterMap map[int]int
hasCurrents, hasVoltages bool // meter actually reports per-phase currents/voltages
// nfc
chargeTracker warp.ChargeTrackerCurrentCharge
@ -307,10 +308,11 @@ func (w *WarpWS) handleEvent(topic string, payload json.RawMessage) error {
if !w.hasFeature(warp.FeatureMeterAllValues) || w.hasFeature(warp.FeatureMeters) {
return nil
}
err = json.Unmarshal(payload, &w.meter.TmpValues)
if len(w.meter.TmpValues) > 5 {
copy(w.meter.Voltages[:], w.meter.TmpValues[:3])
copy(w.meter.Currents[:], w.meter.TmpValues[3:6])
var values []float64
if err = json.Unmarshal(payload, &values); err == nil && len(values) > 5 {
copy(w.meter.Voltages[:], values[:3])
copy(w.meter.Currents[:], values[3:6])
w.hasVoltages, w.hasCurrents = true, true
}
case "meter/values":
if !w.hasFeature(warp.FeatureMeter) || w.hasFeature(warp.FeatureMeters) {
@ -327,13 +329,14 @@ func (w *WarpWS) handleEvent(topic string, payload json.RawMessage) error {
w.meterMap[id] = i
}
case metersValuesTopic:
if err := json.Unmarshal(payload, &w.meter.TmpValues); err != nil {
var values []float64
if err := json.Unmarshal(payload, &values); err != nil {
return err
}
get := func(id int) (float64, bool) {
if idx, ok := w.meterMap[id]; ok && idx < len(w.meter.TmpValues) {
return w.meter.TmpValues[idx], true
if idx, ok := w.meterMap[id]; ok && idx < len(values) {
return values[idx], true
}
return 0, false
}
@ -348,9 +351,11 @@ func (w *WarpWS) handleEvent(topic string, payload json.RawMessage) error {
for p, ids := range s.Phases {
if v, ok := get(ids.CurrentID); ok {
w.meter.Currents[p] = v
w.hasCurrents = true
}
if v, ok := get(ids.VoltageID); ok {
w.meter.Voltages[p] = v
w.hasVoltages = true
}
}
case "power_manager/state":
@ -435,12 +440,18 @@ func (w *WarpWS) totalEnergy() (float64, error) {
func (w *WarpWS) currents() (float64, float64, float64, error) {
w.mu.RLock()
defer w.mu.RUnlock()
if !w.hasCurrents {
return 0, 0, 0, api.ErrNotAvailable
}
return w.meter.Currents[0], w.meter.Currents[1], w.meter.Currents[2], nil
}
func (w *WarpWS) voltages() (float64, float64, float64, error) {
w.mu.RLock()
defer w.mu.RUnlock()
if !w.hasVoltages {
return 0, 0, 0, api.ErrNotAvailable
}
return w.meter.Voltages[0], w.meter.Voltages[1], w.meter.Voltages[2], nil
}

View file

@ -36,7 +36,6 @@ type MeterValues struct {
EnergyAbs float64 `json:"energy_abs"`
Currents [3]float64
Voltages [3]float64
TmpValues []float64
}
type Name struct {