This commit is contained in:
Mohammad Salameh
2024-03-17 09:38:26 +03:00
parent 8ac164f0c5
commit 65cbf10485
38 changed files with 686 additions and 901 deletions
-90
View File
@@ -1,90 +0,0 @@
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/function_model.dart';
class ACModel extends DeviceModel {
late double temperature;
late int fanSpeed;
late int tempMode;
late double coolTo;
late Bounds bounds;
ACModel({
required this.temperature,
required this.fanSpeed,
required this.tempMode,
required this.coolTo,
required this.bounds,
required super.id,
required super.name,
required super.type,
required super.status,
required super.image,
required super.timer,
required super.functions,
});
Map<String, dynamic> toJson() {
return {
'temperature': temperature,
'fanSpeed': fanSpeed,
'tempMode': tempMode,
'coolTo': coolTo,
'id': id,
'name': name,
'status': status,
'type': type,
'image': image,
};
}
factory ACModel.fromJson(Map<String, dynamic> json) {
List<FunctionModel> func = [];
if (json['functions'] != null) {
json['functions'].forEach((v) {
func.add(FunctionModel.fromJson(v));
});
}
return ACModel(
id: json['id'],
name: json['name'],
status: json['status'],
temperature: json['temperature'],
fanSpeed: json['fanSpeed'],
tempMode: json['tempMode'],
type: json['type'],
image: json['image'],
timer: json['timer'],
coolTo: json['coolTo'],
bounds: Bounds.fromJson(json['bounds']),
functions: func,
);
}
}
class Bounds {
late double min;
late double max;
Bounds({
required this.min,
required this.max,
});
Map<String, dynamic> toJson() {
return {
'min': min,
'max': max,
};
}
factory Bounds.fromJson(Map<String, dynamic> json) {
return Bounds(
min: json['min'],
max: json['max'],
);
}
}
@@ -1,48 +0,0 @@
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/function_model.dart';
class CurtainModel extends DeviceModel {
late int openPercentage;
CurtainModel({
required this.openPercentage,
required super.id,
required super.name,
required super.type,
required super.status,
required super.image,
required super.timer,
required super.functions,
});
Map<String, dynamic> toJson() {
return {
'openPercentage': openPercentage,
'timer': timer,
'id': id,
'name': name,
'status': status,
'type': type,
'image': image,
};
}
factory CurtainModel.fromJson(Map<String, dynamic> json) {
List<FunctionModel> func = [];
if (json['functions'] != null) {
json['functions'].forEach((v) {
func.add(FunctionModel.fromJson(v));
});
}
return CurtainModel(
id: json['id'],
name: json['name'],
status: json['status'],
openPercentage: json['openPercentage'],
timer: json['timer'],
type: json['type'],
image: json['image'],
functions: func,
);
}
}
@@ -1,38 +1,55 @@
// ignore_for_file: constant_identifier_names
import 'package:flutter/cupertino.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class DevicesCategoryModel {
final String name;
final String icon;
final Widget page;
int? id;
final String? name;
final String? icon;
bool? devicesStatus;
final List<DeviceModel> devices;
final List<DeviceModel>? devices;
final DeviceType type;
final DeviceType? type;
bool isSelected;
DevicesCategoryModel(
{this.isSelected = false,
required this.page,
required this.type,
required this.name,
required this.icon,
required this.devices}) {
//sets the initial status of the devices
if (devices.isNotEmpty) {
bool tempStatus = devices.first.status ?? false;
for (var device in devices) {
if (device.status != tempStatus) {
devicesStatus = false;
break;
if (devices != null) {
if (devices!.isNotEmpty) {
bool tempStatus = devices!.first.status ?? false;
for (var device in devices!) {
if (device.status != tempStatus) {
devicesStatus = false;
break;
}
}
devicesStatus = tempStatus;
}
devicesStatus = tempStatus;
} else {
devicesStatus = false;
}
}
DevicesCategoryModel.fromJson(Map<String, dynamic> json)
: name = json['groupName'],
id = json['groupId'],
icon = json['icon'],
type = deviceTypeMap[json['groupName']] ?? DeviceType.Other,
devices = [],
isSelected = false;
}
Map<String, DeviceType> deviceTypeMap = {
'Ceiling Presence Sensors': DeviceType.Sensors,
'Wall presence sensor': DeviceType.Sensors,
'Door Locks': DeviceType.DoorLock,
'Gateways': DeviceType.Gateway,
'ACs': DeviceType.AC,
};
+1 -1
View File
@@ -30,7 +30,7 @@ class DeviceModel {
case DeviceType.Lights:
icon = Assets.iconsLight;
break;
case DeviceType.Door:
case DeviceType.DoorLock:
icon = Assets.iconsDoorLock;
break;
case DeviceType.Curtain:
@@ -1,62 +0,0 @@
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/function_model.dart';
class LightModel extends DeviceModel {
late double brightness;
late int color;
late int lightingMode;
late List<int> recentColors;
LightModel({
required this.brightness,
required this.color,
required this.lightingMode,
required this.recentColors,
required super.id,
required super.name,
required super.type,
required super.status,
required super.image,
required super.timer,
required super.functions,
});
Map<String, dynamic> toJson() {
return {
'luminance': brightness,
'color': color,
'lightingMode': lightingMode,
'timer': timer,
'recentColors': recentColors,
'id': id,
'name': name,
'status': status,
'type': type,
'image': image,
};
}
factory LightModel.fromJson(Map<String, dynamic> json) {
List<FunctionModel> func = [];
if (json['functions'] != null) {
json['functions'].forEach((v) {
func.add(FunctionModel.fromJson(v));
});
}
return LightModel(
id: json['id'],
name: json['name'],
status: json['status'],
brightness: json['luminance'],
color: json['color'],
lightingMode: json['lightingMode'],
timer: json['timer'],
type: json['type'],
image: json['image'],
recentColors: json['recentColors'],
functions: func,
);
}
}