Wattpilot: add logging (#15894)

This commit is contained in:
Martin Buchleitner 2024-09-04 18:36:32 +02:00 • committed by GitHub
parent 5489a15b24
commit 06e2b16145
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 7 deletions

View file

@ -3,6 +3,7 @@ package charger
import (
"errors"
"fmt"
"strings"
"time"
"github.com/evcc-io/evcc/api"
@ -13,6 +14,7 @@ import (
// Wattpilot charger implementation
type Wattpilot struct {
api *wattpilot.Wattpilot
log *util.Logger
}
func init() {
@ -40,10 +42,14 @@ func NewWattpilotFromConfig(other map[string]interface{}) (api.Charger, error) {
// NewWattpilot creates Wattpilot charger
func NewWattpilot(uri, password string, cache time.Duration) (api.Charger, error) {
log := util.NewLogger("wattpilot").Redact(password)
c := &Wattpilot{
api: wattpilot.New(uri, password),
log: log,
}
c.api.SetLogger(c.Log)
log.INFO.Println("Wattpilot connecting...")
if err := c.api.Connect(); err != nil {
return nil, err
}
@ -51,6 +57,15 @@ func NewWattpilot(uri, password string, cache time.Duration) (api.Charger, error
return c, nil
}
func (c *Wattpilot) Log(level string, data string) {
switch strings.ToUpper(level) {
case "TRACE":
c.log.TRACE.Println(data)
default:
c.log.DEBUG.Println(data)
}
}
// Status implements the api.Charger interface
func (c *Wattpilot) Status() (api.ChargeStatus, error) {
car, err := c.api.GetProperty("car")

4
go.mod
View file

@ -64,7 +64,7 @@ require (
github.com/libp2p/zeroconf/v2 v2.2.0
github.com/lorenzodonini/ocpp-go v0.18.0
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40
github.com/mabunixda/wattpilot v1.8.1
github.com/mabunixda/wattpilot v1.8.4
github.com/mitchellh/go-homedir v1.1.0
github.com/mlnoga/rct v0.1.2-0.20240421173556-1c5b75037e2f
github.com/muka/go-bluetooth v0.0.0-20240701044517-04c4f09c514e
@ -186,7 +186,7 @@ require (
gitlab.com/c0b/go-ordered-json v0.0.0-20201030195603-febf46534d5a // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.23.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240823204242-4ba0660f739c // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect

8
go.sum
View file

@ -400,8 +400,8 @@ github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0U
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 h1:EnfXoSqDfSNJv0VBNqY/88RNnhSGYkrHaO0mmFGbVsc=
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/mabunixda/wattpilot v1.8.1 h1:XP+Udu1HrSTjBd4Odl0SNpSr12uvnGndoDg2vSNqcdI=
github.com/mabunixda/wattpilot v1.8.1/go.mod h1:oXWlvKInaVt8FFSdEoNObEP5N8+4m6cbiF11M+8DAHY=
github.com/mabunixda/wattpilot v1.8.4 h1:nPwTQft15JeRJDUoxv6IpsGpu45EvNGW3EFU6UHNUzc=
github.com/mabunixda/wattpilot v1.8.4/go.mod h1:oXWlvKInaVt8FFSdEoNObEP5N8+4m6cbiF11M+8DAHY=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
@ -807,8 +807,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=