Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

power

Power profiles, mains or battery, and battery power draw.

list {
    direction = "Horizontal",
    source = mantle.power:map(function(power)
        return power and power.profiles or {}
    end),
    itemfn = function(name)
        return button {
            padding = 6,
            background = mantle.power:map(function(power)
                return (power and power.active_profile == name) and "#89B4FA" or "#313244"
            end),
            on_click = function() mantle.power:set_profile(name) end,
            children = { text { content = name } },
        }
    end,
}

State

mantle.power:get() returns PowerState, nil before the first push. A field marked ? may be absent.

mantle.power’s payload. Profile fields are nil without power-profiles-daemon, the rest without UPower; a failed read is also nil. With neither service the payload is an empty table.

FieldTypeDescription
active_profile?stringActive platform profile, e.g. "balanced".
energy_rate?numberUPower’s display-device EnergyRate in watts; direction is mantle.battery.state.
on_battery?booleanUPower’s OnBattery: running on battery rather than mains.
profiles?string[]Available profiles in daemon order, e.g. {"power-saver", "balanced", "performance"}.

Actions

Call each as mantle.power:<action>(arguments...); ? marks an argument you may omit.

ActionArgumentsDescription
set_profilename: stringSwitches to one of profiles. Not validated here; a rejected name is logged and active_profile stays.

Backend

HalfSourceMissing
active_profile, profilespower-profiles-daemon: org.freedesktop.UPower.PowerProfiles, else net.hadess.PowerProfilesBoth fields absent; set_profile is logged and ignored
on_battery, energy_rateUPower’s OnBattery and its DisplayDevice’s EnergyRateBoth fields absent

Every OnBattery, EnergyRate or ActiveProfile change re-reads all four fields. With neither service the push is an empty table.

Gotchas

TrapFix
power-profiles-daemon started after the capability never shows upThe daemon is looked up once, on the first read. Restart mantle after installing it
energy_rate has no signIt is a magnitude in watts. Read mantle.battery’s state for the direction

See also: battery for charge and time estimates.

Source: supervisor/src/capabilities/power/