getHistory method

Future<List<UPowerDeviceHistoryRecord>> getHistory(
  1. String type,
  2. int resolution, {
  3. int timespan = 0,
})

Gets history of type ('rate' or 'charge').

Implementation

Future<List<UPowerDeviceHistoryRecord>> getHistory(
    String type, int resolution,
    {int timespan = 0}) async {
  var result = await _object.callMethod(
      'org.freedesktop.UPower.Device',
      'GetHistory',
      [DBusString(type), DBusUint32(timespan), DBusUint32(resolution)],
      replySignature: DBusSignature('a(udu)'));
  var records = <UPowerDeviceHistoryRecord>[];
  var children = (result.returnValues[0] as DBusArray)
      .children
      .map((e) => e as DBusStruct);
  for (var child in children) {
    var values = child.children.toList();
    var time = (values[0] as DBusUint32).value;
    var value = (values[1] as DBusDouble).value;
    var state = UPowerDeviceState.values[(values[2] as DBusUint32).value];
    records.add(UPowerDeviceHistoryRecord(time, value, state));
  }
  return records;
}