upower

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package upower reads battery state from UPower over the system D-Bus, the Go counterpart of crates/wayle-battery's zbus proxy: the DisplayDevice aggregate by default, live updates through PropertiesChanged.

Index

Constants

View Source
const (
	// BusName is UPower's well-known name on the system bus.
	BusName = "org.freedesktop.UPower"
)
View Source
const DisplayDevicePath = "/org/freedesktop/UPower/devices/DisplayDevice"

DisplayDevicePath is UPower's composite device across all batteries.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Percentage  float64
	State       DeviceState
	TimeToEmpty time.Duration // 0 when unknown
	TimeToFull  time.Duration // 0 when unknown
	// IsPresent is UPower's IsPresent: a battery is in its bay.
	IsPresent bool
	// EnergyRate is the charge or discharge rate in watts.
	EnergyRate float64
	// Energy and EnergyFull are watt-hours now and at full charge.
	Energy     float64
	EnergyFull float64
	// Capacity is the health percentage (full against design); 0 when
	// unknown.
	Capacity     float64
	WarningLevel WarningLevel
	// ChargeEndThreshold is the charge limit percentage.
	ChargeEndThreshold       uint32
	ChargeThresholdSupported bool
	ChargeThresholdEnabled   bool
}

Device is one battery snapshot: the org.freedesktop.UPower.Device properties the bar and its dropdown read.

type DeviceState

type DeviceState uint8

DeviceState mirrors UPower's device state enum (types.rs's DeviceState/From<u32>).

const (
	StateUnknown          DeviceState = iota
	StateCharging                     // 1
	StateDischarging                  // 2
	StateEmpty                        // 3
	StateFullyCharged                 // 4
	StatePendingCharge                // 5
	StatePendingDischarge             // 6
)

Device states.

func StateFromUint32

func StateFromUint32(v uint32) DeviceState

StateFromUint32 maps UPower's wire value; anything else is Unknown.

type Source

type Source interface {
	// Read returns the current device snapshot.
	Read(ctx context.Context) (Device, error)
	// Subscribe delivers a tick per PropertiesChanged on the device.
	// The returned stop function unsubscribes; the channel closes on
	// ctx completion either way.
	Subscribe(ctx context.Context) (<-chan struct{}, func(), error)
	// EnableChargeThreshold turns the charge limit on or off
	// (Device::enable_charge_threshold).
	EnableChargeThreshold(ctx context.Context, enabled bool) error
}

Source is the seam the bar module and dropdown consume; tests swap in a fake.

type System

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

System reads the real UPower on the system bus.

func NewOn

func NewOn(conn *dbus.Conn) *System

NewOn targets the DisplayDevice over an existing connection.

func NewSystem

func NewSystem() (*System, error)

NewSystem connects to the system bus and targets the DisplayDevice.

func (*System) Close

func (s *System) Close() error

Close drops the bus connection.

func (*System) EnableChargeThreshold

func (s *System) EnableChargeThreshold(ctx context.Context, enabled bool) error

EnableChargeThreshold calls the device's EnableChargeThreshold.

func (*System) Read

func (s *System) Read(ctx context.Context) (Device, error)

Read fetches every DisplayDevice property in one GetAll.

func (*System) Subscribe

func (s *System) Subscribe(ctx context.Context) (<-chan struct{}, func(), error)

Subscribe matches PropertiesChanged for the DisplayDevice and ticks the channel per signal. The match is removed by stop.

type WarningLevel

type WarningLevel uint8

WarningLevel mirrors UPower's warning level enum (types.rs's WarningLevel/From<u32>).

const (
	WarningUnknown     WarningLevel = iota
	WarningNone                     // 1
	WarningDischarging              // 2, UPSes only
	WarningLow                      // 3
	WarningCritical                 // 4
	WarningAction                   // 5
)

Warning levels.

func WarningFromUint32

func WarningFromUint32(v uint32) WarningLevel

WarningFromUint32 maps UPower's wire value; anything else is Unknown.

func (WarningLevel) Low

func (w WarningLevel) Low() bool

Low reports Low, Critical, or Action: the levels the dropdown flags (helpers.rs's is_low_battery).

Jump to

Keyboard shortcuts

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