Added ac bounds in model

implemented bounds in AC Temp controls
This commit is contained in:
Mohammad Salameh
2024-03-04 15:55:02 +03:00
parent 49b24e14eb
commit 282739acf7
3 changed files with 47 additions and 1 deletions
+3 -1
View File
@@ -31,7 +31,9 @@ class AcCubit extends Cubit<AcState> {
}
void setACTemp(ACModel model, double temp) {
model.temperature = temp;
if (model.bounds.min <= temp && temp <= model.bounds.max) {
model.temperature = temp;
}
emit(ACsTempChanged(temp));
}
@@ -35,6 +35,10 @@ class DevicesCubit extends Cubit<DevicesState> {
location: '',
image: '',
timer: null,
bounds: Bounds(
min: 20,
max: 30,
),
),
ACModel(
name: "Master Bedroom AC",
@@ -48,6 +52,10 @@ class DevicesCubit extends Cubit<DevicesState> {
location: '',
image: '',
timer: null,
bounds: Bounds(
min: 20,
max: 30,
),
),
ACModel(
name: "Kitchen AC",
@@ -61,6 +69,10 @@ class DevicesCubit extends Cubit<DevicesState> {
location: '',
image: '',
timer: null,
bounds: Bounds(
min: 20,
max: 30,
),
),
ACModel(
name: "Bathroom AC",
@@ -74,6 +86,10 @@ class DevicesCubit extends Cubit<DevicesState> {
location: '',
image: '',
timer: null,
bounds: Bounds(
min: 20,
max: 30,
),
),
],
icon: Assets.iconsAC,
+28
View File
@@ -9,11 +9,14 @@ class ACModel extends DeviceModel {
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,
@@ -51,6 +54,31 @@ class ACModel extends DeviceModel {
image: json['image'],
timer: json['timer'],
coolTo: json['coolTo'],
bounds: Bounds.fromJson(json['bounds']),
);
}
}
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'],
);
}
}