20 #include <QDBusInterface>
29 const QString UPOWER_SERVICE = QStringLiteral("org.freedesktop.UPower");
30 const QString UPOWER_OBJECT = QStringLiteral("org.freedesktop.UPower.Device");
35 std::string device_path = config.check(
"device_path",
36 Value(
"/org/freedesktop/UPower/devices/battery_BAT0"),
37 "Battery device path (as returned by 'upower -e', for example '/org/freedesktop/UPower/devices/battery_BAT0')").asString();
39 m_interface =
new QDBusInterface(UPOWER_SERVICE, QString(device_path.c_str()), UPOWER_OBJECT, QDBusConnection::systemBus());
40 if (!m_interface->isValid()) {
41 yCError(UPOWERBATTERY) <<
"Interface not found";
57 voltage = m_interface->property(
"Voltage").toDouble();
63 auto energyrate = m_interface->property(
"EnergyRate").toDouble();
64 auto voltage = m_interface->property(
"Voltage").toDouble();
65 auto state = m_interface->property(
"State").toUInt();
66 current = energyrate / voltage;
67 if (current > 0 && state == 1 ) {
75 charge = m_interface->property(
"Percentage").toInt();
82 auto st = m_interface->property(
"State").toUInt();
83 auto wl = m_interface->property(
"WarningLevel").toUInt();
86 case 1 : [[fallthrough]];
93 case 1 : [[fallthrough]];
100 case 4 : [[fallthrough]];
104 case 0 : [[fallthrough]];
115 case 0 : [[fallthrough]];
126 temperature = m_interface->property(
"Temperature").toDouble();
132 info = QStringLiteral(
"Vendor: %1, Model: %2, Serial: %3")
133 .arg(m_interface->property(
"Vendor").toString())
134 .arg(m_interface->property(
"Model").toString())
135 .arg(m_interface->property(
"Serial").toString())
137 yCDebug(UPOWERBATTERY) << info;