evcc-io/vehicle/wrapper/wrapper.go
rivengh a45e240253
Improve action handling to consistently apply and reset vehicle settings (#1942)
allow GetTargetSoC() and GetMinSoC() to be used even when no vehicle is connected
use SetMinSoC() and SetTargetSoC() functions in applyAction()
allow to set minSoC to 0 with applyAction()
apply OnIdentify actions only when OnIdentify node is present in vehicle configuration (optional parameter)
2021-12-01 13:49:59 +01:00

48 lines
940 B
Go

package wrapper
import (
"fmt"
"github.com/evcc-io/evcc/api"
)
// Wrapper wraps an api.Vehicle to capture initialization errors
type Wrapper struct {
err error
}
// New creates a new Vehicle
func New(w api.Vehicle, err error) (api.Vehicle, error) {
v := &Wrapper{
err: fmt.Errorf("vehicle not available: %w", err),
}
return v, nil
}
// Title implements the api.Vehicle interface
func (v *Wrapper) Title() string {
return "unavailable"
}
// Capacity implements the api.Vehicle interface
func (v *Wrapper) Capacity() int64 {
return 0
}
// Identifiers implements the api.Vehicle interface
func (v *Wrapper) Identifiers() []string {
return nil
}
// OnIdentified implements the api.Vehicle interface
func (v *Wrapper) OnIdentified() api.ActionConfig {
return api.ActionConfig{}
}
var _ api.Battery = (*Wrapper)(nil)
// SoC implements the api.Battery interface
func (v *Wrapper) SoC() (float64, error) {
return 0, v.err
}