battery

package
v0.0.0-...-ca40e7b Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: CC-BY-4.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListPowerDevices

func ListPowerDevices() []string

ListPowerDevices returns a string slice containing every power device available as provided by upower -e.

Types

type Battery

type Battery struct {
	Present      bool
	Rechargeable bool
	State        string
	WarningLevel string
	Energy       Energy
	EnergyRate   Watt
	Voltage      Voltage
	ChargeCycles string
	TimeToEmpty  time.Duration
	TimeToFull   time.Duration
	Technology   string
	IconName     string
}

Battery holds the specific information of the battery, such as its current state, if it's rechargeable, its voltage, technology used, and time to empty or full.

type BatteryInfo

type BatteryInfo struct {
	SrcDevice   string
	NativePath  string
	Vendor      string
	Model       string
	Serial      uint64
	PowerSupply bool
	Updated     time.Time
	HasHistory  bool
	Statistics  bool
	Battery     Battery
	History     []History
}

BatteryInfo holds the general information of the battery, such as its model, vendor, serial, among others.

func NewForDefaultDevice

func NewForDefaultDevice() (*BatteryInfo, error)

NewForDefaultDevice returns a *BatteryInfo for the default device, which is the one that ends with BAT#, where # is a number.

The following error types may be returned: *DefaultDeviceNotFoundError, *InvalidDeviceError, *CommandError.

func NewForDevice

func NewForDevice(device string) (*BatteryInfo, error)

NewForDevice constructs a new *BatteryInfo for the given device. The device can be acquired with ListPowerDevices. Alternatively, if something wrong happens when fetching or parsing the battery information, an error may be returned.

The following error types may be returned: *InvalidDeviceError, *CommandError.

func (*BatteryInfo) Update

func (bi *BatteryInfo) Update() (*BatteryInfo, error)

Update returns a new *BatteryInfo by re-parsing the battery information as done by NewForDevice.

Possible returnable errors are the same as for NewForDevice().

type CommandError

type CommandError struct {
	Cmd *exec.Cmd
	Err error
}

func (*CommandError) Error

func (e *CommandError) Error() string

func (*CommandError) Unwrap

func (e *CommandError) Unwrap() error

type DefaultDeviceNotFoundError

type DefaultDeviceNotFoundError struct{}

func (*DefaultDeviceNotFoundError) Error

type Energy

type Energy struct {
	Current, Empty, Full, FullDesign WattHour
	Percentage, Capacity             Percentage
}

Energy holds the information of the energy of the battery, as well as its current percentage and capacity.

type History

type History struct {
	Type   string
	Status string
	Time   time.Time
}

History as listed by upower -i.

type InvalidDeviceError

type InvalidDeviceError struct {
	Name string
}

func (*InvalidDeviceError) Error

func (e *InvalidDeviceError) Error() string

type Percentage

type Percentage float32

func (Percentage) String

func (p Percentage) String() string

type Voltage

type Voltage float32

func (Voltage) String

func (v Voltage) String() string

type Watt

type Watt float32

func (Watt) String

func (w Watt) String() string

type WattHour

type WattHour float32

func (WattHour) String

func (wh WattHour) String() string

Jump to

Keyboard shortcuts

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