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

@ -2,7 +2,6 @@ package eebus
import (
"context"
"errors"
"sync"
"time"
@ -89,15 +88,16 @@ func NewFromConfig(ctx context.Context, other map[string]any, site site.API) (*E
// NewEEBus creates EEBus HEMS
func NewEEBus(ctx context.Context, ski string, limits Limits, passthrough func(bool) error, site site.API, interval time.Duration) (*EEBus, error) {
if eebus.Instance == nil {
return nil, errors.New("eebus not configured")
inst, err := eebus.Instance()
if err != nil {
return nil, err
}
c := &EEBus{
log: util.NewLogger("eebus"),
site: site,
passthrough: passthrough,
cs: eebus.Instance.ControllableSystem(),
cs: inst.ControllableSystem(),
Connector: eebus.NewConnector(),
heartbeat: util.NewValue[struct{}](2 * time.Minute), // LPC-031
interval: interval,
@ -111,12 +111,12 @@ func NewEEBus(ctx context.Context, ski string, limits Limits, passthrough func(b
// otherwise a heartbeat timeout is assumed when the state machine is called for the first time
c.heartbeat.Set(struct{}{})
if err := eebus.Instance.RegisterDevice(ski, "", c); err != nil {
if err := inst.RegisterDevice(ski, "", c); err != nil {
return nil, err
}
if err := c.Wait(ctx); err != nil {
eebus.Instance.UnregisterDevice(ski, c)
inst.UnregisterDevice(ski, c)
return nil, err
}