mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
109 lines
3.1 KiB
Dart
109 lines
3.1 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;
|
|
String? type;
|
|
bool? isOnline;
|
|
List<StatusModel> status = [];
|
|
String? productName;
|
|
String? timeZone;
|
|
int? updateTime;
|
|
String? uuid;
|
|
String? productUuid;
|
|
DeviceType? productType;
|
|
bool isSelected = false;
|
|
late List<FunctionModel> functions;
|
|
DeviceModel(
|
|
{this.activeTime,
|
|
this.productUuid,
|
|
this.localKey,
|
|
this.model,
|
|
this.name,
|
|
this.isOnline,
|
|
required this.status,
|
|
this.productName,
|
|
this.timeZone,
|
|
this.updateTime,
|
|
this.uuid,
|
|
this.productType,
|
|
this.icon,
|
|
this.type}) {
|
|
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.assetsIconsLight;
|
|
} else if (type == DeviceType.CeilingSensor ||
|
|
type == DeviceType.WallSensor) {
|
|
tempIcon = Assets.assetsIconsSensors;
|
|
} else if (type == DeviceType.AC) {
|
|
tempIcon = Assets.assetsIconsAC;
|
|
} else if (type == DeviceType.DoorLock) {
|
|
tempIcon = Assets.assetsIconsDoorLock;
|
|
} else if (type == DeviceType.Curtain) {
|
|
tempIcon = Assets.assetsIconsCurtain;
|
|
} else if (type == DeviceType.ThreeGang) {
|
|
tempIcon = Assets.assetsIcons3GangSwitch;
|
|
} else if (type == DeviceType.Gateway) {
|
|
tempIcon = Assets.assetsIconsGateway;
|
|
} else if (type == DeviceType.OneGang) {
|
|
tempIcon = Assets.oneGang;
|
|
} else if (type == DeviceType.TwoGang) {
|
|
tempIcon = Assets.twoGang;
|
|
} else if (type == DeviceType.WH) {
|
|
tempIcon = Assets.waterHeaterIcon;
|
|
} else if (type == DeviceType.DS) {
|
|
tempIcon = Assets.doorSensorIcon;
|
|
} else {
|
|
tempIcon = Assets.assetsIconsLogo;
|
|
}
|
|
|
|
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,
|
|
type: json['productType'],
|
|
status: [],
|
|
productUuid: json['productUuid']);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'activeTime': activeTime,
|
|
'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] ?? [];
|
|
}
|