Files
syncrow-web/lib/pages/visitor_password/model/device_model.dart
2024-08-28 14:50:47 +03:00

122 lines
3.2 KiB
Dart

import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/enum/device_types.dart';
import 'package:syncrow_web/utils/constants/app_enum.dart';
class DeviceModel {
dynamic productUuid;
dynamic productType;
dynamic activeTime;
dynamic category;
dynamic categoryName;
dynamic createTime;
dynamic gatewayId;
dynamic icon;
dynamic ip;
dynamic lat;
dynamic localKey;
dynamic lon;
dynamic model;
dynamic name;
DeviseStatus online;
dynamic ownerId;
dynamic sub;
dynamic timeZone;
dynamic updateTime;
dynamic uuid;
DeviceModel({
required this.productUuid,
required this.productType,
required this.activeTime,
required this.category,
required this.categoryName,
required this.createTime,
required this.gatewayId,
required this.icon,
required this.ip,
required this.lat,
required this.localKey,
required this.lon,
required this.model,
required this.name,
required this.online,
required this.ownerId,
required this.sub,
required this.timeZone,
required this.updateTime,
required this.uuid,
});
// Deserialize from JSON
factory DeviceModel.fromJson(Map<String, dynamic> json) {
String tempIcon = '';
DeviceType type = devicesTypesMap[json['productType']] ?? DeviceType.Other;
if (type == DeviceType.LightBulb) {
tempIcon = Assets.lightBulb;
} else if (type == DeviceType.CeilingSensor || type == DeviceType.WallSensor) {
tempIcon = Assets.sensors;
} else if (type == DeviceType.AC) {
tempIcon = Assets.ac;
} else if (type == DeviceType.DoorLock) {
tempIcon = Assets.doorLock;
} else if (type == DeviceType.Curtain) {
tempIcon = Assets.curtain;
} else if (type == DeviceType.ThreeGang) {
tempIcon = Assets.gangSwitch;
} else if (type == DeviceType.Gateway) {
tempIcon = Assets.gateway;
} else {
tempIcon = Assets.logo;
}
return DeviceModel(
productUuid: json['productUuid'],
productType: json['productType'],
activeTime: json['activeTime'],
category: json['category'],
categoryName: json['categoryName'],
createTime: json['createTime'],
gatewayId: json['gatewayId'],
icon: tempIcon,
ip: json['ip'],
lat: json['lat'],
localKey: json['localKey'],
lon: json['lon'],
model: json['model'],
name: json['name'],
online: OnlineTypeExtension.fromString(json['online']),
ownerId: json['ownerId'],
sub: json['sub'],
timeZone: json['timeZone'],
updateTime: json['updateTime'],
uuid: json['uuid'],
);
}
// Serialize to JSON
Map<String, dynamic> toJson() {
return {
'productUuid': productUuid,
'productType': productType,
'activeTime': activeTime,
'category': category,
'categoryName': categoryName,
'createTime': createTime,
'gatewayId': gatewayId,
'icon': icon,
'ip': ip,
'lat': lat,
'localKey': localKey,
'lon': lon,
'model': model,
'name': name,
'online': online,
'ownerId': ownerId,
'sub': sub,
'timeZone': timeZone,
'updateTime': updateTime,
'uuid': uuid,
};
}
}