Browse Source

Add charge time formatting for times greater than an hour

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

12
commands.go

@ -127,7 +127,9 @@ func chargeStatus(m chat1.MsgSummary) { @@ -127,7 +127,9 @@ func chargeStatus(m chat1.MsgSummary) {
ret += fmt.Sprintf("\nConnected Cable: %+v", state.ConnChargeCable)
ret += fmt.Sprintf("\nCharging State: %+v", state.ChargingState)
if state.ChargingState != "Stopped" {
ret += fmt.Sprintf("\nTime to full: %+vmin", state.MinutesToFullCharge)
chargeTimer := time.Duration(state.MinutesToFullCharge) * time.Minute
ret += fmt.Sprintf("\nTime to full: %+v (%+v)", formatDuration(chargeTimer), time.Now().Add(chargeTimer).Format("15:04"))
if state.FastChargerPresent {
ret += fmt.Sprintf("\nFast Charger: %+v %+v", state.FastChargerBrand, state.FastChargerType)
}
@ -142,7 +144,13 @@ func chargeStatus(m chat1.MsgSummary) { @@ -142,7 +144,13 @@ func chargeStatus(m chat1.MsgSummary) {
}
k.SendMessageByConvID(m.ConvID, ret)
}
func formatDuration(d time.Duration) string {
d = d.Round(time.Minute)
h := d / time.Hour
d -= h * time.Hour
m := d / time.Minute
return fmt.Sprintf("%02d:%02d", h, m)
}
func flashLights(m chat1.MsgSummary) {
v := getVehicle(m)
if v == nil {

Loading…
Cancel
Save