mirror of
https://github.com/SyncrowIOT/web.git
synced 2026-10-25 22:37:56 +00:00
Created initial remote implementation for all the services in the energy management module.
This commit is contained in:
@@ -3,7 +3,7 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:syncrow_web/pages/analytics/models/energy_data_model.dart';
|
||||
|
||||
class DeviceEnergyDataModel extends Equatable {
|
||||
const DeviceEnergyDataModel( {
|
||||
const DeviceEnergyDataModel({
|
||||
required this.energy,
|
||||
required this.deviceName,
|
||||
required this.deviceId,
|
||||
@@ -17,4 +17,16 @@ class DeviceEnergyDataModel extends Equatable {
|
||||
|
||||
@override
|
||||
List<Object?> get props => [energy, deviceName, deviceId];
|
||||
|
||||
factory DeviceEnergyDataModel.fromJson(Map<String, dynamic> json) {
|
||||
final energy = (json['energy'] as List<dynamic>? ?? [])
|
||||
.map((e) => EnergyDataModel.fromJson(e))
|
||||
.toList();
|
||||
return DeviceEnergyDataModel(
|
||||
energy: energy,
|
||||
deviceName: json['device_name'] as String? ?? '',
|
||||
deviceId: json['device_id'] as String? ?? '',
|
||||
color: Color(int.parse(json['color'] as String? ?? '0xFF000000')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,13 @@ class EnergyDataModel extends Equatable {
|
||||
final DateTime date;
|
||||
final double value;
|
||||
|
||||
factory EnergyDataModel.fromJson(Map<String, dynamic> json) {
|
||||
return EnergyDataModel(
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
value: (json['value'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [date, value];
|
||||
}
|
||||
|
||||
@@ -15,4 +15,13 @@ class PhasesEnergyConsumption extends Equatable {
|
||||
|
||||
@override
|
||||
List<Object?> get props => [month, phaseA, phaseB, phaseC];
|
||||
|
||||
factory PhasesEnergyConsumption.fromJson(Map<String, dynamic> json) {
|
||||
return PhasesEnergyConsumption(
|
||||
month: json['month'] as int,
|
||||
phaseA: (json['phaseA'] as num).toDouble(),
|
||||
phaseB: (json['phaseB'] as num).toDouble(),
|
||||
phaseC: (json['phaseC'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user