power

package
v2.17.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package power reports whether the device is running on mains power or a battery, and how much of that battery is left. The updater uses it to refuse an install that could lose power part-way through.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

type Source string

Source is where the device is drawing power from.

const (
	// SourceNoBattery means the hardware has no battery at all, so it is
	// running on whatever mains supply it always runs on.
	SourceNoBattery Source = "noBattery"
	// SourceExternal means a charger or dock is supplying power. The battery
	// percentage does not matter while this is true.
	SourceExternal Source = "external"
	// SourceBattery means the device is discharging and Percent is its
	// remaining charge.
	SourceBattery Source = "battery"
	// SourceUnknown means the hardware may have a battery but its state could
	// not be read. Callers must treat this as "could lose power at any
	// moment", not as "probably fine".
	SourceUnknown Source = "unknown"
)

type Status

type Status struct {
	Source Source
	// Percent is the remaining charge, 0-100. It is only meaningful when
	// Source is SourceBattery.
	Percent int
}

Status is a snapshot of where the device's power is coming from.

func Read

func Read() (Status, error)

Read reports the device's power state from the kernel's power-supply directory.

Jump to

Keyboard shortcuts

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