diff --git a/.env.dev b/.env.dev
deleted file mode 100644
index e69de29..0000000
diff --git a/.env.development b/.env.development
new file mode 100644
index 0000000..e77609d
--- /dev/null
+++ b/.env.development
@@ -0,0 +1,2 @@
+ENV_NAME=development
+BASE_URL=https://syncrow-dev.azurewebsites.net
\ No newline at end of file
diff --git a/.env.prod b/.env.prod
deleted file mode 100644
index e69de29..0000000
diff --git a/.env.production b/.env.production
new file mode 100644
index 0000000..4e9dcb8
--- /dev/null
+++ b/.env.production
@@ -0,0 +1,2 @@
+ENV_NAME=production
+BASE_URL=https://syncrow-staging.azurewebsites.net
\ No newline at end of file
diff --git a/.env.staging b/.env.staging
index e69de29..9565b42 100644
--- a/.env.staging
+++ b/.env.staging
@@ -0,0 +1,2 @@
+ENV_NAME=staging
+BASE_URL=https://syncrow-staging.azurewebsites.net
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index add5842..c3e0679 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,7 @@ migrate_working_dir/
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
-
+*.env
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 9287665..ad16c69 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -2,12 +2,17 @@
+
+
+
+
+
+ android:allowBackup="false">
+ NSPhotoLibraryUsageDescription
+ We need access to your photo library to allow you to select and upload photos.
CADisableMinimumFrameDurationOnPhone
CFBundleDevelopmentRegion
diff --git a/lib/features/app_layout/bloc/home_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart
index faa4f7b..a313f02 100644
--- a/lib/features/app_layout/bloc/home_cubit.dart
+++ b/lib/features/app_layout/bloc/home_cubit.dart
@@ -27,6 +27,7 @@ import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/navigation/navigation_service.dart';
import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/services/api/devices_api.dart';
+import 'package:syncrow_app/services/api/profile_api.dart';
import 'package:syncrow_app/services/api/spaces_api.dart';
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
@@ -38,6 +39,7 @@ part 'home_state.dart';
class HomeCubit extends Cubit {
HomeCubit._() : super(HomeInitial()) {
checkIfNotificationPermissionGranted();
+ fetchUserInfo();
if (selectedSpace == null) {
fetchUnitsByUserId();
// .then((value) {
@@ -47,7 +49,7 @@ class HomeCubit extends Cubit {
// });
}
}
-
+ static UserModel? user;
static HomeCubit? _instance;
static HomeCubit getInstance() {
// If an instance already exists, return it
@@ -55,6 +57,18 @@ class HomeCubit extends Cubit {
return _instance!;
}
+
+ Future fetchUserInfo() async {
+ try {
+ var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
+ user = await ProfileApi().fetchUserInfo(uuid);
+ emit(HomeUserInfoLoaded(user!)); // Emit state after fetching user info
+
+ } catch (e) {
+ return;
+ }
+ }
+
void emitSafe(HomeState newState) {
final cubit = this;
if (!cubit.isClosed) {
diff --git a/lib/features/app_layout/bloc/home_state.dart b/lib/features/app_layout/bloc/home_state.dart
index 9c20d4e..1125e01 100644
--- a/lib/features/app_layout/bloc/home_state.dart
+++ b/lib/features/app_layout/bloc/home_state.dart
@@ -58,3 +58,9 @@ class RoomSelected extends HomeState {
class RoomUnSelected extends HomeState {}
class NavChangePage extends HomeState {}
+// Define new state classes
+class HomeUserInfoLoaded extends HomeState {
+ final UserModel user;
+
+ HomeUserInfoLoaded(this.user);
+}
diff --git a/lib/features/auth/bloc/auth_cubit.dart b/lib/features/auth/bloc/auth_cubit.dart
index 2b9f14b..5f05563 100644
--- a/lib/features/auth/bloc/auth_cubit.dart
+++ b/lib/features/auth/bloc/auth_cubit.dart
@@ -1,3 +1,4 @@
+
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
@@ -8,6 +9,7 @@ import 'package:syncrow_app/features/auth/model/user_model.dart';
import 'package:syncrow_app/navigation/navigation_service.dart';
import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/services/api/authentication_api.dart';
+import 'package:syncrow_app/services/api/profile_api.dart';
import 'package:syncrow_app/utils/helpers/shared_preferences_helper.dart';
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
@@ -62,7 +64,8 @@ class AuthCubit extends Cubit {
return 'Please enter your password';
}
if (value.isNotEmpty) {
- if (!RegExp(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$')
+ if (!RegExp(
+ r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~])[A-Za-z\d!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]{8,}$')
.hasMatch(value)) {
return 'Password must contain at least:\n - one uppercase letter.\n - one lowercase letter.\n - one number. \n - special character';
}
@@ -178,12 +181,14 @@ class AuthCubit extends Cubit {
if (token.accessTokenIsNotEmpty) {
debugPrint('token: ${token.accessToken}');
FlutterSecureStorage storage = const FlutterSecureStorage();
- await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken);
-
+ await storage.write(
+ key: Token.loginAccessTokenKey,
+ value: token.accessToken
+ );
const FlutterSecureStorage().write(
key: UserModel.userUuidKey,
- value: Token.decodeToken(token.accessToken)['uuid'].toString());
-
+ value: Token.decodeToken(token.accessToken)['uuid'].toString()
+ );
user = UserModel.fromToken(token);
emailController.clear();
passwordController.clear();
@@ -277,8 +282,7 @@ class AuthCubit extends Cubit {
try {
emit(AuthTokenLoading());
const storage = FlutterSecureStorage();
- final firstLaunch =
- await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
+ final firstLaunch = await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
if (firstLaunch) {
storage.deleteAll();
@@ -311,6 +315,7 @@ class AuthCubit extends Cubit {
}
}
+
sendToForgetPassword({required String password}) async {
try {
emit(AuthForgetPassLoading());
@@ -320,4 +325,8 @@ class AuthCubit extends Cubit {
emit(AuthForgetPassError(message: 'Something went wrong'));
}
}
+
+
+
+
}
diff --git a/lib/features/auth/model/user_model.dart b/lib/features/auth/model/user_model.dart
index 5491d73..fd68fb4 100644
--- a/lib/features/auth/model/user_model.dart
+++ b/lib/features/auth/model/user_model.dart
@@ -1,63 +1,81 @@
+import 'dart:convert';
+
+import 'package:flutter/foundation.dart';
import 'package:syncrow_app/features/auth/model/token.dart';
class UserModel {
static String userUuidKey = 'userUuid';
final String? uuid;
final String? email;
- final String? name;
- final String? photoUrl;
-
+ final String? firstName;
+ final String? lastName;
+ final Uint8List? profilePicture;
final String? phoneNumber;
-
final bool? isEmailVerified;
-
+ final String? regionName;
+ final String? timeZone;
final bool? isAgreementAccepted;
UserModel({
required this.uuid,
required this.email,
- required this.name,
- required this.photoUrl,
+ required this.firstName,
+ required this.lastName,
+ required this.profilePicture,
required this.phoneNumber,
required this.isEmailVerified,
required this.isAgreementAccepted,
+ required this.regionName, // Add this line
+ required this.timeZone, // Add this line
+
});
factory UserModel.fromJson(Map json) {
return UserModel(
- uuid: json['id'],
+ uuid: json['uuid'],
email: json['email'],
- name: json['name'],
- photoUrl: json['photoUrl'],
+ firstName: json['firstName'],
+ lastName: json['lastName'],
+ profilePicture: UserModel.decodeBase64Image(json['profilePicture']),
phoneNumber: json['phoneNumber'],
isEmailVerified: json['isEmailVerified'],
isAgreementAccepted: json['isAgreementAccepted'],
+ regionName: json['region']?['regionName'], // Extract regionName
+ timeZone: json['timeZone']?['timeZoneOffset'], // Extract regionName
);
}
-
//uuid to json
-
//from token
- factory UserModel.fromToken(Token token) {
+ factory UserModel.fromToken(Token token) {
Map tempJson = Token.decodeToken(token.accessToken);
-
return UserModel(
uuid: tempJson['uuid'].toString(),
email: tempJson['email'],
- name: null,
- photoUrl: null,
+ lastName: tempJson['lastName'],
+ firstName:tempJson['firstName'] ,
+ profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']),
phoneNumber: null,
isEmailVerified: null,
isAgreementAccepted: null,
+ regionName: tempJson['region']?['regionName'],
+ timeZone: tempJson['timezone']?['timeZoneOffset'],
);
}
+ static Uint8List? decodeBase64Image(String? base64String) {
+ if (base64String != null) {
+ return base64.decode(base64String);
+ }
+ return null;
+ }
+
Map toJson() {
return {
'id': uuid,
'email': email,
- 'name': name,
- 'photoUrl': photoUrl,
+ 'lastName': lastName,
+ 'firstName': firstName,
+ 'photoUrl': profilePicture,
'phoneNumber': phoneNumber,
'isEmailVerified': isEmailVerified,
'isAgreementAccepted': isAgreementAccepted,
diff --git a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart
index b8dad95..8603f98 100644
--- a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart
+++ b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
@@ -12,6 +14,7 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
class ACsBloc extends Bloc {
final String acId;
AcStatusModel deviceStatus = AcStatusModel(
+ uuid: '',
acSwitch: true,
modeString: 'hot',
tempSet: 300,
@@ -24,6 +27,7 @@ class ACsBloc extends Bloc {
bool allAcsOn = true;
bool allTempSame = true;
int globalTemp = 25;
+ Timer? _timer;
ACsBloc({required this.acId}) : super(AcsInitialState()) {
on(_fetchAcsStatus);
@@ -56,11 +60,11 @@ class ACsBloc extends Bloc {
for (var status in response['status']) {
statusModelList.add(StatusModel.fromJson(status));
}
- deviceStatus = AcStatusModel.fromJson(statusModelList);
+ deviceStatus = AcStatusModel.fromJson(response['productUuid'], statusModelList);
emit(GetAcStatusState(acStatusModel: deviceStatus));
}
} catch (e) {
- emit(AcsFailedState(error: e.toString()));
+ emit(AcsFailedState(errorMessage: e.toString()));
return;
}
}
@@ -68,8 +72,6 @@ class ACsBloc extends Bloc {
_getAllAcs() async {
deviceStatusList = [];
devicesList = [];
- allAcsOn = true;
- allTempSame = true;
devicesList = await DevicesAPI.getDeviceByGroupName(
HomeCubit.getInstance().selectedSpace?.id ?? '', 'AC');
@@ -79,8 +81,210 @@ class ACsBloc extends Bloc {
for (var status in response['status']) {
statusModelList.add(StatusModel.fromJson(status));
}
- deviceStatusList.add(AcStatusModel.fromJson(statusModelList));
+ deviceStatusList.add(AcStatusModel.fromJson(response['productUuid'], statusModelList));
}
+ _setAllAcsTempsAndSwitches();
+ }
+
+ void _changeAcSwitch(AcSwitch event, Emitter emit) async {
+ final acSwitchValue = !event.acSwitch;
+ if (allAcsPage) {
+ emit(AcsLoadingState());
+ for (AcStatusModel ac in deviceStatusList) {
+ if (ac.uuid == event.productId) {
+ ac.acSwitch = acSwitchValue;
+ }
+ }
+ _setAllAcsTempsAndSwitches();
+ _emitAcsStatus(emit);
+ } else {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+ deviceStatus.acSwitch = acSwitchValue;
+ emit(AcModifyingState(acStatusModel: deviceStatus));
+ }
+
+ await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'switch', value: acSwitchValue);
+ }
+
+ void _changeAllAcSwitch(ChangeAllSwitch event, Emitter emit) async {
+ emit(AcsLoadingState());
+ if (deviceStatusList.length == devicesList.length) {
+ for (int i = 0; i < deviceStatusList.length; i++) {
+ deviceStatusList[i].acSwitch = event.value;
+ }
+ }
+ _setAllAcsTempsAndSwitches();
+ _emitAcsStatus(emit);
+ _runDeBouncerForAllAcs(code: 'switch', value: event.value);
+ }
+
+ void _increaseAllTemp(IncreaseAllTemp event, Emitter emit) async {
+ emit(AcsLoadingState());
+ double tempValue = event.value + 0.5;
+ int value = (tempValue * 10).toInt();
+
+ if (!_checkTemperatureValue(tempValue, emit)) {
+ return;
+ }
+
+ if (deviceStatusList.length == devicesList.length) {
+ for (int i = 0; i < deviceStatusList.length; i++) {
+ deviceStatusList[i].tempSet = value;
+ }
+ }
+ _setAllAcsTempsAndSwitches();
+ _emitAcsStatus(emit);
+ _runDeBouncerForAllAcs(code: 'temp_set', value: value);
+ }
+
+ void _decreaseAllTemp(DecreaseAllTemp event, Emitter emit) async {
+ emit(AcsLoadingState());
+
+ double tempValue = event.value - 0.5;
+ int value = (tempValue * 10).toInt();
+
+ if (!_checkTemperatureValue(tempValue, emit)) {
+ return;
+ }
+
+ if (deviceStatusList.length == devicesList.length) {
+ for (int i = 0; i < deviceStatusList.length; i++) {
+ deviceStatusList[i].tempSet = value;
+ }
+ }
+ _setAllAcsTempsAndSwitches();
+ _emitAcsStatus(emit);
+ _runDeBouncerForAllAcs(code: 'temp_set', value: value);
+ }
+
+ void _changeLockValue(ChangeLock event, Emitter emit) async {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+
+ final lockValue = !event.lockBool;
+ deviceStatus.childLock = lockValue;
+ emit(AcModifyingState(acStatusModel: deviceStatus));
+
+ _runDeBouncerForOneDevice(deviceId: acId, code: 'child_lock', value: lockValue);
+ }
+
+ void _increaseCoolTo(IncreaseCoolToTemp event, Emitter emit) async {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+
+ double tempValue = event.value + 0.5;
+ int value = (tempValue * 10).toInt();
+
+ if (!_checkTemperatureValue(tempValue, emit)) {
+ return;
+ }
+
+ if (allAcsPage) {
+ emit(AcsLoadingState());
+ for (AcStatusModel ac in deviceStatusList) {
+ if (ac.uuid == event.productId) {
+ ac.tempSet = value;
+ }
+ }
+ _setAllAcsTempsAndSwitches();
+ _emitAcsStatus(emit);
+ } else {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+ deviceStatus.tempSet = value;
+ emit(AcModifyingState(acStatusModel: deviceStatus));
+ }
+
+ await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'temp_set', value: value);
+ }
+
+ void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter emit) async {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+
+ double tempValue = event.value - 0.5;
+ int value = (tempValue * 10).toInt();
+
+ if (!_checkTemperatureValue(tempValue, emit)) {
+ return;
+ }
+
+ if (allAcsPage) {
+ emit(AcsLoadingState());
+ for (AcStatusModel ac in deviceStatusList) {
+ if (ac.uuid == event.productId) {
+ ac.tempSet = value;
+ }
+ }
+ _setAllAcsTempsAndSwitches();
+ _emitAcsStatus(emit);
+ } else {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+ deviceStatus.tempSet = value;
+ emit(AcModifyingState(acStatusModel: deviceStatus));
+ }
+
+ await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'temp_set', value: value);
+ }
+
+ void _changeAcMode(ChangeAcMode event, Emitter emit) async {
+ final tempMode = tempModesMap[getNextItem(tempModesMap, event.tempModes)]!;
+ if (allAcsPage) {
+ emit(AcsLoadingState());
+ for (AcStatusModel ac in deviceStatusList) {
+ if (ac.uuid == event.productId) {
+ ac.modeString = getACModeString(tempMode);
+ ac.acMode = AcStatusModel.getACMode(getACModeString(tempMode));
+ }
+ }
+ _emitAcsStatus(emit);
+ } else {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+ deviceStatus.modeString = getACModeString(tempMode);
+ deviceStatus.acMode = AcStatusModel.getACMode(getACModeString(tempMode));
+ emit(AcModifyingState(acStatusModel: deviceStatus));
+ }
+
+ await _runDeBouncerForOneDevice(
+ deviceId: event.deviceId, code: 'mode', value: getACModeString(tempMode));
+ }
+
+ void _changeFanSpeed(ChangeFanSpeed event, Emitter emit) async {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+
+ final fanSpeed = event.fanSpeeds;
+
+ if (allAcsPage) {
+ emit(AcsLoadingState());
+ for (AcStatusModel ac in deviceStatusList) {
+ if (ac.uuid == event.productId) {
+ ac.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
+ ac.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
+ }
+ }
+ _emitAcsStatus(emit);
+ } else {
+ emit(AcChangeLoading(acStatusModel: deviceStatus));
+ deviceStatus.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
+ deviceStatus.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
+ emit(AcModifyingState(acStatusModel: deviceStatus));
+ }
+
+ await _runDeBouncerForOneDevice(
+ deviceId: event.deviceId, code: 'level', value: getNextFanSpeedKey(fanSpeed));
+ }
+
+ String getACModeString(TempModes value) {
+ if (value == TempModes.cold) {
+ return 'cold';
+ } else if (value == TempModes.hot) {
+ return 'hot';
+ } else if (value == TempModes.wind) {
+ return 'wind';
+ } else {
+ return 'cold';
+ }
+ }
+
+ void _setAllAcsTempsAndSwitches() {
+ allAcsOn = true;
+ allTempSame = true;
if (deviceStatusList.isNotEmpty) {
int temp = deviceStatusList[0].tempSet;
deviceStatusList.firstWhere((element) {
@@ -99,195 +303,71 @@ class ACsBloc extends Bloc {
}
}
- void _changeAcSwitch(AcSwitch event, Emitter emit) async {
- emit(AcChangeLoading(acStatusModel: deviceStatus));
-
- final acSwitchValue = !event.acSwitch;
- try {
- final response = await DevicesAPI.controlDevice(
- DeviceControlModel(
- deviceId: allAcsPage ? event.deviceId : acId, code: 'switch', value: acSwitchValue),
- allAcsPage ? event.deviceId : acId);
-
- if (response['success'] ?? false) {
- deviceStatus.acSwitch = acSwitchValue;
- }
- } catch (_) {}
- if (allAcsPage) {
- await Future.delayed(const Duration(seconds: 1));
- add(const AcsInitial(allAcs: true));
- } else {
- emit(AcModifyingState(acStatusModel: deviceStatus));
+ _runDeBouncerForAllAcs({required String code, required dynamic value}) {
+ if (_timer != null) {
+ _timer!.cancel();
}
- }
-
- void _changeAllAcSwitch(ChangeAllSwitch event, Emitter emit) async {
- emit(AcsLoadingState());
- try {
+ _timer = Timer(const Duration(seconds: 1), () async {
if (deviceStatusList.length == devicesList.length) {
for (int i = 0; i < deviceStatusList.length; i++) {
- await DevicesAPI.controlDevice(
- DeviceControlModel(deviceId: devicesList[i].uuid, code: 'switch', value: event.value),
- devicesList[i].uuid ?? '');
+ try {
+ await DevicesAPI.controlDevice(
+ DeviceControlModel(deviceId: devicesList[i].uuid, code: code, value: value),
+ devicesList[i].uuid ?? '');
+ } catch (_) {
+ await Future.delayed(const Duration(milliseconds: 500));
+ add(const AcsInitial(allAcs: true));
+ }
}
}
- } catch (_) {}
- await Future.delayed(const Duration(seconds: 1));
- add(const AcsInitial(allAcs: true));
+ });
}
- void _increaseAllTemp(IncreaseAllTemp event, Emitter emit) async {
- emit(AcsLoadingState());
- try {
- double tempValue = event.value + 0.5;
- int value = (tempValue * 10).toInt();
- if (deviceStatusList.length == devicesList.length) {
- for (int i = 0; i < deviceStatusList.length; i++) {
- await DevicesAPI.controlDevice(
- DeviceControlModel(deviceId: devicesList[i].uuid, code: 'temp_set', value: value),
- devicesList[i].uuid ?? '');
+ _runDeBouncerForOneDevice({
+ required String deviceId,
+ required String code,
+ required dynamic value,
+ }) {
+ if (_timer != null) {
+ _timer!.cancel();
+ }
+ _timer = Timer(const Duration(seconds: 1), () async {
+ try {
+ final response = await DevicesAPI.controlDevice(
+ DeviceControlModel(deviceId: allAcsPage ? deviceId : acId, code: code, value: value),
+ allAcsPage ? deviceId : acId);
+
+ if (!response['success']) {
+ add(AcsInitial(allAcs: allAcsPage));
}
+ } catch (_) {
+ await Future.delayed(const Duration(milliseconds: 500));
+ add(AcsInitial(allAcs: allAcsPage));
}
- } catch (_) {}
- await Future.delayed(const Duration(seconds: 1));
- add(const AcsInitial(allAcs: true));
+ });
}
- void _decreaseAllTemp(DecreaseAllTemp event, Emitter emit) async {
- emit(AcsLoadingState());
- try {
- double tempValue = event.value - 0.5;
- int value = (tempValue * 10).toInt();
- if (deviceStatusList.length == devicesList.length) {
- for (int i = 0; i < deviceStatusList.length; i++) {
- await DevicesAPI.controlDevice(
- DeviceControlModel(deviceId: devicesList[i].uuid, code: 'temp_set', value: value),
- devicesList[i].uuid ?? '');
- }
- }
- } catch (_) {}
- await Future.delayed(const Duration(seconds: 1));
- add(const AcsInitial(allAcs: true));
- }
-
- void _changeLockValue(ChangeLock event, Emitter emit) async {
- emit(AcChangeLoading(acStatusModel: deviceStatus));
-
- final lockValue = !event.lockBool;
- try {
- final response = await DevicesAPI.controlDevice(
- DeviceControlModel(deviceId: acId, code: 'child_lock', value: lockValue), acId);
-
- if (response['success'] ?? false) {
- deviceStatus.childLock = lockValue;
- }
- } catch (_) {}
- emit(AcModifyingState(acStatusModel: deviceStatus));
- }
-
- void _increaseCoolTo(IncreaseCoolToTemp event, Emitter emit) async {
- emit(AcChangeLoading(acStatusModel: deviceStatus));
- double tempValue = event.value + 0.5;
- int value = (tempValue * 10).toInt();
- try {
- final response = await DevicesAPI.controlDevice(
- DeviceControlModel(
- deviceId: allAcsPage ? event.deviceId : acId, code: 'temp_set', value: value),
- allAcsPage ? event.deviceId : acId);
-
- if (response['success'] ?? false) {
- deviceStatus.tempSet = value;
- }
- } catch (_) {}
- if (allAcsPage) {
- await Future.delayed(const Duration(seconds: 1));
- add(const AcsInitial(allAcs: true));
+ bool _checkTemperatureValue(double value, Emitter emit) {
+ if (value >= 20 && value <= 30) {
+ return true;
} else {
- emit(AcModifyingState(acStatusModel: deviceStatus));
+ emit(const AcsFailedState(errorMessage: 'The temperature must be between 20 and 30'));
+ emit(GetAllAcsStatusState(
+ allAcsStatues: deviceStatusList,
+ allAcs: devicesList,
+ allOn: allAcsOn,
+ allTempSame: allTempSame,
+ temp: globalTemp));
+ return false;
}
}
- void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter emit) async {
- emit(AcChangeLoading(acStatusModel: deviceStatus));
-
- double tempValue = event.value - 0.5;
- int value = (tempValue * 10).toInt();
- try {
- final response = await DevicesAPI.controlDevice(
- DeviceControlModel(
- deviceId: allAcsPage ? event.deviceId : acId, code: 'temp_set', value: value),
- allAcsPage ? event.deviceId : acId);
-
- if (response['success'] ?? false) {
- deviceStatus.tempSet = value;
- }
- } catch (_) {}
- if (allAcsPage) {
- await Future.delayed(const Duration(seconds: 1));
- add(const AcsInitial(allAcs: true));
- } else {
- emit(AcModifyingState(acStatusModel: deviceStatus));
- }
- }
-
- void _changeAcMode(ChangeAcMode event, Emitter emit) async {
- emit(AcChangeLoading(acStatusModel: deviceStatus));
- final tempMode = tempModesMap[getNextItem(tempModesMap, event.tempModes)]!;
- try {
- final response = await DevicesAPI.controlDevice(
- DeviceControlModel(
- deviceId: allAcsPage ? event.deviceId : acId,
- code: 'mode',
- value: getACModeString(tempMode)),
- allAcsPage ? event.deviceId : acId);
-
- if (response['success'] ?? false) {
- deviceStatus.modeString = getACModeString(tempMode);
- deviceStatus.acMode = AcStatusModel.getACMode(getACModeString(tempMode));
- }
- } catch (_) {}
- if (allAcsPage) {
- await Future.delayed(const Duration(seconds: 1));
- add(const AcsInitial(allAcs: true));
- } else {
- emit(AcModifyingState(acStatusModel: deviceStatus));
- }
- }
-
- void _changeFanSpeed(ChangeFanSpeed event, Emitter emit) async {
- emit(AcChangeLoading(acStatusModel: deviceStatus));
-
- final fanSpeed = event.fanSpeeds;
- final response = await DevicesAPI.controlDevice(
- DeviceControlModel(
- deviceId: allAcsPage ? event.deviceId : acId,
- code: 'level',
- value: getNextFanSpeedKey(fanSpeed)),
- allAcsPage ? event.deviceId : acId);
-
- try {
- if (response['success'] ?? false) {
- deviceStatus.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
- deviceStatus.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
- }
- } catch (_) {}
- if (allAcsPage) {
- await Future.delayed(const Duration(seconds: 1));
- add(const AcsInitial(allAcs: true));
- } else {
- emit(AcModifyingState(acStatusModel: deviceStatus));
- }
- }
-
- String getACModeString(TempModes value) {
- if (value == TempModes.cold) {
- return 'cold';
- } else if (value == TempModes.hot) {
- return 'hot';
- } else if (value == TempModes.wind) {
- return 'wind';
- } else {
- return 'cold';
- }
+ _emitAcsStatus(Emitter emit) {
+ emit(GetAllAcsStatusState(
+ allAcsStatues: deviceStatusList,
+ allAcs: devicesList,
+ allOn: allAcsOn,
+ allTempSame: allTempSame,
+ temp: globalTemp));
}
}
diff --git a/lib/features/devices/bloc/acs_bloc/acs_event.dart b/lib/features/devices/bloc/acs_bloc/acs_event.dart
index 806e878..966f69b 100644
--- a/lib/features/devices/bloc/acs_bloc/acs_event.dart
+++ b/lib/features/devices/bloc/acs_bloc/acs_event.dart
@@ -13,10 +13,11 @@ class AcsLoading extends AcsEvent {}
class AcSwitch extends AcsEvent {
final bool acSwitch;
final String deviceId;
- const AcSwitch({required this.acSwitch, this.deviceId = ''});
+ final String productId;
+ const AcSwitch({required this.acSwitch, this.deviceId = '', this.productId = ''});
@override
- List