mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-14 17:25:47 +00:00
98 lines
2.6 KiB
Dart
98 lines
2.6 KiB
Dart
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
|
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
|
import 'package:syncrow_app/generated/assets.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
|
|
|
class DeviceModel {
|
|
int? activeTime;
|
|
// String? id;
|
|
String? localKey;
|
|
String? model;
|
|
String? name;
|
|
String? icon;
|
|
bool? isOnline;
|
|
List<StatusModel> status = [];
|
|
String? productName;
|
|
String? timeZone;
|
|
int? updateTime;
|
|
String? uuid;
|
|
DeviceType? productType;
|
|
bool isSelected = false;
|
|
late List<FunctionModel> functions;
|
|
DeviceModel({
|
|
this.activeTime,
|
|
// this.id,
|
|
this.localKey,
|
|
this.model,
|
|
this.name,
|
|
this.isOnline,
|
|
required this.status,
|
|
this.productName,
|
|
this.timeZone,
|
|
this.updateTime,
|
|
this.uuid,
|
|
this.productType,
|
|
this.icon,
|
|
}) {
|
|
functions = getFunctions(productType!);
|
|
}
|
|
|
|
factory DeviceModel.fromJson(Map<String, dynamic> json) {
|
|
String tempIcon = '';
|
|
DeviceType type = devicesTypesMap[json['productType']] ?? DeviceType.Other;
|
|
|
|
if (type == DeviceType.LightBulb) {
|
|
tempIcon = Assets.iconsLight;
|
|
} else if (type == DeviceType.CeilingSensor ||
|
|
type == DeviceType.WallSensor) {
|
|
tempIcon = Assets.iconsSensors;
|
|
} else if (type == DeviceType.AC) {
|
|
tempIcon = Assets.iconsAC;
|
|
} else if (type == DeviceType.DoorLock) {
|
|
tempIcon = Assets.iconsDoorLock;
|
|
} else if (type == DeviceType.Curtain) {
|
|
tempIcon = Assets.iconsCurtain;
|
|
} else if (type == DeviceType.ThreeGang) {
|
|
tempIcon = Assets.icons3GangSwitch;
|
|
} else if (type == DeviceType.Gateway) {
|
|
tempIcon = Assets.iconsGateway;
|
|
} else {
|
|
tempIcon = Assets.iconsLogo;
|
|
}
|
|
return DeviceModel(
|
|
icon: tempIcon,
|
|
activeTime: json['activeTime'],
|
|
// id: json['id'],
|
|
localKey: json['localKey'],
|
|
model: json['model'],
|
|
name: json['name'],
|
|
isOnline: json['online'],
|
|
productName: json['productName'],
|
|
timeZone: json['timeZone'],
|
|
updateTime: json['updateTime'],
|
|
uuid: json['uuid'],
|
|
productType: type,
|
|
status: [],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'activeTime': activeTime,
|
|
// 'id': id,
|
|
'localKey': localKey,
|
|
'model': model,
|
|
'name': name,
|
|
'online': isOnline,
|
|
'productName': productName,
|
|
'timeZone': timeZone,
|
|
'updateTime': updateTime,
|
|
'uuid': uuid,
|
|
'productType': productType,
|
|
};
|
|
}
|
|
|
|
List<FunctionModel> getFunctions(DeviceType type) =>
|
|
devicesFunctionsMap[productType] ?? [];
|
|
}
|