mirror of
https://github.com/SyncrowIOT/web.git
synced 2026-10-27 05:17:56 +00:00
push factory reset logic and call for all devices
This commit is contained in:
@@ -19,6 +19,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
on<GetDeviceReportsEvent>(_getDeviceReports);
|
||||
on<ShowDescriptionEvent>(_showDescription);
|
||||
on<BackToGridViewEvent>(_backToGridView);
|
||||
on<WallSensorFactoryResetEvent>(_onFactoryReset);
|
||||
}
|
||||
|
||||
void _fetchWallSensorStatus(
|
||||
@@ -168,4 +169,22 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
BackToGridViewEvent event, Emitter<WallSensorState> emit) {
|
||||
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
|
||||
}
|
||||
|
||||
FutureOr<void> _onFactoryReset(
|
||||
WallSensorFactoryResetEvent event, Emitter<WallSensorState> emit) async {
|
||||
emit(WallSensorLoadingNewSate(wallSensorModel: deviceStatus));
|
||||
try {
|
||||
final response = await DevicesManagementApi().factoryReset(
|
||||
event.factoryReset,
|
||||
event.deviceId,
|
||||
);
|
||||
if (!response) {
|
||||
emit(const WallSensorFailedState(error: 'Failed'));
|
||||
} else {
|
||||
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(WallSensorFailedState(error: e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||
|
||||
abstract class WallSensorEvent extends Equatable {
|
||||
const WallSensorEvent();
|
||||
@@ -59,3 +60,13 @@ class WallSensorBatchControlEvent extends WallSensorEvent {
|
||||
@override
|
||||
List<Object> get props => [deviceIds, code, value];
|
||||
}
|
||||
|
||||
class WallSensorFactoryResetEvent extends WallSensorEvent {
|
||||
final String deviceId;
|
||||
final FactoryResetModel factoryReset;
|
||||
|
||||
const WallSensorFactoryResetEvent({
|
||||
required this.deviceId,
|
||||
required this.factoryReset,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_update_data.dart';
|
||||
@@ -118,7 +119,16 @@ class WallSensorBatchControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 2),
|
||||
FactoryResetWidget(deviceId: devicesIds.first),
|
||||
FactoryResetWidget(
|
||||
callFactoryReset: () {
|
||||
context.read<WallSensorBloc>().add(
|
||||
WallSensorFactoryResetEvent(
|
||||
deviceId: devicesIds.first,
|
||||
factoryReset: FactoryResetModel(devicesUuid: devicesIds),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user