OCPP/EEBus: lazy-start servers so the CLI works against a running evcc (#30839)

Co-authored-by: Michael Geers <michael@geers.tv>
This commit is contained in:
andig 2026-06-25 17:26:08 +02:00 • committed by GitHub
parent 518556e6b8
commit fc84062905
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 237 additions and 159 deletions

View file

@ -200,28 +200,39 @@ func runRoot(cmd *cobra.Command, args []string) {
valueChan := make(chan util.Param, 64)
go tee.Run(valueChan)
// start OCPP server
ocppCS := ocpp.Instance()
ocppCS.SetUpdated(func() {
// republish when OCPP state updates
valueChan <- util.Param{Key: keys.Ocpp, Val: globalconfig.ConfigStatus{
Config: ocpp.CurrentConfig(),
Status: ocpp.GetStatus(),
}}
})
log.INFO.Printf("OCPP local url: ws://127.0.0.1:%d/<stationId>", conf.Ocpp.Port)
if ocpp.ExternalUrl() != "" {
log.INFO.Printf("OCPP external url: %s/<stationId>", ocpp.ExternalUrl())
}
// register the callback even with no rules so runtime additions are pushed
ocpp.SetForwarderUpdated(func() {
valueChan <- util.Param{Key: keys.OcppForwarder, Val: globalconfig.ConfigStatus{
Config: lo.Map(ocpp.ForwarderRules(), func(r ocpp.ForwarderRule, _ int) ocpp.ForwarderRule { return r.Redacted() }),
Status: ocpp.GetForwarderStatus(),
}}
})
if ocpp.ForwarderEnabled() {
log.INFO.Printf("OCPP forwarder: %d rule(s) active", len(ocpp.ForwarderRules()))
// start OCPP and EEBus servers (skipped in degraded mode where setup failed,
// so a misconfigured instance serves only the offline UI)
if err == nil {
cs, ocppErr := ocpp.Instance()
if ocppErr != nil {
log.ERROR.Println("ocpp:", ocppErr)
} else {
cs.SetUpdated(func() {
// republish when OCPP state updates
valueChan <- util.Param{Key: keys.Ocpp, Val: globalconfig.ConfigStatus{
Config: ocpp.CurrentConfig(),
Status: ocpp.GetStatus(),
}}
})
log.INFO.Printf("OCPP local url: ws://127.0.0.1:%d/<stationId>", conf.Ocpp.Port)
if ocpp.ExternalUrl() != "" {
log.INFO.Printf("OCPP external url: %s/<stationId>", ocpp.ExternalUrl())
}
}
// register the callback even with no rules so runtime additions are pushed
ocpp.SetForwarderUpdated(func() {
valueChan <- util.Param{Key: keys.OcppForwarder, Val: globalconfig.ConfigStatus{
Config: lo.Map(ocpp.ForwarderRules(), func(r ocpp.ForwarderRule, _ int) ocpp.ForwarderRule { return r.Redacted() }),
Status: ocpp.GetForwarderStatus(),
}}
})
if ocpp.ForwarderEnabled() {
log.INFO.Printf("OCPP forwarder: %d rule(s) active", len(ocpp.ForwarderRules()))
}
if _, eebusErr := eebus.Instance(); eebusErr != nil {
log.ERROR.Println("eebus:", eebusErr)
}
}
// value cache