Mqtt: support settting guest vehicle by using negative value

This commit is contained in:
andig 2022-10-17 10:13:44 +02:00
parent ad0591e252
commit 43d4221cf9
2 changed files with 7 additions and 4 deletions

View file

@ -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
}

View file

@ -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)
}
}
})