mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
push factory reset
This commit is contained in:
@ -9,6 +9,7 @@ import 'package:syncrow_web/pages/device_managment/curtain/view/curtain_batch_st
|
|||||||
import 'package:syncrow_web/pages/device_managment/curtain/view/curtain_status_view.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain/view/curtain_status_view.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_batch_control_view.dart';
|
import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_batch_control_view.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_control_view.dart';
|
import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_control_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/view/garage_door_batch_control_view.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/garage_door/view/garage_door_control_view.dart';
|
import 'package:syncrow_web/pages/device_managment/garage_door/view/garage_door_control_view.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_batch_control.dart';
|
import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_batch_control.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_view.dart';
|
import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_view.dart';
|
||||||
@ -110,56 +111,105 @@ mixin RouteControlsBasedCode {
|
|||||||
switch (devices.first.productType) {
|
switch (devices.first.productType) {
|
||||||
case '1G':
|
case '1G':
|
||||||
return WallLightBatchControlView(
|
return WallLightBatchControlView(
|
||||||
deviceIds: devices.where((e) => (e.productType == '1G')).map((e) => e.uuid!).toList(),
|
deviceIds: devices
|
||||||
|
.where((e) => (e.productType == '1G'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case '2G':
|
case '2G':
|
||||||
return TwoGangBatchControlView(
|
return TwoGangBatchControlView(
|
||||||
deviceIds: devices.where((e) => (e.productType == '2G')).map((e) => e.uuid!).toList(),
|
deviceIds: devices
|
||||||
|
.where((e) => (e.productType == '2G'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case '3G':
|
case '3G':
|
||||||
return LivingRoomBatchControlsView(
|
return LivingRoomBatchControlsView(
|
||||||
deviceIds: devices.where((e) => (e.productType == '3G')).map((e) => e.uuid!).toList(),
|
deviceIds: devices
|
||||||
|
.where((e) => (e.productType == '3G'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case '1GT':
|
case '1GT':
|
||||||
return OneGangGlassSwitchBatchControlView(
|
return OneGangGlassSwitchBatchControlView(
|
||||||
deviceIds: devices.where((e) => (e.productType == '1GT')).map((e) => e.uuid!).toList(),
|
deviceIds: devices
|
||||||
|
.where((e) => (e.productType == '1GT'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case '2GT':
|
case '2GT':
|
||||||
return TwoGangGlassSwitchBatchControlView(
|
return TwoGangGlassSwitchBatchControlView(
|
||||||
deviceIds: devices.where((e) => (e.productType == '2GT')).map((e) => e.uuid!).toList(),
|
deviceIds: devices
|
||||||
|
.where((e) => (e.productType == '2GT'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case '3GT':
|
case '3GT':
|
||||||
return ThreeGangGlassSwitchBatchControlView(
|
return ThreeGangGlassSwitchBatchControlView(
|
||||||
deviceIds: devices.where((e) => (e.productType == '3GT')).map((e) => e.uuid!).toList(),
|
deviceIds: devices
|
||||||
|
.where((e) => (e.productType == '3GT'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case 'GW':
|
case 'GW':
|
||||||
return GatewayBatchControlView(
|
return GatewayBatchControlView(
|
||||||
gatewayIds: devices.where((e) => (e.productType == 'GW')).map((e) => e.uuid!).toList(),
|
gatewayIds: devices
|
||||||
|
.where((e) => (e.productType == 'GW'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case 'DL':
|
case 'DL':
|
||||||
return DoorLockBatchControlView(
|
return DoorLockBatchControlView(
|
||||||
devicesIds: devices.where((e) => (e.productType == 'DL')).map((e) => e.uuid!).toList());
|
devicesIds: devices
|
||||||
|
.where((e) => (e.productType == 'DL'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList());
|
||||||
case 'WPS':
|
case 'WPS':
|
||||||
return WallSensorBatchControlView(
|
return WallSensorBatchControlView(
|
||||||
devicesIds: devices.where((e) => (e.productType == 'WPS')).map((e) => e.uuid!).toList());
|
devicesIds: devices
|
||||||
|
.where((e) => (e.productType == 'WPS'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList());
|
||||||
case 'CPS':
|
case 'CPS':
|
||||||
return CeilingSensorBatchControlView(
|
return CeilingSensorBatchControlView(
|
||||||
devicesIds: devices.where((e) => (e.productType == 'CPS')).map((e) => e.uuid!).toList(),
|
devicesIds: devices
|
||||||
|
.where((e) => (e.productType == 'CPS'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case 'CUR':
|
case 'CUR':
|
||||||
return CurtainBatchStatusView(
|
return CurtainBatchStatusView(
|
||||||
devicesIds: devices.where((e) => (e.productType == 'CUR')).map((e) => e.uuid!).toList(),
|
devicesIds: devices
|
||||||
|
.where((e) => (e.productType == 'CUR'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case 'AC':
|
case 'AC':
|
||||||
return AcDeviceBatchControlView(
|
return AcDeviceBatchControlView(
|
||||||
devicesIds: devices.where((e) => (e.productType == 'AC')).map((e) => e.uuid!).toList());
|
devicesIds: devices
|
||||||
|
.where((e) => (e.productType == 'AC'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList());
|
||||||
case 'WH':
|
case 'WH':
|
||||||
return WaterHEaterBatchControlView(
|
return WaterHEaterBatchControlView(
|
||||||
deviceIds: devices.where((e) => (e.productType == 'WH')).map((e) => e.uuid!).toList(),
|
deviceIds: devices
|
||||||
|
.where((e) => (e.productType == 'WH'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
case 'DS':
|
case 'DS':
|
||||||
return MainDoorSensorBatchView(
|
return MainDoorSensorBatchView(
|
||||||
devicesIds: devices.where((e) => (e.productType == 'DS')).map((e) => e.uuid!).toList(),
|
devicesIds: devices
|
||||||
|
.where((e) => (e.productType == 'DS'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
case 'GD':
|
||||||
|
return GarageDoorBatchControlView(
|
||||||
|
deviceIds: devices
|
||||||
|
.where((e) => (e.productType == 'GD'))
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
|
@ -35,6 +35,9 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
on<BackToGarageDoorGridViewEvent>(_backToGridView);
|
on<BackToGarageDoorGridViewEvent>(_backToGridView);
|
||||||
on<UpdateCountdownAlarmEvent>(_onUpdateCountdownAlarm);
|
on<UpdateCountdownAlarmEvent>(_onUpdateCountdownAlarm);
|
||||||
on<UpdateTrTimeConEvent>(_onUpdateTrTimeCon);
|
on<UpdateTrTimeConEvent>(_onUpdateTrTimeCon);
|
||||||
|
on<GarageDoorBatchControlEvent>(_onBatchControl);
|
||||||
|
on<GarageDoorFetchBatchStatusEvent>(_onFetchBatchStatus);
|
||||||
|
on<GarageDoorFactoryResetEvent>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchGarageDoorStatus(
|
void _fetchGarageDoorStatus(
|
||||||
@ -50,6 +53,20 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onFetchBatchStatus(GarageDoorFetchBatchStatusEvent event,
|
||||||
|
Emitter<GarageDoorState> emit) async {
|
||||||
|
emit(GarageDoorLoadingState());
|
||||||
|
try {
|
||||||
|
final status =
|
||||||
|
await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||||
|
deviceStatus =
|
||||||
|
GarageDoorStatusModel.fromJson(event.deviceIds.first, status.status);
|
||||||
|
emit(GarageDoorBatchStatusLoaded(deviceStatus));
|
||||||
|
} catch (e) {
|
||||||
|
emit(GarageDoorBatchControlError(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _addSchedule(
|
Future<void> _addSchedule(
|
||||||
AddGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
AddGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
@ -222,6 +239,27 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onBatchControl(
|
||||||
|
GarageDoorBatchControlEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
|
final oldValue = event.code == 'switch_1' ? deviceStatus.switch1 : false;
|
||||||
|
|
||||||
|
_updateLocalValue(event.code, event.value);
|
||||||
|
emit(GarageDoorBatchStatusLoaded(deviceStatus));
|
||||||
|
|
||||||
|
final success = await _runDeBouncer(
|
||||||
|
deviceId: event.deviceIds,
|
||||||
|
code: event.code,
|
||||||
|
value: event.value,
|
||||||
|
oldValue: oldValue,
|
||||||
|
emit: emit,
|
||||||
|
isBatch: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
_revertValue(event.code, oldValue, emit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _backToGridView(
|
void _backToGridView(
|
||||||
BackToGarageDoorGridViewEvent event, Emitter<GarageDoorState> emit) {
|
BackToGarageDoorGridViewEvent event, Emitter<GarageDoorState> emit) {
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
@ -263,6 +301,22 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onFactoryReset(
|
||||||
|
GarageDoorFactoryResetEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
|
emit(GarageDoorLoadingState());
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi()
|
||||||
|
.factoryReset(event.factoryReset, event.deviceId);
|
||||||
|
if (!response) {
|
||||||
|
emit(const GarageDoorErrorState(message: 'Failed to reset device'));
|
||||||
|
} else {
|
||||||
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(GarageDoorErrorState(message: e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _increaseDelay(
|
void _increaseDelay(
|
||||||
IncreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
|
IncreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
// if (deviceStatus.countdown1 != 0) {
|
// if (deviceStatus.countdown1 != 0) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
|
||||||
abstract class GarageDoorEvent extends Equatable {
|
abstract class GarageDoorEvent extends Equatable {
|
||||||
const GarageDoorEvent();
|
const GarageDoorEvent();
|
||||||
@ -180,3 +181,40 @@ class UpdateTrTimeConEvent extends GarageDoorEvent {
|
|||||||
|
|
||||||
const UpdateTrTimeConEvent(this.trTimeCon);
|
const UpdateTrTimeConEvent(this.trTimeCon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GarageDoorBatchControlEvent extends GarageDoorEvent {
|
||||||
|
final List<String> deviceIds;
|
||||||
|
final String code;
|
||||||
|
final bool value;
|
||||||
|
|
||||||
|
const GarageDoorBatchControlEvent({
|
||||||
|
required this.deviceIds,
|
||||||
|
required this.code,
|
||||||
|
required this.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [deviceIds, code, value];
|
||||||
|
}
|
||||||
|
|
||||||
|
class GarageDoorFetchBatchStatusEvent extends GarageDoorEvent {
|
||||||
|
final List<String> deviceIds;
|
||||||
|
|
||||||
|
const GarageDoorFetchBatchStatusEvent(this.deviceIds);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [deviceIds];
|
||||||
|
}
|
||||||
|
|
||||||
|
class GarageDoorFactoryResetEvent extends GarageDoorEvent {
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
final String deviceId;
|
||||||
|
|
||||||
|
const GarageDoorFactoryResetEvent({
|
||||||
|
required this.factoryReset,
|
||||||
|
required this.deviceId,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [factoryReset, deviceId];
|
||||||
|
}
|
||||||
|
@ -121,3 +121,21 @@ class ShowGarageDoorDescriptionState extends GarageDoorState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ScheduleGarageLoadingState extends GarageDoorState {}
|
class ScheduleGarageLoadingState extends GarageDoorState {}
|
||||||
|
|
||||||
|
class GarageDoorBatchStatusLoaded extends GarageDoorState {
|
||||||
|
final GarageDoorStatusModel status;
|
||||||
|
|
||||||
|
const GarageDoorBatchStatusLoaded(this.status);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [status];
|
||||||
|
}
|
||||||
|
|
||||||
|
class GarageDoorBatchControlError extends GarageDoorState {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const GarageDoorBatchControlError(this.message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [message];
|
||||||
|
}
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
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/garage_door/bloc/garage_door_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/models/garage_door_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/toggle_widget.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
|
class GarageDoorBatchControlView extends StatelessWidget
|
||||||
|
with HelperResponsiveLayout {
|
||||||
|
final List<String> deviceIds;
|
||||||
|
|
||||||
|
const GarageDoorBatchControlView({Key? key, required this.deviceIds})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocProvider(
|
||||||
|
create: (context) => GarageDoorBloc(deviceId: deviceIds.first)
|
||||||
|
..add(GarageDoorFetchBatchStatusEvent(deviceIds)),
|
||||||
|
child: BlocBuilder<GarageDoorBloc, GarageDoorState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
if (state is GarageDoorLoadingState) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
} else if (state is GarageDoorBatchStatusLoaded) {
|
||||||
|
return _buildStatusControls(context, state.status);
|
||||||
|
} else if (state is GarageDoorBatchControlError) {
|
||||||
|
return Center(child: Text('Error: ${state.message}'));
|
||||||
|
} else {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStatusControls(
|
||||||
|
BuildContext context, GarageDoorStatusModel status) {
|
||||||
|
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||||
|
final isLarge = isLargeScreenSize(context);
|
||||||
|
final isMedium = isMediumScreenSize(context);
|
||||||
|
return GridView(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: isLarge || isExtraLarge
|
||||||
|
? 3
|
||||||
|
: isMedium
|
||||||
|
? 2
|
||||||
|
: 1,
|
||||||
|
mainAxisExtent: 140,
|
||||||
|
crossAxisSpacing: 12,
|
||||||
|
mainAxisSpacing: 12,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
ToggleWidget(
|
||||||
|
value: status.switch1,
|
||||||
|
code: 'switch_1',
|
||||||
|
deviceId: deviceIds.first,
|
||||||
|
label: 'Garage Door',
|
||||||
|
icon: status.switch1 ? Assets.openedDoor : Assets.closedDoor,
|
||||||
|
onChange: (value) {
|
||||||
|
context.read<GarageDoorBloc>().add(
|
||||||
|
GarageDoorBatchControlEvent(
|
||||||
|
deviceIds: deviceIds,
|
||||||
|
code: 'switch_1',
|
||||||
|
value: value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
FirmwareUpdateWidget(
|
||||||
|
deviceId: deviceIds.first,
|
||||||
|
version: 12,
|
||||||
|
),
|
||||||
|
FactoryResetWidget(
|
||||||
|
callFactoryReset: () {
|
||||||
|
context.read<GarageDoorBloc>().add(
|
||||||
|
GarageDoorFactoryResetEvent(
|
||||||
|
deviceId: deviceIds.first,
|
||||||
|
factoryReset: FactoryResetModel(devicesUuid: deviceIds),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,38 +3,45 @@ import 'dart:async';
|
|||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.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/one_g_glass_switch/models/once_gang_glass_status_model.dart';
|
import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/models/once_gang_glass_status_model.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
|
|
||||||
part 'one_gang_glass_switch_event.dart';
|
part 'one_gang_glass_switch_event.dart';
|
||||||
part 'one_gang_glass_switch_state.dart';
|
part 'one_gang_glass_switch_state.dart';
|
||||||
|
|
||||||
class OneGangGlassSwitchBloc extends Bloc<OneGangGlassSwitchEvent, OneGangGlassSwitchState> {
|
class OneGangGlassSwitchBloc
|
||||||
|
extends Bloc<OneGangGlassSwitchEvent, OneGangGlassSwitchState> {
|
||||||
OneGangGlassStatusModel deviceStatus;
|
OneGangGlassStatusModel deviceStatus;
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
|
|
||||||
OneGangGlassSwitchBloc({required String deviceId})
|
OneGangGlassSwitchBloc({required String deviceId})
|
||||||
: deviceStatus = OneGangGlassStatusModel(uuid: deviceId, switch1: false, countDown: 0),
|
: deviceStatus = OneGangGlassStatusModel(
|
||||||
|
uuid: deviceId, switch1: false, countDown: 0),
|
||||||
super(OneGangGlassSwitchInitial()) {
|
super(OneGangGlassSwitchInitial()) {
|
||||||
on<OneGangGlassSwitchFetchDeviceEvent>(_onFetchDeviceStatus);
|
on<OneGangGlassSwitchFetchDeviceEvent>(_onFetchDeviceStatus);
|
||||||
on<OneGangGlassSwitchControl>(_onControl);
|
on<OneGangGlassSwitchControl>(_onControl);
|
||||||
on<OneGangGlassSwitchBatchControl>(_onBatchControl);
|
on<OneGangGlassSwitchBatchControl>(_onBatchControl);
|
||||||
on<OneGangGlassSwitchFetchBatchStatusEvent>(_onFetchBatchStatus);
|
on<OneGangGlassSwitchFetchBatchStatusEvent>(_onFetchBatchStatus);
|
||||||
|
on<OneGangGlassFactoryResetEvent>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onFetchDeviceStatus(
|
Future<void> _onFetchDeviceStatus(OneGangGlassSwitchFetchDeviceEvent event,
|
||||||
OneGangGlassSwitchFetchDeviceEvent event, Emitter<OneGangGlassSwitchState> emit) async {
|
Emitter<OneGangGlassSwitchState> emit) async {
|
||||||
emit(OneGangGlassSwitchLoading());
|
emit(OneGangGlassSwitchLoading());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
final status =
|
||||||
deviceStatus = OneGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
|
deviceStatus =
|
||||||
|
OneGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
||||||
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(OneGangGlassSwitchError(e.toString()));
|
emit(OneGangGlassSwitchError(e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onControl(OneGangGlassSwitchControl event, Emitter<OneGangGlassSwitchState> emit) async {
|
Future<void> _onControl(OneGangGlassSwitchControl event,
|
||||||
|
Emitter<OneGangGlassSwitchState> emit) async {
|
||||||
final oldValue = _getValueByCode(event.code);
|
final oldValue = _getValueByCode(event.code);
|
||||||
|
|
||||||
_updateLocalValue(event.code, event.value);
|
_updateLocalValue(event.code, event.value);
|
||||||
@ -50,7 +57,24 @@ class OneGangGlassSwitchBloc extends Bloc<OneGangGlassSwitchEvent, OneGangGlassS
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onBatchControl(OneGangGlassSwitchBatchControl event, Emitter<OneGangGlassSwitchState> emit) async {
|
Future<void> _onFactoryReset(OneGangGlassFactoryResetEvent event,
|
||||||
|
Emitter<OneGangGlassSwitchState> emit) async {
|
||||||
|
emit(OneGangGlassSwitchLoading());
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi()
|
||||||
|
.factoryReset(event.factoryReset, event.deviceId);
|
||||||
|
if (!response) {
|
||||||
|
emit(OneGangGlassSwitchError('Failed to reset device'));
|
||||||
|
} else {
|
||||||
|
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(OneGangGlassSwitchError(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onBatchControl(OneGangGlassSwitchBatchControl event,
|
||||||
|
Emitter<OneGangGlassSwitchState> emit) async {
|
||||||
final oldValue = _getValueByCode(event.code);
|
final oldValue = _getValueByCode(event.code);
|
||||||
|
|
||||||
_updateLocalValue(event.code, event.value);
|
_updateLocalValue(event.code, event.value);
|
||||||
@ -67,11 +91,14 @@ class OneGangGlassSwitchBloc extends Bloc<OneGangGlassSwitchEvent, OneGangGlassS
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onFetchBatchStatus(
|
Future<void> _onFetchBatchStatus(
|
||||||
OneGangGlassSwitchFetchBatchStatusEvent event, Emitter<OneGangGlassSwitchState> emit) async {
|
OneGangGlassSwitchFetchBatchStatusEvent event,
|
||||||
|
Emitter<OneGangGlassSwitchState> emit) async {
|
||||||
emit(OneGangGlassSwitchLoading());
|
emit(OneGangGlassSwitchLoading());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
final status =
|
||||||
deviceStatus = OneGangGlassStatusModel.fromJson(event.deviceIds.first, status.status);
|
await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||||
|
deviceStatus = OneGangGlassStatusModel.fromJson(
|
||||||
|
event.deviceIds.first, status.status);
|
||||||
emit(OneGangGlassSwitchBatchStatusLoaded(deviceStatus));
|
emit(OneGangGlassSwitchBatchStatusLoaded(deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(OneGangGlassSwitchError(e.toString()));
|
emit(OneGangGlassSwitchError(e.toString()));
|
||||||
@ -101,9 +128,11 @@ class OneGangGlassSwitchBloc extends Bloc<OneGangGlassSwitchEvent, OneGangGlassS
|
|||||||
try {
|
try {
|
||||||
late bool response;
|
late bool response;
|
||||||
if (isBatch) {
|
if (isBatch) {
|
||||||
response = await DevicesManagementApi().deviceBatchControl(deviceId, code, value);
|
response = await DevicesManagementApi()
|
||||||
|
.deviceBatchControl(deviceId, code, value);
|
||||||
} else {
|
} else {
|
||||||
response = await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value));
|
response = await DevicesManagementApi()
|
||||||
|
.deviceControl(deviceId, Status(code: code, value: value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
@ -115,7 +144,8 @@ class OneGangGlassSwitchBloc extends Bloc<OneGangGlassSwitchEvent, OneGangGlassS
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _revertValueAndEmit(String deviceId, String code, bool oldValue, Emitter<OneGangGlassSwitchState> emit) {
|
void _revertValueAndEmit(String deviceId, String code, bool oldValue,
|
||||||
|
Emitter<OneGangGlassSwitchState> emit) {
|
||||||
_updateLocalValue(code, oldValue);
|
_updateLocalValue(code, oldValue);
|
||||||
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
||||||
}
|
}
|
||||||
|
@ -38,3 +38,13 @@ class OneGangGlassSwitchFetchBatchStatusEvent extends OneGangGlassSwitchEvent {
|
|||||||
|
|
||||||
OneGangGlassSwitchFetchBatchStatusEvent(this.deviceIds);
|
OneGangGlassSwitchFetchBatchStatusEvent(this.deviceIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class OneGangGlassFactoryResetEvent extends OneGangGlassSwitchEvent {
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
final String deviceId;
|
||||||
|
|
||||||
|
OneGangGlassFactoryResetEvent({
|
||||||
|
required this.factoryReset,
|
||||||
|
required this.deviceId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -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_g_glass_switch/bloc/one_gang_glass_switch_bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/bloc/one_gang_glass_switch_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/models/once_gang_glass_status_model.dart';
|
import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/models/once_gang_glass_status_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';
|
||||||
@ -7,16 +8,18 @@ import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware
|
|||||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.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';
|
||||||
|
|
||||||
class OneGangGlassSwitchBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
class OneGangGlassSwitchBatchControlView extends StatelessWidget
|
||||||
|
with HelperResponsiveLayout {
|
||||||
final List<String> deviceIds;
|
final List<String> deviceIds;
|
||||||
|
|
||||||
const OneGangGlassSwitchBatchControlView({required this.deviceIds, super.key});
|
const OneGangGlassSwitchBatchControlView(
|
||||||
|
{required this.deviceIds, super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) =>
|
create: (context) => OneGangGlassSwitchBloc(deviceId: deviceIds.first)
|
||||||
OneGangGlassSwitchBloc(deviceId: deviceIds.first)..add(OneGangGlassSwitchFetchBatchStatusEvent(deviceIds)),
|
..add(OneGangGlassSwitchFetchBatchStatusEvent(deviceIds)),
|
||||||
child: BlocBuilder<OneGangGlassSwitchBloc, OneGangGlassSwitchState>(
|
child: BlocBuilder<OneGangGlassSwitchBloc, OneGangGlassSwitchState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is OneGangGlassSwitchLoading) {
|
if (state is OneGangGlassSwitchLoading) {
|
||||||
@ -33,7 +36,8 @@ class OneGangGlassSwitchBatchControlView extends StatelessWidget with HelperResp
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildStatusControls(BuildContext context, OneGangGlassStatusModel status) {
|
Widget _buildStatusControls(
|
||||||
|
BuildContext context, OneGangGlassStatusModel status) {
|
||||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||||
final isLarge = isLargeScreenSize(context);
|
final isLarge = isLargeScreenSize(context);
|
||||||
final isMedium = isMediumScreenSize(context);
|
final isMedium = isMediumScreenSize(context);
|
||||||
@ -72,7 +76,14 @@ class OneGangGlassSwitchBatchControlView extends StatelessWidget with HelperResp
|
|||||||
version: 12, // adjust the version according to your requirement
|
version: 12, // adjust the version according to your requirement
|
||||||
),
|
),
|
||||||
FactoryResetWidget(
|
FactoryResetWidget(
|
||||||
callFactoryReset: () {},
|
callFactoryReset: () {
|
||||||
|
context.read<OneGangGlassSwitchBloc>().add(
|
||||||
|
OneGangGlassFactoryResetEvent(
|
||||||
|
factoryReset: FactoryResetModel(devicesUuid: deviceIds),
|
||||||
|
deviceId: deviceIds.first,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -33,7 +33,8 @@ class ThreeGangGlassSwitchBatchControl extends ThreeGangGlassSwitchEvent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class ThreeGangGlassSwitchFetchBatchStatusEvent extends ThreeGangGlassSwitchEvent {
|
class ThreeGangGlassSwitchFetchBatchStatusEvent
|
||||||
|
extends ThreeGangGlassSwitchEvent {
|
||||||
final List<String> deviceIds;
|
final List<String> deviceIds;
|
||||||
|
|
||||||
ThreeGangGlassSwitchFetchBatchStatusEvent(this.deviceIds);
|
ThreeGangGlassSwitchFetchBatchStatusEvent(this.deviceIds);
|
||||||
|
@ -10,13 +10,18 @@ import 'package:syncrow_web/services/devices_mang_api.dart';
|
|||||||
part 'two_gang_glass_switch_event.dart';
|
part 'two_gang_glass_switch_event.dart';
|
||||||
part 'two_gang_glass_switch_state.dart';
|
part 'two_gang_glass_switch_state.dart';
|
||||||
|
|
||||||
class TwoGangGlassSwitchBloc extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassSwitchState> {
|
class TwoGangGlassSwitchBloc
|
||||||
|
extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassSwitchState> {
|
||||||
TwoGangGlassStatusModel deviceStatus;
|
TwoGangGlassStatusModel deviceStatus;
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
|
|
||||||
TwoGangGlassSwitchBloc({required String deviceId})
|
TwoGangGlassSwitchBloc({required String deviceId})
|
||||||
: deviceStatus =
|
: deviceStatus = TwoGangGlassStatusModel(
|
||||||
TwoGangGlassStatusModel(uuid: deviceId, switch1: false, countDown1: 0, switch2: false, countDown2: 0),
|
uuid: deviceId,
|
||||||
|
switch1: false,
|
||||||
|
countDown1: 0,
|
||||||
|
switch2: false,
|
||||||
|
countDown2: 0),
|
||||||
super(TwoGangGlassSwitchInitial()) {
|
super(TwoGangGlassSwitchInitial()) {
|
||||||
on<TwoGangGlassSwitchFetchDeviceEvent>(_onFetchDeviceStatus);
|
on<TwoGangGlassSwitchFetchDeviceEvent>(_onFetchDeviceStatus);
|
||||||
on<TwoGangGlassSwitchControl>(_onControl);
|
on<TwoGangGlassSwitchControl>(_onControl);
|
||||||
@ -25,19 +30,22 @@ class TwoGangGlassSwitchBloc extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassS
|
|||||||
on<TwoGangGlassFactoryReset>(_onFactoryReset);
|
on<TwoGangGlassFactoryReset>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onFetchDeviceStatus(
|
Future<void> _onFetchDeviceStatus(TwoGangGlassSwitchFetchDeviceEvent event,
|
||||||
TwoGangGlassSwitchFetchDeviceEvent event, Emitter<TwoGangGlassSwitchState> emit) async {
|
Emitter<TwoGangGlassSwitchState> emit) async {
|
||||||
emit(TwoGangGlassSwitchLoading());
|
emit(TwoGangGlassSwitchLoading());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
final status =
|
||||||
deviceStatus = TwoGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
|
deviceStatus =
|
||||||
|
TwoGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
||||||
emit(TwoGangGlassSwitchStatusLoaded(deviceStatus));
|
emit(TwoGangGlassSwitchStatusLoaded(deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(TwoGangGlassSwitchError(e.toString()));
|
emit(TwoGangGlassSwitchError(e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onControl(TwoGangGlassSwitchControl event, Emitter<TwoGangGlassSwitchState> emit) async {
|
Future<void> _onControl(TwoGangGlassSwitchControl event,
|
||||||
|
Emitter<TwoGangGlassSwitchState> emit) async {
|
||||||
final oldValue = _getValueByCode(event.code);
|
final oldValue = _getValueByCode(event.code);
|
||||||
|
|
||||||
_updateLocalValue(event.code, event.value);
|
_updateLocalValue(event.code, event.value);
|
||||||
@ -53,7 +61,8 @@ class TwoGangGlassSwitchBloc extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassS
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onBatchControl(TwoGangGlassSwitchBatchControl event, Emitter<TwoGangGlassSwitchState> emit) async {
|
Future<void> _onBatchControl(TwoGangGlassSwitchBatchControl event,
|
||||||
|
Emitter<TwoGangGlassSwitchState> emit) async {
|
||||||
final oldValue = _getValueByCode(event.code);
|
final oldValue = _getValueByCode(event.code);
|
||||||
|
|
||||||
_updateLocalValue(event.code, event.value);
|
_updateLocalValue(event.code, event.value);
|
||||||
@ -70,21 +79,26 @@ class TwoGangGlassSwitchBloc extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassS
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onFetchBatchStatus(
|
Future<void> _onFetchBatchStatus(
|
||||||
TwoGangGlassSwitchFetchBatchStatusEvent event, Emitter<TwoGangGlassSwitchState> emit) async {
|
TwoGangGlassSwitchFetchBatchStatusEvent event,
|
||||||
|
Emitter<TwoGangGlassSwitchState> emit) async {
|
||||||
emit(TwoGangGlassSwitchLoading());
|
emit(TwoGangGlassSwitchLoading());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
final status =
|
||||||
deviceStatus = TwoGangGlassStatusModel.fromJson(event.deviceIds.first, status.status);
|
await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||||
|
deviceStatus = TwoGangGlassStatusModel.fromJson(
|
||||||
|
event.deviceIds.first, status.status);
|
||||||
emit(TwoGangGlassSwitchBatchStatusLoaded(deviceStatus));
|
emit(TwoGangGlassSwitchBatchStatusLoaded(deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(TwoGangGlassSwitchError(e.toString()));
|
emit(TwoGangGlassSwitchError(e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onFactoryReset(TwoGangGlassFactoryReset event, Emitter<TwoGangGlassSwitchState> emit) async {
|
Future<void> _onFactoryReset(TwoGangGlassFactoryReset event,
|
||||||
|
Emitter<TwoGangGlassSwitchState> emit) async {
|
||||||
emit(TwoGangGlassSwitchLoading());
|
emit(TwoGangGlassSwitchLoading());
|
||||||
try {
|
try {
|
||||||
final response = await DevicesManagementApi().factoryReset(event.factoryReset, event.deviceId);
|
final response = await DevicesManagementApi()
|
||||||
|
.factoryReset(event.factoryReset, event.deviceId);
|
||||||
if (!response) {
|
if (!response) {
|
||||||
emit(TwoGangGlassSwitchError('Failed'));
|
emit(TwoGangGlassSwitchError('Failed'));
|
||||||
} else {
|
} else {
|
||||||
@ -118,9 +132,11 @@ class TwoGangGlassSwitchBloc extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassS
|
|||||||
try {
|
try {
|
||||||
late bool response;
|
late bool response;
|
||||||
if (isBatch) {
|
if (isBatch) {
|
||||||
response = await DevicesManagementApi().deviceBatchControl(deviceId, code, value);
|
response = await DevicesManagementApi()
|
||||||
|
.deviceBatchControl(deviceId, code, value);
|
||||||
} else {
|
} else {
|
||||||
response = await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value));
|
response = await DevicesManagementApi()
|
||||||
|
.deviceControl(deviceId, Status(code: code, value: value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
@ -132,7 +148,8 @@ class TwoGangGlassSwitchBloc extends Bloc<TwoGangGlassSwitchEvent, TwoGangGlassS
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _revertValueAndEmit(String deviceId, String code, bool oldValue, Emitter<TwoGangGlassSwitchState> emit) {
|
void _revertValueAndEmit(String deviceId, String code, bool oldValue,
|
||||||
|
Emitter<TwoGangGlassSwitchState> emit) {
|
||||||
_updateLocalValue(code, oldValue);
|
_updateLocalValue(code, oldValue);
|
||||||
emit(TwoGangGlassSwitchStatusLoaded(deviceStatus));
|
emit(TwoGangGlassSwitchStatusLoaded(deviceStatus));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user