battery

package
v0.0.0-...-c936f35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 30

Documentation

Overview

Package battery provides a battery status i3bar module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	// Capacity in *percents*, from 0 to 100.
	Capacity int
	// Energy when the battery is full, in Wh.
	EnergyFull float64
	// Max Energy the battery can store, in Wh.
	EnergyMax float64
	// Energy currently stored in the battery, in Wh.
	EnergyNow float64
	// Power currently being drawn from the battery, in W.
	Power float64
	// Current voltage of the batter, in V.
	Voltage float64
	// Status of the battery, e.g. "Charging", "Full", "Disconnected".
	Status Status
	// Technology of the battery, e.g. "Li-Ion", "Li-Poly", "Ni-MH".
	Technology string
}

Info represents the current battery information.

func (Info) Discharging

func (i Info) Discharging() bool

Discharging returns true if the battery is being discharged.

func (Info) PluggedIn

func (i Info) PluggedIn() bool

PluggedIn returns true if the laptop is plugged in.

func (Info) Remaining

func (i Info) Remaining() float64

Remaining returns the fraction of battery capacity remaining.

func (Info) RemainingPct

func (i Info) RemainingPct() int

RemainingPct returns the percentage of battery capacity remaining.

func (Info) RemainingTime

func (i Info) RemainingTime() time.Duration

RemainingTime returns the best guess for remaining time. This is based on the current power draw and remaining capacity.

func (Info) SignedPower

func (i Info) SignedPower() float64

SignedPower returns a positive power value when the battery is being charged, and a negative power value when discharged.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module represents a battery bar module. It supports setting the output format, click handler, update frequency, and urgency/colour functions.

func All

func All() *Module

All constructs a battery module that aggregates all detected batteries.

func Named

func Named(name string) *Module

Named constructs an instance of the battery module for the given battery name.

func (*Module) Output

func (m *Module) Output(outputFunc func(Info) bar.Output) *Module

Output configures a module to display the output of a user-defined function.

func (*Module) RefreshInterval

func (m *Module) RefreshInterval(interval time.Duration) *Module

RefreshInterval configures the polling frequency for battery info.

func (*Module) Stream

func (m *Module) Stream(s bar.Sink)

Stream starts the module.

type Status

type Status string

Status represents a normalised battery status.

const (
	// Disconnected represents a named battery that was not found.
	Disconnected Status = "Disconnected"
	// Charging represents a battery that is actively being charged.
	Charging Status = "Charging"
	// Discharging represents a battery that is actively being discharged.
	Discharging Status = "Discharging"
	// Full represents a battery that is plugged in and at capacity.
	Full Status = "Full"
	// NotCharging represents a battery that is plugged in,
	// not full, but not charging.
	NotCharging Status = "Not charging"
	// Unknown is used to catch all other statuses.
	Unknown Status = ""
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL