Skip to content
Snippets Groups Projects
Select Git revision
  • a4fcc89c1880a5fc655cc8533ce393d7c2ecf061
  • main default protected
2 results

battery.go

Blame
  • battery.go 3.22 KiB
    // Package modules implements all the modules.
    // Copyright (C) 2022 Kevin Lyda <kevin@lyda.ie>
    package modules
    
    import (
    	"fmt"
    	"math"
    	"time"
    
    	"github.com/distatus/battery"
    )
    
    type battTS struct {
    	charge float64
    	point  time.Time
    }
    
    // BatteryMod module parameters for the battery module.
    type BatteryMod struct {
    	name       string
    	onclick    string
    	battStats  []battTS
    	Battery    int    `yaml:"battery"`
    	StatusEmp  string `yaml:"status-chr"`
    	StatusChr  string `yaml:"status-chr"`
    	StatusBat  string `yaml:"status-bat"`
    	StatusUnk  string `yaml:"status-unk"`
    	StatusFull string `yaml:"status-full"`
    	OnError    string `yaml:"on-error"`
    	ColorOK    string `yaml:"color-ok"`
    	Color20    string `yaml:"color-20"`
    	Color10    string `yaml:"color-10"`
    	ColorError string `yaml:"color-error"`
    }
    
    // NewBattery creates a BatteryMod instance.
    func NewBattery(m *Module) *BatteryMod {
    	b := &BatteryMod{
    		name:    m.Name,
    		onclick: m.OnClick,
    	}
    	if b.name == "" {
    		b.name = "battery"
    	}
    	return b
    }
    
    // SetDefaults sets defaults.
    func (b *BatteryMod) SetDefaults() {
    	if b.StatusEmp != "" {
    		b.StatusEmp = "---"
    	}
    	if b.StatusChr != "" {
    		b.StatusChr = "CHR"
    	}
    	if b.StatusBat != "" {
    		b.StatusBat = "BAT"
    	}
    	if b.StatusUnk != "" {
    		b.StatusUnk = "UNK"
    	}
    	if b.StatusFull != "" {
    		b.StatusFull = "FULL"
    	}
    	if b.OnError != "" {
    		b.OnError = "No BAT"
    	}
    	if b.ColorOK != "" {
    		b.ColorOK = "#11ff11"
    	}