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, the peripherals UPower enumerates beside it, and live updates through PropertiesChanged, DeviceAdded and DeviceRemoved.
Index ¶
- Constants
- type Device
- type DeviceKind
- type DeviceState
- type Peripheral
- type Source
- type System
- func (s *System) EnableChargeThreshold(ctx context.Context, enabled bool) error
- func (s *System) OnBattery(ctx context.Context) (bool, error)
- func (s *System) Peripherals(ctx context.Context) ([]Peripheral, error)
- func (s *System) Read(ctx context.Context) (Device, error)
- func (s *System) Subscribe(ctx context.Context) (<-chan struct{}, func(), error)
- func (s *System) SubscribeOnBattery(ctx context.Context) (<-chan struct{}, func(), error)
- func (s *System) SubscribePeripherals(ctx context.Context) (<-chan struct{}, func(), error)
- type WarningLevel
Constants ¶
const (
// BusName is UPower's well-known name on the system bus.
BusName = "org.freedesktop.UPower"
)
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 DeviceKind ¶ added in v0.3.15
type DeviceKind uint8
DeviceKind mirrors UPower's device Type enum.
const ( KindUnknown DeviceKind = iota KindLinePower KindBattery KindUPS KindMonitor KindMouse KindKeyboard KindPDA KindPhone KindMediaPlayer KindTablet KindComputer KindGamingInput KindPen KindTouchpad KindModem KindNetwork KindHeadset KindSpeakers KindHeadphones KindVideo KindOtherAudio KindRemoteControl KindPrinter KindScanner KindCamera KindWearable KindToy KindBluetoothGeneric )
Device kinds, numbered as UPower's Type property.
func KindFromUint32 ¶ added in v0.3.15
func KindFromUint32(v uint32) DeviceKind
KindFromUint32 maps UPower's wire value; anything else is Unknown.
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 Peripheral ¶ added in v0.3.15
type Peripheral struct {
Path dbus.ObjectPath
Kind DeviceKind
Model string
Percentage float64
State DeviceState
WarningLevel WarningLevel
}
Peripheral is one device UPower reports beside the DisplayDevice aggregate: a wireless mouse, a keyboard, a controller, a headset, a UPS.
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
// Peripherals returns the peripherals UPower enumerates, ordered by
// object path.
Peripherals(ctx context.Context) ([]Peripheral, error)
// SubscribePeripherals delivers a tick per device added or removed
// and per PropertiesChanged on any device but the DisplayDevice.
SubscribePeripherals(ctx context.Context) (<-chan struct{}, func(), 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 (*System) EnableChargeThreshold ¶
EnableChargeThreshold calls the device's EnableChargeThreshold.
func (*System) OnBattery ¶ added in v0.3.15
OnBattery reads UPower's OnBattery: the machine runs on its battery.
func (*System) Peripherals ¶ added in v0.3.15
func (s *System) Peripherals(ctx context.Context) ([]Peripheral, error)
Peripherals enumerates UPower's devices and reads each one, keeping the peripherals.
func (*System) Subscribe ¶
Subscribe matches PropertiesChanged for the DisplayDevice, and UPower gaining an owner, and ticks the channel per signal. The matches are removed by stop.
func (*System) SubscribeOnBattery ¶ added in v0.3.15
SubscribeOnBattery ticks per PropertiesChanged of UPower itself, which carries OnBattery. The match is removed by stop.
func (*System) SubscribePeripherals ¶ added in v0.3.15
SubscribePeripherals matches DeviceAdded and DeviceRemoved on UPower and PropertiesChanged under its devices, and UPower gaining an owner. The matches are 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).
func (WarningLevel) Rank ¶ added in v0.3.15
func (w WarningLevel) Rank() uint8
Rank orders the levels a battery alert follows: 0 for none, 1 for Low, 2 for Critical and Action.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package upowertest serves a scriptable UPower on a test bus: the DisplayDevice and enumerated devices, each change announced with the signal the real daemon sends, and every GetAll counted.
|
Package upowertest serves a scriptable UPower on a test bus: the DisplayDevice and enumerated devices, each change announced with the signal the real daemon sends, and every GetAll counted. |