getEnergyStats method

Future<EnergyStats?> getEnergyStats({
  1. required HomeAutoQueryCommand command,
  2. required int deviceId,
})

Implementation

Future<EnergyStats?> getEnergyStats({
  required HomeAutoQueryCommand command,
  required int deviceId,
}) async {
  assert(sessionId != null && sessionId!.isNotEmpty, 'SessionId must not be null or empty');

  final url = Uri.parse('$baseUrl/net/home_auto_query.lua?sid=${sessionId!}&command=${command.name}&id=$deviceId&xhr=1');
  final Map<String, String> headers = {};
  final response = await get(url, headers: headers);

  try {
    return EnergyStats.fromJson(jsonDecode(response.body));
  } catch (e) {
    debugPrint(e.toString());
  }
  return null;
}