Skip to content

Battery

properties

  • available: boolean whether a battery is available or not
  • percent: number round number from 0 to 100
  • charging: boolean
  • charged: boolean fully charged or percent == 100 and charging
  • icon-name: string
  • time-remaining: number time in seconds until fully charged (when charging) or until it fully drains (when discharging)
  • energy: number - current energy in W
  • energy-full: number capacity in W
  • energy-rate: number - drain rate in W (positive if not charging, negative if charging)

Example Widgets

const battery = await Service.import('battery')
const batteryProgress = Widget.CircularProgress({
child: Widget.Icon({
icon: battery.bind('icon_name')
}),
visible: battery.bind('available'),
value: battery.bind('percent').as(p => p > 0 ? p / 100 : 0),
class_name: battery.bind('charging').as(ch => ch ? 'charging' : ''),
})