Skip to content

Commit

Permalink
Mqtt: support settting guest vehicle by using negative value
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Oct 17, 2022
1 parent ad0591e commit 43d4221
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/loadpoint_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (lp *LoadPoint) SetMode(mode api.ChargeMode) {
defer lp.Unlock()

if _, err := api.ChargeModeString(mode.String()); err != nil {
lp.log.WARN.Printf("invalid charge mode: %s", string(mode))
lp.log.ERROR.Printf("invalid charge mode: %s", string(mode))
return
}

Expand Down
9 changes: 6 additions & 3 deletions server/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ func (m *MQTT) listenSetters(topic string, site site.API, lp loadpoint.API) {
})
m.Handler.ListenSetter(topic+"/vehicle/set", func(payload string) {
if vehicle, err := strconv.Atoi(payload); err == nil {
vehicles := site.GetVehicles()
if vehicle < len(vehicles) {
lp.SetVehicle(vehicles[vehicle])
if vehicle >= 0 {
if vehicles := site.GetVehicles(); vehicle < len(vehicles) {
lp.SetVehicle(vehicles[vehicle])
}
} else {
lp.SetVehicle(nil)
}
}
})
Expand Down

0 comments on commit 43d4221

Please sign in to comment.