OpenWB: add CP interrupt (#3968)

This commit is contained in:
andig 2022-07-27 21:41:34 +02:00 • committed by GitHub
parent abf4f76568
commit 346c818c5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package charger
import (
"fmt"
"strings"
"time"
"github.com/evcc-io/evcc/api"
@ -24,6 +25,7 @@ type OpenWB struct {
currentPowerG func() (float64, error)
totalEnergyG func() (float64, error)
currentsG []func() (float64, error)
wakeupS func(int64) error
authS func(string) error
}
@ -95,6 +97,14 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
currentS := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, currentTopic),
timeout).WithRetained().IntSetter("current")
cpTopic := openwb.SlaveCPInterruptTopic
if id == 2 {
// TODO remove after https://github.com/snaptec/openWB/issues/1757
cpTopic = strings.TrimSuffix(cpTopic, "1") + "2"
}
wakeupS := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%d/get/%s", topic, id, cpTopic),
timeout).WithRetained().IntSetter("cp")
authS := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/chargepoint/%d/get/%s", topic, id, openwb.RfidTopic),
timeout).WithRetained().StringSetter("rfid")
@ -115,6 +125,7 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
currentPowerG: currentPowerG,
totalEnergyG: totalEnergyG,
currentsG: currentsG,
wakeupS: wakeupS,
authS: authS,
}
@ -222,3 +233,10 @@ var _ api.Authorizer = (*OpenWB)(nil)
func (m *OpenWB) Authorize(key string) error {
return m.authS(key)
}
var _ api.AlarmClock = (*OpenWB)(nil)
// WakeUp implements the api.AlarmClock interface
func (m *OpenWB) WakeUp() error {
return m.wakeupS(1)
}

View file

@ -57,4 +57,5 @@ const (
SlaveChargeCurrentTopic = "Current"
SlavePhasesTopic = "U1p3p"
SlaveClearRfidTopic = "ClearRfid"
SlaveCPInterruptTopic = "Cpulp1"
)