Add charge time formatting for times greater than 1 hour
This commit is contained in:
20
main.go
20
main.go
@ -117,7 +117,7 @@ func main() {
|
||||
centralWidget := widgets.NewQWidget(window, 0)
|
||||
|
||||
// Set Values for everything
|
||||
go setValues()
|
||||
setValues()
|
||||
if refresh {
|
||||
go func() {
|
||||
time.Sleep(1 * time.Minute)
|
||||
@ -167,8 +167,8 @@ func main() {
|
||||
chargeHbox.AddWidget(batteryRange, 0, 0)
|
||||
|
||||
// Charging State has its own section and is handled differently based on if it is present or not
|
||||
if chargeStats != nil && chargeStats.ChargingState != "Disconnected" {
|
||||
statusLayout.AddRow3("Minutes to Full:", minutesToFull)
|
||||
if chargeStats.ChargingState != "Disconnected" {
|
||||
statusLayout.AddRow3("Time to Full:", minutesToFull)
|
||||
if chargeStats.FastChargerPresent {
|
||||
statusLayout.AddRow3("Fast Charger:", fastChargerInd)
|
||||
}
|
||||
@ -196,7 +196,7 @@ func main() {
|
||||
securityHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
securityHbox.AddWidget(sentryModeLabel, 0, 0)
|
||||
securityHbox.AddWidget(sentryMode, 0, 0)
|
||||
if chargeStats != nil && chargeStats.ChargingState != "Disconnected" {
|
||||
if chargeStats.ChargingState != "Disconnected" {
|
||||
securityHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
securityHbox.AddWidget(chargingStateLabel, 0, 0)
|
||||
securityHbox.AddWidget(startStopCharge, 0, 0)
|
||||
@ -270,8 +270,8 @@ func setValues() {
|
||||
strings.Replace(guiSettings.GuiDistanceUnits, "/hr", "", -1)))
|
||||
batteryRange.SetFixedWidth(10 * len(batteryRange.Text()))
|
||||
chargingState.SetText(chargeStats.ChargingState)
|
||||
|
||||
minutesToFull.SetText(fmt.Sprintf("%+v", chargeStats.MinutesToFullCharge))
|
||||
chargeTimer := time.Duration(chargeStats.MinutesToFullCharge) * time.Minute
|
||||
minutesToFull.SetText(fmt.Sprintf("%+v (%+v)", formatDuration(chargeTimer), time.Now().Add(chargeTimer).Format("15:04")))
|
||||
|
||||
fastChargerInd.SetText(chargeStats.FastChargerBrand)
|
||||
if chargeStats.BatteryHeaterOn {
|
||||
@ -422,3 +422,11 @@ func showDialogue(recover bool, msg string, a ...interface{}) {
|
||||
|
||||
dialogue.Show()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user