Browse Source

Only start/stop charge if plugged in

master
Gregory Rudolph 3 years ago
parent
commit
1cf76471da
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 31
      commands.go

31
commands.go

@ -306,13 +306,25 @@ func startCharge(m chat1.MsgSummary) { @@ -306,13 +306,25 @@ func startCharge(m chat1.MsgSummary) {
if v == nil {
return
}
err := v.StartCharging()
state, err := v.ChargeState()
if err != nil {
tracker := uuid.NewString()
k.SendMessageByConvID(m.ConvID, "There was an error starting your charge. Contact @rudi9719 for more information with code %+v", tracker)
k.SendMessageByConvID(m.ConvID, "There was an error getting charge state. Contact @rudi9719 for more information with code %+v", tracker)
log.LogError("%+v: %+v", tracker, err)
return
}
if state.ChargingState != "Disconnected" {
err := v.StartCharging()
if err != nil {
tracker := uuid.NewString()
k.SendMessageByConvID(m.ConvID, "There was an error starting your charge. Contact @rudi9719 for more information with code %+v", tracker)
log.LogError("%+v: %+v", tracker, err)
return
}
} else {
k.SendMessageByConvID(m.ConvID, "You must plug in first, to be able to charge.")
}
}
func stopCharge(m chat1.MsgSummary) {
@ -320,13 +332,24 @@ func stopCharge(m chat1.MsgSummary) { @@ -320,13 +332,24 @@ func stopCharge(m chat1.MsgSummary) {
if v == nil {
return
}
err := v.StopCharging()
state, err := v.ChargeState()
if err != nil {
tracker := uuid.NewString()
k.SendMessageByConvID(m.ConvID, "There was an error stopping your charge. Contact @rudi9719 for more information with code %+v", tracker)
k.SendMessageByConvID(m.ConvID, "There was an error getting charge state. Contact @rudi9719 for more information with code %+v", tracker)
log.LogError("%+v: %+v", tracker, err)
return
}
if state.ChargingState != "Disconnected" {
err := v.StopCharging()
if err != nil {
tracker := uuid.NewString()
k.SendMessageByConvID(m.ConvID, "There was an error stopping your charge. Contact @rudi9719 for more information with code %+v", tracker)
log.LogError("%+v: %+v", tracker, err)
return
}
} else {
k.SendMessageByConvID(m.ConvID, "You must plug in first, to be able to stop charging.")
}
}
func enableStart(m chat1.MsgSummary) {

Loading…
Cancel
Save