diff --git a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart index 2820da4..99c94ea 100644 --- a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart +++ b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart @@ -376,40 +376,31 @@ class TwoGangBloc extends Bloc { void _groupAllOn(GroupAllOnEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { - // Set all switches (firstSwitch and secondSwitch) based on the event value (on/off) for (int i = 0; i < groupTwoGangList.length; i++) { groupTwoGangList[i].firstSwitch = true; groupTwoGangList[i].secondSwitch = true; } - - // Emit the state with updated values emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true)); - - // Get a list of all device IDs List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); - // First call for switch_1 final response1 = await DevicesAPI.deviceController( - code: 'switch_1', // Controls first switch for all devices + code: 'switch_1', devicesUuid: allDeviceIds, - value: true, // true (on) or false (off) depending on the event value + value: true, ); - // Second call for switch_2 final response2 = await DevicesAPI.deviceController( - code: 'switch_2', // Controls second switch for all devices + code: 'switch_2', devicesUuid: allDeviceIds, - value: true, // true (on) or false (off) depending on the event value + value: true, ); - // Check if either response is unsuccessful, then reset to initial state if (!response1['success'] || !response2['success']) { await Future.delayed(const Duration(milliseconds: 500)); add(const InitialEvent(groupScreen: true)); } } catch (_) { - // In case of an error, delay and reset the screen to initial state await Future.delayed(const Duration(milliseconds: 500)); add(const InitialEvent(groupScreen: true)); } @@ -418,40 +409,33 @@ class TwoGangBloc extends Bloc { void _groupAllOff(GroupAllOffEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { - // Set all switches (firstSwitch and secondSwitch) based on the event value (on/off) for (int i = 0; i < groupTwoGangList.length; i++) { groupTwoGangList[i].firstSwitch = false; groupTwoGangList[i].secondSwitch = false; } - // Emit the state with updated values emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false)); - // Get a list of all device IDs List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); - // First call for switch_1 final response1 = await DevicesAPI.deviceController( - code: 'switch_1', // Controls first switch for all devices + code: 'switch_1', devicesUuid: allDeviceIds, - value: true, // true (on) or false (off) depending on the event value + value: true, ); - // Second call for switch_2 final response2 = await DevicesAPI.deviceController( - code: 'switch_2', // Controls second switch for all devices + code: 'switch_2', devicesUuid: allDeviceIds, - value: true, // true (on) or false (off) depending on the event value + value: true, ); - // Check if either response is unsuccessful, then reset to initial state if (!response1['success'] || !response2['success']) { await Future.delayed(const Duration(milliseconds: 500)); add(const InitialEvent(groupScreen: true)); } } catch (_) { - // In case of an error, delay and reset the screen to initial state await Future.delayed(const Duration(milliseconds: 500)); add(const InitialEvent(groupScreen: true)); } @@ -767,6 +751,4 @@ class TwoGangBloc extends Bloc { add(InitialEvent(groupScreen: twoGangGroup)); } } - - } diff --git a/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart b/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart index 057b118..247c597 100644 --- a/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart +++ b/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart @@ -360,7 +360,6 @@ class WaterHeaterBloc extends Bloc { ); } - // List devicesList = []; List groupTwoGangList = []; bool allSwitchesOn = true; @@ -438,39 +437,32 @@ class WaterHeaterBloc extends Bloc { GroupAllOnEvent event, Emitter emit) async { emit(LoadingNewSate(whModel: deviceStatus)); try { - // Set all switches (firstSwitch and secondSwitch) based on the event value (on/off) for (int i = 0; i < groupTwoGangList.length; i++) { groupTwoGangList[i].firstSwitch = true; } - // Emit the state with updated values emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true)); - // Get a list of all device IDs List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); - // First call for switch_1 final response1 = await DevicesAPI.deviceController( - code: 'switch_1', // Controls first switch for all devices + code: 'switch_1', devicesUuid: allDeviceIds, - value: true, // true (on) or false (off) depending on the event value + value: true, ); - // Second call for switch_2 final response2 = await DevicesAPI.deviceController( - code: 'switch_2', // Controls second switch for all devices + code: 'switch_2', devicesUuid: allDeviceIds, - value: true, // true (on) or false (off) depending on the event value + value: true, ); - // Check if either response is unsuccessful, then reset to initial state if (!response1['success'] || !response2['success']) { await Future.delayed(const Duration(milliseconds: 500)); add(InitialWizardEvent()); } } catch (_) { - // In case of an error, delay and reset the screen to initial state await Future.delayed(const Duration(milliseconds: 500)); add(InitialWizardEvent()); } @@ -480,39 +472,31 @@ class WaterHeaterBloc extends Bloc { GroupAllOffEvent event, Emitter emit) async { emit(LoadingNewSate(whModel: deviceStatus)); try { - // Set all switches (firstSwitch and secondSwitch) based on the event value (on/off) for (int i = 0; i < groupTwoGangList.length; i++) { groupTwoGangList[i].firstSwitch = false; } - - // Emit the state with updated values emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false)); - // Get a list of all device IDs List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); - // First call for switch_1 final response1 = await DevicesAPI.deviceController( - code: 'switch_1', // Controls first switch for all devices + code: 'switch_1', devicesUuid: allDeviceIds, - value: true, // true (on) or false (off) depending on the event value + value: true, ); - // Second call for switch_2 final response2 = await DevicesAPI.deviceController( - code: 'switch_2', // Controls second switch for all devices + code: 'switch_2', devicesUuid: allDeviceIds, - value: true, // true (on) or false (off) depending on the event value + value: true, ); - // Check if either response is unsuccessful, then reset to initial state if (!response1['success'] || !response2['success']) { await Future.delayed(const Duration(milliseconds: 500)); add(InitialWizardEvent()); } } catch (_) { - // In case of an error, delay and reset the screen to initial state await Future.delayed(const Duration(milliseconds: 500)); add(InitialWizardEvent()); }