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

@ -15,6 +15,7 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
on<CurtainFetchBatchStatus>(_onFetchBatchStatus);
on<CurtainControl>(_onCurtainControl);
on<CurtainBatchControl>(_onCurtainBatchControl);
on<CurtainFactoryReset>(_onFactoryReset);
}
FutureOr<void> _onFetchDeviceStatus(
@ -139,4 +140,22 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
isBatch: true,
);
}
FutureOr<void> _onFactoryReset(
CurtainFactoryReset event, Emitter<CurtainState> emit) async {
emit(CurtainStatusLoading());
try {
final response = await DevicesManagementApi().factoryReset(
event.factoryReset,
event.deviceId,
);
if (!response) {
emit(const CurtainControlError('Failed'));
} else {
add(CurtainFetchDeviceStatus(event.deviceId));
}
} catch (e) {
emit(CurtainControlError(e.toString()));
}
}
}