From 1cf76471dab492732a69bc9be46c05fdaf74d712 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 6 Jul 2021 11:22:52 -0400 Subject: [PATCH] Only start/stop charge if plugged in --- commands.go | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index a4f6788..12b4f4c 100644 --- a/commands.go +++ b/commands.go @@ -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) { 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) {