mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-24 22:57:55 +00:00
Refactor device status handling and update UI components
- Update device status handling from 'status' to 'isOnline' for consistency - Remove unused imports and redundant code related to light switches - Refactor UI components to use 'isOnline' instead of 'status' for device status
This commit is contained in:
@@ -24,9 +24,9 @@ class DevicesCategoryModel {
|
||||
//sets the initial status of the devices
|
||||
if (devices != null) {
|
||||
if (devices!.isNotEmpty) {
|
||||
bool tempStatus = devices!.first.status ?? false;
|
||||
bool tempStatus = devices!.first.isOnline ?? false;
|
||||
for (var device in devices!) {
|
||||
if (device.status != tempStatus) {
|
||||
if (device.isOnline != tempStatus) {
|
||||
devicesStatus = false;
|
||||
break;
|
||||
}
|
||||
@@ -41,9 +41,9 @@ class DevicesCategoryModel {
|
||||
DevicesCategoryModel.fromJson(Map<String, dynamic> json)
|
||||
: name = json['groupName'],
|
||||
id = json['groupId'],
|
||||
type = deviceTypeMap[json['groupName']] ?? DeviceType.Other,
|
||||
type = devicesTypesMap[json['productType']] ?? DeviceType.Other,
|
||||
icon = deviceTypeIconMap[
|
||||
deviceTypeMap[json['groupName']] ?? DeviceType.Other] ??
|
||||
devicesTypesMap[json['productType']] ?? DeviceType.Other] ??
|
||||
'',
|
||||
devices = [],
|
||||
isSelected = false;
|
||||
@@ -53,22 +53,14 @@ class DevicesCategoryModel {
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, DeviceType> deviceTypeMap = {
|
||||
'Ceiling Presence Sensors': DeviceType.Sensors,
|
||||
'Wall presence sensor': DeviceType.Sensors,
|
||||
'Door Locks': DeviceType.DoorLock,
|
||||
'Gateways': DeviceType.Gateway,
|
||||
'ACs': DeviceType.AC,
|
||||
'3Gang': DeviceType.Gang,
|
||||
};
|
||||
|
||||
Map<DeviceType, String> deviceTypeIconMap = {
|
||||
DeviceType.AC: Assets.iconsAC,
|
||||
DeviceType.Lights: Assets.iconsLight,
|
||||
DeviceType.LightBulb: Assets.iconsLight,
|
||||
DeviceType.DoorLock: Assets.iconsDoorLock,
|
||||
DeviceType.Curtain: Assets.iconsCurtain,
|
||||
DeviceType.Gateway: Assets.iconsGateway,
|
||||
DeviceType.Sensors: Assets.iconsSensors,
|
||||
DeviceType.Gang: Assets.iconsGang,
|
||||
DeviceType.CeilingSensor: Assets.iconsSensors,
|
||||
DeviceType.WallSensor: Assets.iconsSensors,
|
||||
DeviceType.ThreeGang: Assets.iconsGang,
|
||||
DeviceType.Other: Assets.iconsAC,
|
||||
};
|
||||
|
||||
@@ -1,46 +1,116 @@
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class DeviceModel {
|
||||
final int? id;
|
||||
final String? name;
|
||||
final DeviceType? type;
|
||||
bool? status;
|
||||
final String? image;
|
||||
final double? timer;
|
||||
late final String icon;
|
||||
int? activeTime;
|
||||
String? category;
|
||||
String? categoryName;
|
||||
int? createTime;
|
||||
String? gatewayId;
|
||||
String? icon;
|
||||
String? id;
|
||||
String? ip;
|
||||
double? lat;
|
||||
String? localKey;
|
||||
double? lon;
|
||||
String? model;
|
||||
String? name;
|
||||
String? nodeId; //rmeove
|
||||
bool? isOnline;
|
||||
String? ownerId; //remove
|
||||
String? productId; //remove
|
||||
String? productName;
|
||||
bool? isSub;
|
||||
String? timeZone;
|
||||
int? updateTime;
|
||||
String? uuid;
|
||||
DeviceType? productType;
|
||||
bool isSelected = false;
|
||||
|
||||
late List<FunctionModel> functions;
|
||||
|
||||
DeviceModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.image,
|
||||
required this.timer,
|
||||
required this.functions,
|
||||
this.activeTime,
|
||||
this.category,
|
||||
this.categoryName,
|
||||
this.createTime,
|
||||
this.gatewayId,
|
||||
this.icon,
|
||||
this.id,
|
||||
this.ip,
|
||||
this.lat,
|
||||
this.localKey,
|
||||
this.lon,
|
||||
this.model,
|
||||
this.name,
|
||||
this.nodeId,
|
||||
this.isOnline,
|
||||
this.ownerId,
|
||||
this.productId,
|
||||
this.productName,
|
||||
this.isSub,
|
||||
this.timeZone,
|
||||
this.updateTime,
|
||||
this.uuid,
|
||||
this.productType,
|
||||
}) {
|
||||
switch (type) {
|
||||
case DeviceType.AC:
|
||||
icon = Assets.iconsAC;
|
||||
break;
|
||||
case DeviceType.Lights:
|
||||
icon = Assets.iconsLight;
|
||||
break;
|
||||
case DeviceType.DoorLock:
|
||||
icon = Assets.iconsDoorLock;
|
||||
break;
|
||||
case DeviceType.Curtain:
|
||||
icon = Assets.iconsCurtain;
|
||||
break;
|
||||
case DeviceType.Gateway:
|
||||
icon = Assets.iconsGateway;
|
||||
break;
|
||||
default:
|
||||
icon = '';
|
||||
}
|
||||
functions = getFunctions(productType!);
|
||||
}
|
||||
|
||||
factory DeviceModel.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceModel(
|
||||
activeTime: json['activeTime'],
|
||||
category: json['category'],
|
||||
categoryName: json['categoryName'],
|
||||
createTime: json['createTime'],
|
||||
gatewayId: json['gatewayId'],
|
||||
icon: json['icon'],
|
||||
id: json['id'],
|
||||
ip: json['ip'],
|
||||
lat: double.tryParse(json['lat']),
|
||||
localKey: json['localKey'],
|
||||
lon: double.tryParse(json['lon']),
|
||||
model: json['model'],
|
||||
name: json['name'],
|
||||
nodeId: json['nodeId'],
|
||||
isOnline: json['online'],
|
||||
ownerId: json['ownerId'],
|
||||
productId: json['productId'],
|
||||
productName: json['productName'],
|
||||
isSub: json['sub'],
|
||||
timeZone: json['timeZone'],
|
||||
updateTime: json['updateTime'],
|
||||
uuid: json['uuid'],
|
||||
productType: devicesTypesMap[json['productName']] ?? DeviceType.Other,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'activeTime': activeTime,
|
||||
'category': category,
|
||||
'categoryName': categoryName,
|
||||
'createTime': createTime,
|
||||
'gatewayId': gatewayId,
|
||||
'icon': icon,
|
||||
'id': id,
|
||||
'ip': ip,
|
||||
'lat': lat,
|
||||
'localKey': localKey,
|
||||
'lon': lon,
|
||||
'model': model,
|
||||
'name': name,
|
||||
'nodeId': nodeId,
|
||||
'online': isOnline,
|
||||
'ownerId': ownerId,
|
||||
'productId': productId,
|
||||
'productName': productName,
|
||||
'sub': isSub,
|
||||
'timeZone': timeZone,
|
||||
'updateTime': updateTime,
|
||||
'uuid': uuid,
|
||||
'productType': productType,
|
||||
};
|
||||
}
|
||||
|
||||
List<FunctionModel> getFunctions(DeviceType type) =>
|
||||
devicesFunctionsMap[productType] ?? [];
|
||||
}
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
//{
|
||||
// "code": "switch_1",
|
||||
// "desc": "switch 1",
|
||||
// "name": "switch 1",
|
||||
// "type": "Boolean",
|
||||
// "values": "{}"
|
||||
// }
|
||||
class FunctionModel {
|
||||
String? code;
|
||||
String? desc;
|
||||
String? name;
|
||||
String? type;
|
||||
String? values;
|
||||
|
||||
FunctionModel({
|
||||
required this.code,
|
||||
required this.desc,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.values,
|
||||
});
|
||||
@@ -23,8 +12,6 @@ class FunctionModel {
|
||||
factory FunctionModel.fromJson(Map<String, dynamic> json) {
|
||||
return FunctionModel(
|
||||
code: json['code'],
|
||||
desc: json['desc'],
|
||||
name: json['name'],
|
||||
type: json['type'],
|
||||
values: json['values'],
|
||||
);
|
||||
@@ -33,8 +20,6 @@ class FunctionModel {
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'code': code,
|
||||
'desc': desc,
|
||||
'name': name,
|
||||
'type': type,
|
||||
'values': values,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user