From 282739acf7417029254ff95edad58703054203fb Mon Sep 17 00:00:00 2001 From: Mohammad Salameh Date: Mon, 4 Mar 2024 15:55:02 +0300 Subject: [PATCH] Added ac bounds in model implemented bounds in AC Temp controls --- lib/features/devices/bloc/ac/ac_cubit.dart | 4 ++- lib/features/devices/bloc/devices_cubit.dart | 16 +++++++++++ lib/features/devices/model/ac_model.dart | 28 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/features/devices/bloc/ac/ac_cubit.dart b/lib/features/devices/bloc/ac/ac_cubit.dart index 5010649..699e12f 100644 --- a/lib/features/devices/bloc/ac/ac_cubit.dart +++ b/lib/features/devices/bloc/ac/ac_cubit.dart @@ -31,7 +31,9 @@ class AcCubit extends Cubit { } void setACTemp(ACModel model, double temp) { - model.temperature = temp; + if (model.bounds.min <= temp && temp <= model.bounds.max) { + model.temperature = temp; + } emit(ACsTempChanged(temp)); } diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index df14719..59e7eee 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -35,6 +35,10 @@ class DevicesCubit extends Cubit { location: '', image: '', timer: null, + bounds: Bounds( + min: 20, + max: 30, + ), ), ACModel( name: "Master Bedroom AC", @@ -48,6 +52,10 @@ class DevicesCubit extends Cubit { location: '', image: '', timer: null, + bounds: Bounds( + min: 20, + max: 30, + ), ), ACModel( name: "Kitchen AC", @@ -61,6 +69,10 @@ class DevicesCubit extends Cubit { location: '', image: '', timer: null, + bounds: Bounds( + min: 20, + max: 30, + ), ), ACModel( name: "Bathroom AC", @@ -74,6 +86,10 @@ class DevicesCubit extends Cubit { location: '', image: '', timer: null, + bounds: Bounds( + min: 20, + max: 30, + ), ), ], icon: Assets.iconsAC, diff --git a/lib/features/devices/model/ac_model.dart b/lib/features/devices/model/ac_model.dart index e81b234..8da6acd 100644 --- a/lib/features/devices/model/ac_model.dart +++ b/lib/features/devices/model/ac_model.dart @@ -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 toJson() { + return { + 'min': min, + 'max': max, + }; + } + + factory Bounds.fromJson(Map json) { + return Bounds( + min: json['min'], + max: json['max'], ); } }