diff options
author | Sean E. Russell <ser@ser1.net> | 2020-02-25 14:02:44 -0600 |
---|---|---|
committer | Sean E. Russell <ser@ser1.net> | 2020-02-25 14:22:20 -0600 |
commit | 11c33726aa01bf27a6f25e4c13eed0cf382473f5 (patch) | |
tree | 42353da6710954348deb8824ee642d00b22cb4b4 /widgets | |
parent | 8d767a448ea768f3fbad911f8fe38131a5044951 (diff) |
Adds charge/discharge to power widget.
Issue tracking
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/batterygauge.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/widgets/batterygauge.go b/widgets/batterygauge.go index 04b1434..a84637c 100644 --- a/widgets/batterygauge.go +++ b/widgets/batterygauge.go @@ -3,8 +3,7 @@ package widgets import ( "fmt" "log" - //"math" - //"strconv" + "time" "github.com/distatus/battery" @@ -65,12 +64,22 @@ func (self *BatteryGauge) update() { } mx := 0.0 cu := 0.0 + charging := "%d%% ⚡%s" + rate := 0.0 for _, bat := range bats { mx += bat.Full cu += bat.Current + if rate < bat.ChargeRate { + rate = bat.ChargeRate + } + if bat.State == battery.Charging { + charging = "%d%% 🔌%s" + } } + tn := (mx - cu) / rate + d, _ := time.ParseDuration(fmt.Sprintf("%fh", tn)) self.Percent = int((cu / mx) * 100.0) - self.Label = fmt.Sprintf("%d%%", self.Percent) + self.Label = fmt.Sprintf(charging, self.Percent, d.Truncate(time.Minute)) if self.metric != nil { self.metric.Set(cu / mx) } |