diff --git a/api/api.go b/api/api.go index a157777fc..6707ed9fa 100644 --- a/api/api.go +++ b/api/api.go @@ -1,9 +1,12 @@ package api import ( - "encoding/json" "fmt" + "reflect" + "strings" "time" + + "github.com/fatih/structs" ) //go:generate mockgen -package mock -destination ../mock/mock_api.go github.com/evcc-io/evcc/api Charger,ChargeState,ChargePhases,Identifier,Meter,MeterEnergy,Vehicle,ChargeRater,Battery @@ -53,13 +56,15 @@ type ActionConfig struct { TargetSoC *int `mapstructure:"targetSoC,omitempty"` // Target SoC } -// String implements Stringer +// String implements Stringer and returns the ActionConfig as comma-separated key:value string func (a ActionConfig) String() string { - if data, err := json.Marshal(a); err != nil { - return fmt.Sprintf("%v\n", err) - } else { - return fmt.Sprintf("%s\n", data) + var s []string + for k, v := range structs.Map(a) { + if v != nil && !reflect.ValueOf(v).IsNil() { + s = append(s, fmt.Sprintf("%s:%v", k, v)) + } } + return strings.Join(s, ", ") } // Meter is able to provide current power in W diff --git a/cmd/dumper.go b/cmd/dumper.go index 714b0b5a2..69247bb8b 100644 --- a/cmd/dumper.go +++ b/cmd/dumper.go @@ -164,8 +164,10 @@ func (d *dumper) Dump(name string, v interface{}) { if v, ok := v.(api.Vehicle); ok { fmt.Fprintf(w, "Capacity:\t%dkWh\n", v.Capacity()) - fmt.Fprintf(w, "Identifiers:\t%v\n", v.Identifiers()) - fmt.Fprintf(w, "OnIdentified:\t%v\n", v.OnIdentified()) + if len(v.Identifiers()) > 0 { + fmt.Fprintf(w, "Identifiers:\t%v\n", v.Identifiers()) + fmt.Fprintf(w, "OnIdentified:\t%s\n", v.OnIdentified()) + } } // Identity