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 ¶
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 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 (*System) EnableChargeThreshold ¶
EnableChargeThreshold calls the device's EnableChargeThreshold.
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).