Skip to content

Check Battery and Network

mcdbus includes two read-only shortcut tools for checking hardware status: battery_status reads from UPower on the system bus, and network_status reads from NetworkManager on the system bus. Both tools only read properties — they do not change any state and require no confirmation prompt.

“What’s my battery level?”

battery_status()

The tool enumerates all power devices through UPower, filters for battery-type devices (type 2 in the UPower spec), and returns a summary for each battery found:

## Battery Status
### DELL XXXX
- **Charge:** 73%
- **State:** Discharging
- **Time:** 2h 14m remaining
- **Power draw:** 12.3 W

The tool calls org.freedesktop.UPower.EnumerateDevices to find all power devices, then reads org.freedesktop.UPower.Device properties on each one. The fields reported are:

FieldSource propertyNotes
ChargePercentage0-100 float
StateStateMapped from integer: 1=Charging, 2=Discharging, 3=Empty, 4=Fully charged, 5=Pending charge, 6=Pending discharge
Time remainingTimeToEmptySeconds, shown as hours and minutes when discharging
Time to fullTimeToFullSeconds, shown when charging
Power drawEnergyRateWatts
ModelModelBattery model string from the hardware

The shortcut tool shows the most useful fields. For deeper information (voltage, energy capacity, charge cycles, technology), use get_all_properties on the battery device path:

get_all_properties(
bus="system",
service="org.freedesktop.UPower",
object_path="/org/freedesktop/UPower/devices/battery_BAT0",
interface="org.freedesktop.UPower.Device"
)

On desktop machines without a battery, battery_status returns “No batteries found.” This is normal — UPower may still report other device types like line power or UPS units, but the tool filters for batteries specifically.

“Am I connected to the internet?”

network_status()

The tool reads properties from org.freedesktop.NetworkManager on the system bus and returns overall connectivity state, wireless status, and a table of active connections:

## Network Status
- **State:** Connected (global)
- **Wireless:** enabled
| Connection | Type | State |
|------------|------|-------|
| Ethernet 1 | 802-3-ethernet | Activated |
| MyWiFi | 802-11-wireless | Activated |

The tool calls Properties.GetAll on the org.freedesktop.NetworkManager interface to get the top-level state, then iterates over ActiveConnections to read each connection’s properties.

Top-level properties:

FieldSource propertyNotes
StateStateInteger mapped to: 0=Unknown, 10=Asleep, 20=Disconnected, 30=Disconnecting, 40=Connecting, 50=Connected (local), 60=Connected (site), 70=Connected (global)
WirelessWirelessEnabledBoolean

Per-connection properties (read from org.freedesktop.NetworkManager.Connection.Active on each active connection object path):

FieldSource property
ConnectionId
TypeType
StateState (mapped: 1=Activating, 2=Activated, 3=Deactivating, 4=Deactivated)

For detailed information about a specific network device (IP addresses, DNS servers, signal strength for wireless), use get_all_properties on the device’s object path. Network devices live under /org/freedesktop/NetworkManager/Devices/:

list_objects(
bus="system",
service="org.freedesktop.NetworkManager",
root_path="/org/freedesktop/NetworkManager/Devices"
)

Then introspect a specific device to see which interfaces it exposes (Wired, Wireless, Statistics) and read their properties.