Index | Files

package battery

import ""

Package battery provides a battery status i3bar module.


Package Files


type Info Uses

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 Uses

func (i Info) Discharging() bool

Discharging returns true if the battery is being discharged.

func (Info) PluggedIn Uses

func (i Info) PluggedIn() bool

PluggedIn returns true if the laptop is plugged in.

func (Info) Remaining Uses

func (i Info) Remaining() float64

Remaining returns the fraction of battery capacity remaining.

func (Info) RemainingPct Uses

func (i Info) RemainingPct() int

RemainingPct returns the percentage of battery capacity remaining.

func (Info) RemainingTime Uses

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 Uses

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 Uses

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 Uses

func All() *Module

All constructs a battery module that aggregates all detected batteries.

func Named Uses

func Named(name string) *Module

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

func (*Module) Output Uses

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 Uses

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

RefreshInterval configures the polling frequency for battery info.

func (*Module) Stream Uses

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

Stream starts the module.

type Status Uses

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 = ""

Package battery imports 12 packages (graph) and is imported by 3 packages. Updated 2019-04-27. Refresh now. Tools for package owners.