added devices

This commit is contained in:
ashrafzarkanisala
2024-11-16 23:58:33 +03:00
parent a6e2681b6a
commit 16dd95c8d1
23 changed files with 1117 additions and 114 deletions

View File

@ -3,6 +3,7 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/device_spa
import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/enum/device_types.dart';
class AllDevicesModel {
/*
@ -100,12 +101,8 @@ class AllDevicesModel {
this.spaces,
});
AllDevicesModel.fromJson(Map<String, dynamic> json) {
room = (json['room'] != null && (json['room'] is Map))
? DevicesModelRoom.fromJson(json['room'])
: null;
unit = (json['unit'] != null && (json['unit'] is Map))
? DevicesModelUnit.fromJson(json['unit'])
: null;
room = (json['room'] != null && (json['room'] is Map)) ? DevicesModelRoom.fromJson(json['room']) : null;
unit = (json['unit'] != null && (json['unit'] is Map)) ? DevicesModelUnit.fromJson(json['unit']) : null;
community = (json['community'] != null && (json['community'] is Map))
? DeviceCommunityModel.fromJson(json['community'])
: null;
@ -117,7 +114,7 @@ class AllDevicesModel {
categoryName = json['categoryName']?.toString();
createTime = int.tryParse(json['createTime']?.toString() ?? '');
gatewayId = json['gatewayId']?.toString();
icon = json['icon'] ?? _getDefaultIcon(productType);
icon = json['icon'] ?? getDefaultIcon(productType);
ip = json['ip']?.toString();
lat = json['lat']?.toString();
localKey = json['localKey']?.toString();
@ -134,38 +131,88 @@ class AllDevicesModel {
batteryLevel = int.tryParse(json['battery']?.toString() ?? '');
productName = json['productName']?.toString();
if (json['spaces'] != null && json['spaces'] is List) {
spaces = (json['spaces'] as List)
.map((space) => DeviceSpaceModel.fromJson(space))
.toList();
spaces = (json['spaces'] as List).map((space) => DeviceSpaceModel.fromJson(space)).toList();
}
}
String _getDefaultIcon(String? productType) {
switch (productType) {
case 'LightBulb':
return Assets.lightBulb;
case 'CeilingSensor':
case 'WallSensor':
return Assets.sensors;
case 'AC':
return Assets.ac;
case 'DoorLock':
return Assets.doorLock;
case 'Curtain':
return Assets.curtain;
case '3G':
case '2G':
case '1G':
return Assets.gangSwitch;
case 'Gateway':
return Assets.gateway;
case 'WH':
return Assets.blackLogo;
case 'DS':
return Assets.sensors;
default:
return Assets.logo;
String getDefaultIcon(String? productType) {
/*
AC
GD
3G
3G
GW
DL
WPS
CPS
AC
CPS
WPS
GW
AC
CUR
DS
1GT
2GT
3GT
1G
1G
2G
2G
DS
WH
1GT
2GT
3GT
GD
WL
WL
3G
CUR
GW
PC
PC
SOS
*/
DeviceType type = devicesTypesMap[productType] ?? DeviceType.Other;
String tempIcon = '';
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 if (type == DeviceType.OneGang) {
tempIcon = Assets.oneGang;
} else if (type == DeviceType.TwoGang) {
tempIcon = Assets.twoGang;
} else if (type == DeviceType.WH) {
tempIcon = Assets.waterHeater;
} else if (type == DeviceType.DS) {
// tempIcon = Assets.mainDoor;
} else if (type == DeviceType.OneTouch) {
// tempIcon = Assets.oneGang;
} else if (type == DeviceType.TowTouch) {
// tempIcon = Assets.twoGang;
} else if (type == DeviceType.GarageDoor) {
//tempIcon = Assets.;
} else if (type == DeviceType.ThreeTouch) {
// tempIcon = Assets.gang3touch;
} else if (type == DeviceType.WaterLeak) {
tempIcon = Assets.waterLeakNormal;
} else {
tempIcon = Assets.logoHorizontal;
}
return tempIcon;
}
Map<String, dynamic> toJson() {
@ -271,4 +318,23 @@ class AllDevicesModel {
productName.hashCode ^
batteryLevel.hashCode;
}
Map<String, DeviceType> devicesTypesMap = {
"AC": DeviceType.AC,
"GW": DeviceType.Gateway,
"CPS": DeviceType.CeilingSensor,
"DL": DeviceType.DoorLock,
"WPS": DeviceType.WallSensor,
"3G": DeviceType.ThreeGang,
"2G": DeviceType.TwoGang,
"1G": DeviceType.OneGang,
"CUR": DeviceType.Curtain,
"WH": DeviceType.WH,
"DS": DeviceType.DS,
"1GT": DeviceType.OneTouch,
"2GT": DeviceType.TowTouch,
"3GT": DeviceType.ThreeTouch,
"GD": DeviceType.GarageDoor,
"WL": DeviceType.WaterLeak,
};
}