push factory reset logic and call for all devices

This commit is contained in:
ashrafzarkanisala
2024-09-22 21:56:17 +03:00
parent 3a28f0ef9a
commit 2955533209
31 changed files with 481 additions and 35 deletions

View File

@ -18,6 +18,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
on<AcFetchBatchStatusEvent>(_onFetchAcBatchStatus);
on<AcControlEvent>(_onAcControl);
on<AcBatchControlEvent>(_onAcBatchControl);
on<AcFactoryResetEvent>(_onFactoryReset);
}
FutureOr<void> _onFetchAcStatus(
@ -184,4 +185,22 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
emit: emit,
);
}
FutureOr<void> _onFactoryReset(
AcFactoryResetEvent event, Emitter<AcsState> emit) async {
emit(AcsLoadingState());
try {
final response = await DevicesManagementApi().factoryReset(
event.factoryResetModel,
event.deviceId,
);
if (!response) {
emit(const AcsFailedState(error: 'Failed'));
} else {
add(AcFetchDeviceStatusEvent(event.deviceId));
}
} catch (e) {
emit(AcsFailedState(error: e.toString()));
}
}
}