From 346c818c5deaec02478a0aa375dbe18a2a86b707 Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 27 Jul 2022 21:41:34 +0200 Subject: [PATCH] OpenWB: add CP interrupt (#3968) --- charger/openwb.go | 18 ++++++++++++++++++ charger/openwb/topics.go | 1 + 2 files changed, 19 insertions(+) diff --git a/charger/openwb.go b/charger/openwb.go index 85753496b..8c3b321f3 100644 --- a/charger/openwb.go +++ b/charger/openwb.go @@ -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) +} diff --git a/charger/openwb/topics.go b/charger/openwb/topics.go index d23370580..d80c10a5e 100644 --- a/charger/openwb/topics.go +++ b/charger/openwb/topics.go @@ -57,4 +57,5 @@ const ( SlaveChargeCurrentTopic = "Current" SlavePhasesTopic = "U1p3p" SlaveClearRfidTopic = "ClearRfid" + SlaveCPInterruptTopic = "Cpulp1" )