Support Audi and Tesla vehicle APIs (#20)

This commit is contained in:
andig 2020-03-29 21:15:44 +02:00 • committed by GitHub
parent 0a63ceb90a
commit ef6140cce5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 432 additions and 137 deletions

View file

@ -55,7 +55,9 @@ type ChargeRater interface {
ChargedEnergy() (float64, error)
}
// SoC represents the EV battery's state
type SoC interface {
// Vehicle represents the EV and it's battery
type Vehicle interface {
Title() string
Capacity() int64
ChargeState() (float64, error)
}

24
api/decoder.go Normal file
View file

@ -0,0 +1,24 @@
package api
import (
"github.com/mitchellh/mapstructure"
)
// DecodeOther decodes string map into target configuration
func DecodeOther(log *Logger, other map[string]interface{}, cc interface{}) {
decoderConfig := &mapstructure.DecoderConfig{
Result: cc,
ErrorUnused: true,
WeaklyTypedInput: true,
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
}
decoder, err := mapstructure.NewDecoder(decoderConfig)
if err != nil {
log.FATAL.Fatal(err)
}
if err := decoder.Decode(other); err != nil {
log.FATAL.Fatal(err)
}
}