Skip to content

Commit

Permalink
Mqtt: re-add plan api (evcc-io#11022)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Dec 6, 2023
1 parent 6709edf commit 06617a3
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions server/mqtt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"encoding/json"
"fmt"
"math"
"reflect"
Expand Down Expand Up @@ -266,27 +267,19 @@ func (m *MQTT) listenLoadpointSetters(topic string, site site.API, lp loadpoint.
return err
})
}
// TODO plan
// if err == nil {
// err = m.Handler.ListenSetter(topic+"/planEnergy", func(payload string) error {
// val, err := parseFloat(payload)
// if err == nil {
// lp.SetPlanEnergy(val)
// }
// return err
// })
// }
// if err == nil {
// err = m.Handler.ListenSetter(topic+"/planTime", func(payload string) error {
// val, err := time.Parse(time.RFC3339, payload)
// if err == nil {
// err = lp.SetPlanTime(val)
// } else if string(payload) == "null" {
// err = lp.SetPlanTime(time.Time{})
// }
// return err
// })
// }
if err == nil {
err = m.Handler.ListenSetter(topic+"/planEnergy", func(payload string) error {
var plan struct {
Time time.Time `json:"time"`
Value float64 `json:"value"`
}
err := json.Unmarshal([]byte(payload), &plan)
if err == nil {
err = lp.SetPlanEnergy(plan.Time, plan.Value)
}
return err
})
}
if err == nil {
err = m.Handler.ListenSetter(topic+"/vehicle", func(payload string) error {
if payload == "" {
Expand Down Expand Up @@ -322,7 +315,6 @@ func (m *MQTT) listenLoadpointSetters(topic string, site site.API, lp loadpoint.
return err
}

// TODO plan
func (m *MQTT) listenVehicleSetters(topic string, v vehicle.API) error {
var err error

Expand All @@ -344,7 +336,19 @@ func (m *MQTT) listenVehicleSetters(topic string, v vehicle.API) error {
return err
})
}

if err == nil {
err = m.Handler.ListenSetter(topic+"/planSoc", func(payload string) error {
var plan struct {
Time time.Time `json:"time"`
Value int `json:"value"`
}
err := json.Unmarshal([]byte(payload), &plan)
if err == nil {
err = v.SetPlanSoc(plan.Time, plan.Value)
}
return err
})
}
return err
}

Expand Down

0 comments on commit 06617a3

Please sign in to comment.