From 281414ac41a113e92fa09bfc372116cb377f7ad5 Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 7 Oct 2024 10:29:42 +0300 Subject: [PATCH] garage wizard --- .../garage_door_bloc/garage_door_bloc.dart | 33 +++++++++---------- .../garage_door_bloc/garage_door_state.dart | 6 ++-- .../widgets/garage_door/garage_wizard.dart | 7 ++-- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/features/devices/bloc/garage_door_bloc/garage_door_bloc.dart b/lib/features/devices/bloc/garage_door_bloc/garage_door_bloc.dart index ae11720..995cd0c 100644 --- a/lib/features/devices/bloc/garage_door_bloc/garage_door_bloc.dart +++ b/lib/features/devices/bloc/garage_door_bloc/garage_door_bloc.dart @@ -418,7 +418,7 @@ class GarageDoorBloc extends Bloc { bool oneGangGroup = false; List devicesList = []; - List groupOneGangList = []; + List groupList = []; bool allSwitchesOn = true; void _fetchWizardStatus( @@ -426,7 +426,7 @@ class GarageDoorBloc extends Bloc { emit(LoadingInitialState()); try { devicesList = []; - groupOneGangList = []; + groupList = []; allSwitchesOn = true; devicesList = await DevicesAPI.getDeviceByGroupName( HomeCubit.getInstance().selectedSpace?.id ?? '', 'GD'); @@ -439,23 +439,22 @@ class GarageDoorBloc extends Bloc { statusModelList.add(StatusModel.fromJson(status)); } deviceStatus = GarageDoorModel.fromJson(statusModelList); - groupOneGangList.add(GroupGarageModel( + groupList.add(GroupGarageModel( deviceId: devicesList[i].uuid ?? '', deviceName: devicesList[i].name ?? '', firstSwitch: deviceStatus.switch1, )); } - if (groupOneGangList.isNotEmpty) { - groupOneGangList.firstWhere((element) { + if (groupList.isNotEmpty) { + groupList.firstWhere((element) { if (!element.firstSwitch) { allSwitchesOn = false; } return true; }); } - emit(UpdateGroupState( - oneGangList: groupOneGangList, allSwitches: allSwitchesOn)); + emit(UpdateGroupState(garageList: groupList, allSwitches: allSwitchesOn)); } catch (e) { emit(GarageDoorFailedState(errorMessage: e.toString())); @@ -468,16 +467,16 @@ class GarageDoorBloc extends Bloc { emit(LoadingNewSate(doorSensor: deviceStatus)); try { // Set all switches (firstSwitch and secondSwitch) based on the event value (on/off) - for (int i = 0; i < groupOneGangList.length; i++) { - groupOneGangList[i].firstSwitch = true; + for (int i = 0; i < groupList.length; i++) { + groupList[i].firstSwitch = true; } // Emit the state with updated values - emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: true)); + emit(UpdateGroupState(garageList: groupList, allSwitches: true)); // Get a list of all device IDs List allDeviceIds = - groupOneGangList.map((device) => device.deviceId).toList(); + groupList.map((device) => device.deviceId).toList(); // First call for switch_1 final response = await DevicesAPI.deviceBatchController( @@ -502,16 +501,16 @@ class GarageDoorBloc extends Bloc { emit(LoadingNewSate(doorSensor: deviceStatus)); try { // Set all switches (firstSwitch and secondSwitch) based on the event value (on/off) - for (int i = 0; i < groupOneGangList.length; i++) { - groupOneGangList[i].firstSwitch = false; + for (int i = 0; i < groupList.length; i++) { + groupList[i].firstSwitch = false; } // Emit the state with updated values - emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: false)); + emit(UpdateGroupState(garageList: groupList, allSwitches: false)); // Get a list of all device IDs List allDeviceIds = - groupOneGangList.map((device) => device.deviceId).toList(); + groupList.map((device) => device.deviceId).toList(); // First call for switch_1 final response = await DevicesAPI.deviceBatchController( @@ -537,7 +536,7 @@ class GarageDoorBloc extends Bloc { emit(LoadingNewSate(doorSensor: deviceStatus)); try { bool allSwitchesValue = true; - groupOneGangList.forEach((element) { + groupList.forEach((element) { if (element.deviceId == event.deviceId) { element.firstSwitch = !event.value; } @@ -547,7 +546,7 @@ class GarageDoorBloc extends Bloc { }); emit(UpdateGroupState( - oneGangList: groupOneGangList, allSwitches: allSwitchesValue)); + garageList: groupList, allSwitches: allSwitchesValue)); final response = await DevicesAPI.deviceBatchController( code: 'switch_1', diff --git a/lib/features/devices/bloc/garage_door_bloc/garage_door_state.dart b/lib/features/devices/bloc/garage_door_bloc/garage_door_state.dart index 86f3f5e..d16f326 100644 --- a/lib/features/devices/bloc/garage_door_bloc/garage_door_state.dart +++ b/lib/features/devices/bloc/garage_door_bloc/garage_door_state.dart @@ -83,12 +83,12 @@ class UpdateCreateScheduleState extends GarageDoorSensorState { } class UpdateGroupState extends GarageDoorSensorState { - final List oneGangList; + final List garageList; final bool allSwitches; const UpdateGroupState( - {required this.oneGangList, required this.allSwitches}); + {required this.garageList, required this.allSwitches}); @override - List get props => [oneGangList, allSwitches]; + List get props => [garageList, allSwitches]; } diff --git a/lib/features/devices/view/widgets/garage_door/garage_wizard.dart b/lib/features/devices/view/widgets/garage_door/garage_wizard.dart index e143dab..4419139 100644 --- a/lib/features/devices/view/widgets/garage_door/garage_wizard.dart +++ b/lib/features/devices/view/widgets/garage_door/garage_wizard.dart @@ -21,15 +21,14 @@ class GarageWizard extends StatelessWidget { return DefaultScaffold( title: 'Garage Door Opener', child: BlocProvider( - create: (context) => - GarageDoorBloc( GDId: device?.uuid ?? '') - ..add(InitialWizardEvent()), + create: (context) => GarageDoorBloc(GDId: device?.uuid ?? '') + ..add(InitialWizardEvent()), child: BlocBuilder( builder: (context, state) { bool allSwitchesOn = false; if (state is UpdateGroupState) { - groupGarageModel = state.oneGangList; + groupGarageModel = state.garageList; allSwitchesOn = state.allSwitches; } return state is LoadingInitialState