summaryrefslogtreecommitdiff
path: root/batteryModule.go
blob: 81fdef0955177b0c720a36e1d2800a8c7e071c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main

import (
	"io/ioutil"
)

// TODO: Move this to a central spot, like a config.h
const (
	batteryPath = "/sys/class/power_supply/BAT0/capacity"
	identifier  = "BAT"
)

// BatteryModule is the module that controls finding out the battery
// percentage, mainly useful in laptops
type BatteryModule struct {
}

func (_ BatteryModule) GetInfo() (string, error) {
	return readBatteryLevel(batteryPath)
}

func readBatteryLevel(path string) (string, error) {
	dat, err := ioutil.ReadFile(path)

	if err != nil {
		return "NULL", err
	}

	return (string(dat[:len(dat)-1]) + "%"), nil
}