mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
push factory reset logic and call for all devices
This commit is contained in:
@ -18,6 +18,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
on<AcFetchBatchStatusEvent>(_onFetchAcBatchStatus);
|
on<AcFetchBatchStatusEvent>(_onFetchAcBatchStatus);
|
||||||
on<AcControlEvent>(_onAcControl);
|
on<AcControlEvent>(_onAcControl);
|
||||||
on<AcBatchControlEvent>(_onAcBatchControl);
|
on<AcBatchControlEvent>(_onAcBatchControl);
|
||||||
|
on<AcFactoryResetEvent>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onFetchAcStatus(
|
FutureOr<void> _onFetchAcStatus(
|
||||||
@ -184,4 +185,22 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
emit: emit,
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
|
||||||
sealed class AcsEvent extends Equatable {
|
sealed class AcsEvent extends Equatable {
|
||||||
const AcsEvent();
|
const AcsEvent();
|
||||||
@ -54,3 +55,16 @@ class AcBatchControlEvent extends AcsEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [devicesIds, code, value];
|
List<Object> get props => [devicesIds, code, value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AcFactoryResetEvent extends AcsEvent {
|
||||||
|
final String deviceId;
|
||||||
|
final FactoryResetModel factoryResetModel;
|
||||||
|
|
||||||
|
const AcFactoryResetEvent({
|
||||||
|
required this.deviceId,
|
||||||
|
required this.factoryResetModel,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceId, factoryResetModel];
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@ import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_state.dart';
|
|||||||
import 'package:syncrow_web/pages/device_managment/ac/view/batch_control_list/batch_ac_mode.dart';
|
import 'package:syncrow_web/pages/device_managment/ac/view/batch_control_list/batch_ac_mode.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ac/view/batch_control_list/batch_current_temp.dart';
|
import 'package:syncrow_web/pages/device_managment/ac/view/batch_control_list/batch_current_temp.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ac/view/batch_control_list/batch_fan_speed.dart';
|
import 'package:syncrow_web/pages/device_managment/ac/view/batch_control_list/batch_fan_speed.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/factory_reset.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||||
@ -89,7 +90,15 @@ class AcDeviceBatchControlView extends StatelessWidget
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 5),
|
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 5),
|
||||||
FactoryResetWidget(deviceId: devicesIds.first),
|
FactoryResetWidget(
|
||||||
|
callFactoryReset: () {
|
||||||
|
context.read<AcBloc>().add(AcFactoryResetEvent(
|
||||||
|
deviceId: state.status.uuid,
|
||||||
|
factoryResetModel:
|
||||||
|
FactoryResetModel(devicesUuid: devicesIds),
|
||||||
|
));
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else if (state is AcsLoadingState) {
|
} else if (state is AcsLoadingState) {
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
class FactoryResetModel {
|
||||||
|
final List<String> devicesUuid;
|
||||||
|
|
||||||
|
FactoryResetModel({
|
||||||
|
required this.devicesUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory FactoryResetModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return FactoryResetModel(
|
||||||
|
devicesUuid: List<String>.from(json['devicesUuid']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'devicesUuid': devicesUuid,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
FactoryResetModel copyWith({
|
||||||
|
List<String>? devicesUuid,
|
||||||
|
}) {
|
||||||
|
return FactoryResetModel(
|
||||||
|
devicesUuid: devicesUuid ?? this.devicesUuid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'devicesUuid': devicesUuid,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory FactoryResetModel.fromMap(Map<String, dynamic> map) {
|
||||||
|
return FactoryResetModel(
|
||||||
|
devicesUuid: List<String>.from(map['devicesUuid']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => 'FactoryReset(devicesUuid: $devicesUuid)';
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is FactoryResetModel &&
|
||||||
|
listEquals(other.devicesUuid, devicesUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => devicesUuid.hashCode;
|
||||||
|
}
|
@ -20,14 +20,15 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
on<GetCeilingDeviceReportsEvent>(_getDeviceReports);
|
on<GetCeilingDeviceReportsEvent>(_getDeviceReports);
|
||||||
on<ShowCeilingDescriptionEvent>(_showDescription);
|
on<ShowCeilingDescriptionEvent>(_showDescription);
|
||||||
on<BackToCeilingGridViewEvent>(_backToGridView);
|
on<BackToCeilingGridViewEvent>(_backToGridView);
|
||||||
|
on<CeilingFactoryResetEvent>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchCeilingSensorStatus(
|
void _fetchCeilingSensorStatus(
|
||||||
CeilingInitialEvent event, Emitter<CeilingSensorState> emit) async {
|
CeilingInitialEvent event, Emitter<CeilingSensorState> emit) async {
|
||||||
emit(CeilingLoadingInitialState());
|
emit(CeilingLoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesManagementApi()
|
var response =
|
||||||
.getDeviceStatus(event.deviceId);
|
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
deviceStatus = CeilingSensorModel.fromJson(response.status);
|
deviceStatus = CeilingSensorModel.fromJson(response.status);
|
||||||
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
||||||
// _listenToChanges();
|
// _listenToChanges();
|
||||||
@ -188,4 +189,22 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onFactoryReset(
|
||||||
|
CeilingFactoryResetEvent event, Emitter<CeilingSensorState> emit) async {
|
||||||
|
emit(CeilingLoadingNewSate(ceilingSensorModel: deviceStatus));
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi().factoryReset(
|
||||||
|
event.factoryResetModel,
|
||||||
|
event.devicesId,
|
||||||
|
);
|
||||||
|
if (!response) {
|
||||||
|
emit(const CeilingFailedState(error: 'Failed'));
|
||||||
|
} else {
|
||||||
|
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(CeilingFailedState(error: e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
|
||||||
abstract class CeilingSensorEvent extends Equatable {
|
abstract class CeilingSensorEvent extends Equatable {
|
||||||
const CeilingSensorEvent();
|
const CeilingSensorEvent();
|
||||||
@ -69,3 +70,16 @@ class ShowCeilingDescriptionEvent extends CeilingSensorEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BackToCeilingGridViewEvent extends CeilingSensorEvent {}
|
class BackToCeilingGridViewEvent extends CeilingSensorEvent {}
|
||||||
|
|
||||||
|
class CeilingFactoryResetEvent extends CeilingSensorEvent {
|
||||||
|
final String devicesId;
|
||||||
|
final FactoryResetModel factoryResetModel;
|
||||||
|
|
||||||
|
const CeilingFactoryResetEvent({
|
||||||
|
required this.devicesId,
|
||||||
|
required this.factoryResetModel,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [devicesId, factoryResetModel];
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/ceiling_sensor/bloc/bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
|
||||||
@ -112,7 +113,17 @@ class CeilingSensorBatchControlView extends StatelessWidget
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 4),
|
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 4),
|
||||||
FactoryResetWidget(deviceId: devicesIds.first),
|
FactoryResetWidget(
|
||||||
|
callFactoryReset: () {
|
||||||
|
context.read<CeilingSensorBloc>().add(
|
||||||
|
CeilingFactoryResetEvent(
|
||||||
|
devicesId: devicesIds.first,
|
||||||
|
factoryResetModel:
|
||||||
|
FactoryResetModel(devicesUuid: devicesIds),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
on<CurtainFetchBatchStatus>(_onFetchBatchStatus);
|
on<CurtainFetchBatchStatus>(_onFetchBatchStatus);
|
||||||
on<CurtainControl>(_onCurtainControl);
|
on<CurtainControl>(_onCurtainControl);
|
||||||
on<CurtainBatchControl>(_onCurtainBatchControl);
|
on<CurtainBatchControl>(_onCurtainBatchControl);
|
||||||
|
on<CurtainFactoryReset>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onFetchDeviceStatus(
|
FutureOr<void> _onFetchDeviceStatus(
|
||||||
@ -139,4 +140,22 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
isBatch: true,
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
|
||||||
sealed class CurtainEvent extends Equatable {
|
sealed class CurtainEvent extends Equatable {
|
||||||
const CurtainEvent();
|
const CurtainEvent();
|
||||||
@ -48,3 +49,14 @@ class CurtainBatchControl extends CurtainEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [devicesIds, code, value];
|
List<Object> get props => [devicesIds, code, value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CurtainFactoryReset extends CurtainEvent {
|
||||||
|
final String deviceId;
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
|
||||||
|
const CurtainFactoryReset(
|
||||||
|
{required this.deviceId, required this.factoryReset});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceId, factoryReset];
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/curtain_toggle.dart';
|
import 'package:syncrow_web/pages/common/curtain_toggle.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_event.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_event.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_state.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_state.dart';
|
||||||
@ -68,7 +69,16 @@ class CurtainBatchStatusView extends StatelessWidget
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 5),
|
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 5),
|
||||||
FactoryResetWidget(deviceId: devicesIds.first),
|
FactoryResetWidget(
|
||||||
|
callFactoryReset: () {
|
||||||
|
context.read<CurtainBloc>().add(
|
||||||
|
CurtainFactoryReset(
|
||||||
|
deviceId: devicesIds.first,
|
||||||
|
factoryReset: FactoryResetModel(devicesUuid: devicesIds),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
|
|||||||
on<DoorLockFetchStatus>(_onFetchDeviceStatus);
|
on<DoorLockFetchStatus>(_onFetchDeviceStatus);
|
||||||
//on<DoorLockControl>(_onDoorLockControl);
|
//on<DoorLockControl>(_onDoorLockControl);
|
||||||
on<UpdateLockEvent>(_updateLock);
|
on<UpdateLockEvent>(_updateLock);
|
||||||
|
on<DoorLockFactoryReset>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onFetchDeviceStatus(
|
FutureOr<void> _onFetchDeviceStatus(
|
||||||
@ -113,4 +114,22 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onFactoryReset(
|
||||||
|
DoorLockFactoryReset event, Emitter<DoorLockState> emit) async {
|
||||||
|
emit(DoorLockStatusLoading());
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi().factoryReset(
|
||||||
|
event.factoryReset,
|
||||||
|
event.deviceId,
|
||||||
|
);
|
||||||
|
if (!response) {
|
||||||
|
emit(const DoorLockControlError('Failed'));
|
||||||
|
} else {
|
||||||
|
add(DoorLockFetchStatus(event.deviceId));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(DoorLockControlError(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
|
||||||
sealed class DoorLockEvent extends Equatable {
|
sealed class DoorLockEvent extends Equatable {
|
||||||
const DoorLockEvent();
|
const DoorLockEvent();
|
||||||
@ -38,4 +39,15 @@ class UpdateLockEvent extends DoorLockEvent {
|
|||||||
List<Object> get props => [value];
|
List<Object> get props => [value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DoorLockFactoryReset extends DoorLockEvent {
|
||||||
|
final String deviceId;
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
|
||||||
|
const DoorLockFactoryReset({
|
||||||
|
required this.deviceId,
|
||||||
|
required this.factoryReset,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceId, factoryReset];
|
||||||
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
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/door_lock/bloc/door_lock_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/door_lock/bloc/door_lock_event.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.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/batch_control/firmware_update.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
@ -30,7 +34,16 @@ class DoorLockBatchControlView extends StatelessWidget
|
|||||||
deviceId: devicesIds.first,
|
deviceId: devicesIds.first,
|
||||||
version: 12,
|
version: 12,
|
||||||
),
|
),
|
||||||
FactoryResetWidget(deviceId: devicesIds.first),
|
FactoryResetWidget(
|
||||||
|
callFactoryReset: () {
|
||||||
|
BlocProvider.of<DoorLockBloc>(context).add(
|
||||||
|
DoorLockFactoryReset(
|
||||||
|
deviceId: devicesIds.first,
|
||||||
|
factoryReset: FactoryResetModel(devicesUuid: devicesIds),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/model/device_model.dart';
|
import 'package:syncrow_web/pages/visitor_password/model/device_model.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ class GateWayBloc extends Bloc<GateWayEvent, GateWayState> {
|
|||||||
GateWayBloc() : super(GateWayInitial()) {
|
GateWayBloc() : super(GateWayInitial()) {
|
||||||
on<GateWayFetch>((event, emit) {});
|
on<GateWayFetch>((event, emit) {});
|
||||||
on<GatWayById>(_getGatWayById);
|
on<GatWayById>(_getGatWayById);
|
||||||
|
on<GateWayFactoryReset>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _getGatWayById(
|
FutureOr<void> _getGatWayById(
|
||||||
@ -27,4 +29,22 @@ class GateWayBloc extends Bloc<GateWayEvent, GateWayState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onFactoryReset(
|
||||||
|
GateWayFactoryReset event, Emitter<GateWayState> emit) async {
|
||||||
|
emit(GatewayLoadingState());
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi().factoryReset(
|
||||||
|
event.factoryReset,
|
||||||
|
event.deviceId,
|
||||||
|
);
|
||||||
|
if (!response) {
|
||||||
|
emit(const ErrorState(message: 'Failed'));
|
||||||
|
} else {
|
||||||
|
add(GatWayById(event.deviceId));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(ErrorState(message: e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,3 +18,15 @@ class GatWayById extends GateWayEvent {
|
|||||||
final String getWayId;
|
final String getWayId;
|
||||||
const GatWayById(this.getWayId);
|
const GatWayById(this.getWayId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GateWayFactoryReset extends GateWayEvent {
|
||||||
|
final String deviceId;
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
const GateWayFactoryReset({
|
||||||
|
required this.deviceId,
|
||||||
|
required this.factoryReset,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceId, factoryReset];
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/gateway/bloc/gate_way_bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/gateway/bloc/gate_way_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.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/batch_control/firmware_update.dart';
|
||||||
@ -36,7 +37,17 @@ class GatewayBatchControlView extends StatelessWidget
|
|||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
FirmwareUpdateWidget(deviceId: gatewayIds.first, version: 2),
|
FirmwareUpdateWidget(deviceId: gatewayIds.first, version: 2),
|
||||||
FactoryResetWidget(deviceId: gatewayIds.first),
|
FactoryResetWidget(
|
||||||
|
callFactoryReset: () {
|
||||||
|
context.read<GateWayBloc>().add(
|
||||||
|
GateWayFactoryReset(
|
||||||
|
deviceId: gatewayIds.first,
|
||||||
|
factoryReset:
|
||||||
|
FactoryResetModel(devicesUuid: gatewayIds),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,6 +15,7 @@ class WallLightSwitchBloc
|
|||||||
on<WallLightSwitchControl>(_onControl);
|
on<WallLightSwitchControl>(_onControl);
|
||||||
on<WallLightSwitchFetchBatchEvent>(_onFetchBatchStatus);
|
on<WallLightSwitchFetchBatchEvent>(_onFetchBatchStatus);
|
||||||
on<WallLightSwitchBatchControl>(_onBatchControl);
|
on<WallLightSwitchBatchControl>(_onBatchControl);
|
||||||
|
on<WallLightFactoryReset>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
late WallLightStatusModel deviceStatus;
|
late WallLightStatusModel deviceStatus;
|
||||||
@ -153,4 +154,22 @@ class WallLightSwitchBloc
|
|||||||
isBatch: true,
|
isBatch: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onFactoryReset(
|
||||||
|
WallLightFactoryReset event, Emitter<WallLightSwitchState> emit) async {
|
||||||
|
emit(WallLightSwitchLoading());
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi().factoryReset(
|
||||||
|
event.factoryReset,
|
||||||
|
event.deviceId,
|
||||||
|
);
|
||||||
|
if (!response) {
|
||||||
|
emit(WallLightSwitchError('Failed'));
|
||||||
|
} else {
|
||||||
|
emit(WallLightSwitchStatusLoaded(deviceStatus));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(WallLightSwitchError(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
|
||||||
class WallLightSwitchEvent extends Equatable {
|
class WallLightSwitchEvent extends Equatable {
|
||||||
@override
|
@override
|
||||||
@ -46,3 +47,13 @@ class WallLightSwitchBatchControl extends WallLightSwitchEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [devicesIds, code, value];
|
List<Object> get props => [devicesIds, code, value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WallLightFactoryReset extends WallLightSwitchEvent {
|
||||||
|
final String deviceId;
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
|
||||||
|
WallLightFactoryReset({required this.deviceId, required this.factoryReset});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceId, factoryReset];
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/one_gang_switch/bloc/wall_light_switch_bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_event.dart';
|
import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_event.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_state.dart';
|
import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_state.dart';
|
||||||
@ -77,7 +78,13 @@ class WallLightBatchControlView extends StatelessWidget
|
|||||||
deviceId: deviceIds.first,
|
deviceId: deviceIds.first,
|
||||||
version: 12,
|
version: 12,
|
||||||
),
|
),
|
||||||
FactoryResetWidget(deviceId: deviceIds.first),
|
FactoryResetWidget(
|
||||||
|
callFactoryReset: () {
|
||||||
|
context.read<WallLightSwitchBloc>().add(WallLightFactoryReset(
|
||||||
|
deviceId: status.uuid,
|
||||||
|
factoryReset: FactoryResetModel(devicesUuid: deviceIds)));
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -6,36 +6,41 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
|||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
class FactoryResetWidget extends StatelessWidget {
|
class FactoryResetWidget extends StatelessWidget {
|
||||||
const FactoryResetWidget({super.key, required String deviceId});
|
const FactoryResetWidget({super.key, required this.callFactoryReset});
|
||||||
|
|
||||||
|
final Null Function() callFactoryReset;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DeviceControlsContainer(
|
return DeviceControlsContainer(
|
||||||
child: Column(
|
child: GestureDetector(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
onTap: callFactoryReset,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
ClipOval(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
child: Container(
|
children: [
|
||||||
color: ColorsManager.whiteColors,
|
ClipOval(
|
||||||
height: 60,
|
child: Container(
|
||||||
width: 60,
|
color: ColorsManager.whiteColors,
|
||||||
child: Padding(
|
height: 60,
|
||||||
padding: const EdgeInsets.all(12.0),
|
width: 60,
|
||||||
child: SvgPicture.asset(
|
child: Padding(
|
||||||
Assets.factoryReset,
|
padding: const EdgeInsets.all(12.0),
|
||||||
fit: BoxFit.cover,
|
child: SvgPicture.asset(
|
||||||
|
Assets.factoryReset,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
Text(
|
||||||
|
'Factory Reset',
|
||||||
|
style: context.textTheme.titleMedium!.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)),
|
],
|
||||||
Text(
|
),
|
||||||
'Factory Reset',
|
|
||||||
style: context.textTheme.titleMedium!.copyWith(
|
|
||||||
fontWeight: FontWeight.w400,
|
|
||||||
color: ColorsManager.blackColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import 'dart:async';
|
|||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/three_gang_switch/models/living_room_model.dart';
|
import 'package:syncrow_web/pages/device_managment/three_gang_switch/models/living_room_model.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
|
|
||||||
@ -20,6 +21,7 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
|||||||
on<LivingRoomControl>(_livingRoomControl);
|
on<LivingRoomControl>(_livingRoomControl);
|
||||||
on<LivingRoomBatchControl>(_livingRoomBatchControl);
|
on<LivingRoomBatchControl>(_livingRoomBatchControl);
|
||||||
on<LivingRoomFetchBatchEvent>(_livingRoomFetchBatchControl);
|
on<LivingRoomFetchBatchEvent>(_livingRoomFetchBatchControl);
|
||||||
|
on<LivingRoomFactoryResetEvent>(_livingRoomFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onFetchDeviceStatus(LivingRoomFetchDeviceStatusEvent event,
|
FutureOr<void> _onFetchDeviceStatus(LivingRoomFetchDeviceStatusEvent event,
|
||||||
@ -165,4 +167,22 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
|||||||
isBatch: true,
|
isBatch: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _livingRoomFactoryReset(
|
||||||
|
LivingRoomFactoryResetEvent event, Emitter<LivingRoomState> emit) async {
|
||||||
|
emit(LivingRoomDeviceStatusLoading());
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi().factoryReset(
|
||||||
|
event.factoryReset,
|
||||||
|
event.uuid,
|
||||||
|
);
|
||||||
|
if (!response) {
|
||||||
|
emit(const LivingRoomDeviceManagementError('Failed'));
|
||||||
|
} else {
|
||||||
|
emit(LivingRoomDeviceStatusLoaded(deviceStatus));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(LivingRoomDeviceManagementError(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,3 +49,12 @@ class LivingRoomBatchControl extends LivingRoomEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [devicesIds, code, value];
|
List<Object> get props => [devicesIds, code, value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LivingRoomFactoryResetEvent extends LivingRoomEvent {
|
||||||
|
final String uuid;
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
const LivingRoomFactoryResetEvent(this.uuid, this.factoryReset);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [uuid, factoryReset];
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/factory_reset.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/three_gang_switch/bloc/living_room_bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/three_gang_switch/bloc/living_room_bloc.dart';
|
||||||
@ -105,7 +106,14 @@ class LivingRoomBatchControlsView extends StatelessWidget
|
|||||||
deviceId: deviceIds.first,
|
deviceId: deviceIds.first,
|
||||||
version: 12,
|
version: 12,
|
||||||
),
|
),
|
||||||
FactoryResetWidget(deviceId: deviceIds.first),
|
FactoryResetWidget(callFactoryReset: () {
|
||||||
|
context.read<LivingRoomBloc>().add(
|
||||||
|
LivingRoomFactoryResetEvent(
|
||||||
|
status.uuid,
|
||||||
|
FactoryResetModel(devicesUuid: deviceIds),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -13,6 +13,7 @@ class TwoGangSwitchBloc extends Bloc<TwoGangSwitchEvent, TwoGangSwitchState> {
|
|||||||
on<TwoGangSwitchControl>(_onControl);
|
on<TwoGangSwitchControl>(_onControl);
|
||||||
on<TwoGangSwitchFetchBatchEvent>(_onFetchBatchStatus);
|
on<TwoGangSwitchFetchBatchEvent>(_onFetchBatchStatus);
|
||||||
on<TwoGangSwitchBatchControl>(_onBatchControl);
|
on<TwoGangSwitchBatchControl>(_onBatchControl);
|
||||||
|
on<TwoGangFactoryReset>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
late TwoGangStatusModel deviceStatus;
|
late TwoGangStatusModel deviceStatus;
|
||||||
@ -155,4 +156,22 @@ class TwoGangSwitchBloc extends Bloc<TwoGangSwitchEvent, TwoGangSwitchState> {
|
|||||||
isBatch: true,
|
isBatch: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onFactoryReset(
|
||||||
|
TwoGangFactoryReset event, Emitter<TwoGangSwitchState> emit) async {
|
||||||
|
emit(TwoGangSwitchLoading());
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi().factoryReset(
|
||||||
|
event.factoryReset,
|
||||||
|
event.deviceId,
|
||||||
|
);
|
||||||
|
if (!response) {
|
||||||
|
emit(TwoGangSwitchError('Failed'));
|
||||||
|
} else {
|
||||||
|
emit(TwoGangSwitchStatusLoaded(deviceStatus));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(TwoGangSwitchError(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
|
||||||
class TwoGangSwitchEvent extends Equatable {
|
class TwoGangSwitchEvent extends Equatable {
|
||||||
@override
|
@override
|
||||||
@ -46,3 +47,13 @@ class TwoGangSwitchBatchControl extends TwoGangSwitchEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [deviceId, code, value];
|
List<Object> get props => [deviceId, code, value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TwoGangFactoryReset extends TwoGangSwitchEvent {
|
||||||
|
final String deviceId;
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
|
||||||
|
TwoGangFactoryReset({required this.deviceId, required this.factoryReset});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceId, factoryReset];
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/factory_reset.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||||
@ -87,7 +88,14 @@ class TwoGangBatchControlView extends StatelessWidget
|
|||||||
deviceId: deviceIds.first,
|
deviceId: deviceIds.first,
|
||||||
version: 12,
|
version: 12,
|
||||||
),
|
),
|
||||||
FactoryResetWidget(deviceId: deviceIds.first),
|
FactoryResetWidget(callFactoryReset: () {
|
||||||
|
context.read<TwoGangSwitchBloc>().add(
|
||||||
|
TwoGangFactoryReset(
|
||||||
|
deviceId: status.uuid,
|
||||||
|
factoryReset: FactoryResetModel(devicesUuid: deviceIds),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -19,6 +19,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
on<GetDeviceReportsEvent>(_getDeviceReports);
|
on<GetDeviceReportsEvent>(_getDeviceReports);
|
||||||
on<ShowDescriptionEvent>(_showDescription);
|
on<ShowDescriptionEvent>(_showDescription);
|
||||||
on<BackToGridViewEvent>(_backToGridView);
|
on<BackToGridViewEvent>(_backToGridView);
|
||||||
|
on<WallSensorFactoryResetEvent>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchWallSensorStatus(
|
void _fetchWallSensorStatus(
|
||||||
@ -168,4 +169,22 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
BackToGridViewEvent event, Emitter<WallSensorState> emit) {
|
BackToGridViewEvent event, Emitter<WallSensorState> emit) {
|
||||||
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
|
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:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
|
||||||
abstract class WallSensorEvent extends Equatable {
|
abstract class WallSensorEvent extends Equatable {
|
||||||
const WallSensorEvent();
|
const WallSensorEvent();
|
||||||
@ -59,3 +60,13 @@ class WallSensorBatchControlEvent extends WallSensorEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [deviceIds, code, value];
|
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/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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/factory_reset.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.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';
|
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),
|
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 2),
|
||||||
FactoryResetWidget(deviceId: devicesIds.first),
|
FactoryResetWidget(
|
||||||
|
callFactoryReset: () {
|
||||||
|
context.read<WallSensorBloc>().add(
|
||||||
|
WallSensorFactoryResetEvent(
|
||||||
|
deviceId: devicesIds.first,
|
||||||
|
factoryReset: FactoryResetModel(devicesUuid: devicesIds),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/water_heater/models/schedule_model.dart';
|
import 'package:syncrow_web/pages/device_managment/water_heater/models/schedule_model.dart';
|
||||||
import 'package:syncrow_web/pages/visitor_password/model/device_model.dart';
|
import 'package:syncrow_web/pages/visitor_password/model/device_model.dart';
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
@ -259,4 +260,21 @@ class DevicesManagementApi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> factoryReset(FactoryResetModel factoryReset, String uuid) async {
|
||||||
|
try {
|
||||||
|
final response = await HTTPService().post(
|
||||||
|
path: ApiEndpoints.factoryReset.replaceAll('{deviceUuid}', uuid),
|
||||||
|
body: factoryReset.toMap(),
|
||||||
|
showServerMessage: true,
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
return json['success'] ?? false;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Error fetching $e');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,4 +46,6 @@ abstract class ApiEndpoints {
|
|||||||
'/schedule/{deviceUuid}/{scheduleUuid}';
|
'/schedule/{deviceUuid}/{scheduleUuid}';
|
||||||
static const String updateScheduleByDeviceId =
|
static const String updateScheduleByDeviceId =
|
||||||
'/schedule/enable/{deviceUuid}';
|
'/schedule/enable/{deviceUuid}';
|
||||||
|
|
||||||
|
static const String factoryReset = '/device/factory/reset/{deviceUuid}';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user