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:
parent
518556e6b8
commit
fc84062905
23 changed files with 237 additions and 159 deletions
16
cmd/setup.go
16
cmd/setup.go
|
|
@ -853,11 +853,16 @@ func configureOCPP(cfg *ocpp.Config, externalUrl string) {
|
|||
log.WARN.Printf("ocpp: failed to load settings: %v", err)
|
||||
}
|
||||
}
|
||||
ocpp.Init(*cfg, externalUrl)
|
||||
ocpp.NewServer(*cfg, externalUrl)
|
||||
|
||||
// Load proxy forwarding rules from DB if present.
|
||||
var rules []ocpp.ForwarderRule
|
||||
if err := settings.Json(keys.OcppForwarder, &rules); err == nil {
|
||||
if err := settings.Json(keys.OcppForwarder, &rules); err == nil && len(rules) > 0 {
|
||||
// the forwarder relays through the central system; abort if it failed to start
|
||||
if _, err := ocpp.Instance(); err != nil {
|
||||
log.ERROR.Printf("ocpp: forwarder disabled: %v", err)
|
||||
return
|
||||
}
|
||||
ocpp.ApplyForwarderRules(rules)
|
||||
}
|
||||
}
|
||||
|
|
@ -885,13 +890,12 @@ func configureEEBus(conf *eebus.Config) error {
|
|||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
if eebus.Instance, err = eebus.NewServer(*conf); err != nil {
|
||||
srv, err := eebus.NewServer(*conf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed configuring eebus: %w", err)
|
||||
}
|
||||
|
||||
eebus.Instance.Run()
|
||||
shutdown.Register(eebus.Instance.Shutdown)
|
||||
shutdown.Register(srv.Shutdown)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue