Skip to content

Commit

Permalink
Easee: add command response logging (evcc-io#7597)
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis authored Apr 22, 2023
1 parent 13054f9 commit d7dc0ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
33 changes: 18 additions & 15 deletions charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,19 @@ func (c *Easee) waitForInitialUpdate(done chan struct{}) {
close(done)
}

// observe handles the subscription messages
func (c *Easee) observe(typ string, i json.RawMessage) {
// ProductUpdate implements the signalr receiver
func (c *Easee) ProductUpdate(i json.RawMessage) {
var res easee.Observation
err := json.Unmarshal(i, &res)
if err != nil {
c.log.ERROR.Printf("invalid message: %s %s %v", i, typ, err)

if err := json.Unmarshal(i, &res); err != nil {
c.log.ERROR.Printf("invalid message: %s %v", i, err)
return
}

var value interface{}
var (
value interface{}
err error
)

switch res.DataType {
case easee.Boolean:
Expand Down Expand Up @@ -276,6 +279,8 @@ func (c *Easee) observe(typ string, i json.RawMessage) {
}
c.updated = time.Now()

c.log.TRACE.Printf("ProductUpdate %s: %s %v", res.Mid, res.ID, value)

switch res.ID {
case easee.USER_IDTOKEN:
c.rfid = res.Value
Expand Down Expand Up @@ -324,13 +329,6 @@ func (c *Easee) observe(typ string, i json.RawMessage) {
value.(int) == easee.ModeCompleted ||
value.(int) == easee.ModeReadyToCharge
}

c.log.TRACE.Printf("%s %s: %s %v", typ, res.Mid, res.ID, value)
}

// ProductUpdate implements the signalr receiver
func (c *Easee) ProductUpdate(i json.RawMessage) {
c.observe("ProductUpdate", i)
}

// ChargerUpdate implements the signalr receiver
Expand All @@ -340,7 +338,13 @@ func (c *Easee) ChargerUpdate(i json.RawMessage) {

// CommandResponse implements the signalr receiver
func (c *Easee) CommandResponse(i json.RawMessage) {
// c.observe("CommandResponse", i)
var res easee.SignalRCommandResponse

if err := json.Unmarshal(i, &res); err != nil {
c.log.ERROR.Printf("invalid message: %s %v", i, err)
return
}
c.log.TRACE.Printf("CommandResponse %s: %+v", res.SerialNumber, res)
}

func (c *Easee) chargers() ([]easee.Charger, error) {
Expand Down Expand Up @@ -393,7 +397,6 @@ func (c *Easee) Enable(enable bool) error {
if enable {
action = easee.ChargeResume
}

uri := fmt.Sprintf("%s/chargers/%s/commands/%s", easee.API, c.charger, action)
_, err := c.Post(uri, request.JSONContent, nil)

Expand Down
17 changes: 17 additions & 0 deletions charger/easee/signalr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ type Observation struct {
Value string
}

type SignalRCommandResponse struct {
SerialNumber string
ID int
Timestamp time.Time
DeliveredAt time.Time
WasAccepted bool
ResultCode string
Comment string
Ticks int64
}

type RestCommandResponse struct {
Device string
CommandId int
Ticks int64
}

type DataType int

// https://github.com/Masterloop/Masterloop.Core.Types/blob/master/src/Masterloop.Core.Types/Base/DataType.cs
Expand Down

0 comments on commit d7dc0ee

Please sign in to comment.