diff --git a/assets/icons/sos.svg b/assets/icons/sos.svg
new file mode 100644
index 00000000..887e9f19
--- /dev/null
+++ b/assets/icons/sos.svg
@@ -0,0 +1,23 @@
+
diff --git a/assets/icons/sos_normal.svg b/assets/icons/sos_normal.svg
new file mode 100644
index 00000000..ea795024
--- /dev/null
+++ b/assets/icons/sos_normal.svg
@@ -0,0 +1,23 @@
+
diff --git a/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart b/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart
index 8edb0a1e..85ecf7b6 100644
--- a/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart
+++ b/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart
@@ -20,6 +20,8 @@ import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_lig
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_device_control.dart';
import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart';
import 'package:syncrow_web/pages/device_managment/power_clamp/view/smart_power_device_control.dart';
+import 'package:syncrow_web/pages/device_managment/sos/view/sos_batch_control_view.dart';
+import 'package:syncrow_web/pages/device_managment/sos/view/sos_device_control_view.dart';
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/view/three_gang_glass_switch_batch_control_view.dart';
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/view/three_gang_glass_switch_control_view.dart';
import 'package:syncrow_web/pages/device_managment/three_gang_switch/view/living_room_batch_controls.dart';
@@ -100,6 +102,8 @@ mixin RouteControlsBasedCode {
return SmartPowerDeviceControl(
deviceId: device.uuid!,
);
+ case 'SOS':
+ return SosDeviceControlsView(device: device);
default:
return const SizedBox();
}
@@ -123,119 +127,72 @@ mixin RouteControlsBasedCode {
switch (devices.first.productType) {
case '1G':
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':
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':
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':
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':
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':
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':
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':
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':
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':
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':
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':
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':
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':
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(),
+ deviceIds: devices.where((e) => (e.productType == 'GD')).map((e) => e.uuid!).toList(),
);
case 'WL':
return WaterLeakBatchControlView(
- deviceIds: devices
- .where((e) => (e.productType == 'WL'))
- .map((e) => e.uuid!)
- .toList(),
+ deviceIds: devices.where((e) => (e.productType == 'WL')).map((e) => e.uuid!).toList(),
);
case 'PC':
return PowerClampBatchControlView(
- deviceIds: devices
- .where((e) => (e.productType == 'PC'))
- .map((e) => e.uuid!)
- .toList(),
+ deviceIds: devices.where((e) => (e.productType == 'PC')).map((e) => e.uuid!).toList(),
+ );
+ case 'SOS':
+ return SOSBatchControlView(
+ deviceIds: devices.where((e) => (e.productType == 'sos')).map((e) => e.uuid!).toList(),
);
default:
return const SizedBox();
diff --git a/lib/pages/device_managment/sos/bloc/sos_device_bloc.dart b/lib/pages/device_managment/sos/bloc/sos_device_bloc.dart
new file mode 100644
index 00000000..e9ed6899
--- /dev/null
+++ b/lib/pages/device_managment/sos/bloc/sos_device_bloc.dart
@@ -0,0 +1,74 @@
+import 'dart:async';
+
+import 'package:bloc/bloc.dart';
+import 'package:equatable/equatable.dart';
+import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
+import 'package:syncrow_web/pages/device_managment/sos/models/sos_status_model.dart';
+import 'package:syncrow_web/services/devices_mang_api.dart';
+
+part 'sos_device_event.dart';
+part 'sos_device_state.dart';
+
+class SosDeviceBloc extends Bloc {
+ SosDeviceBloc() : super(SosDeviceInitial()) {
+ on(_getDeviceStatus);
+ on(_getBatchStatus);
+ on(_getDeviceRecords);
+ on(_getDeviceAutomationRecords);
+ on(_backToSosStatusView);
+ }
+
+ late SosStatusModel deviceStatus;
+
+ FutureOr _getDeviceStatus(GetDeviceStatus event, Emitter emit) async {
+ emit(SosDeviceLoadingState());
+ try {
+ final status = await DevicesManagementApi().getDeviceStatus(event.uuid);
+ deviceStatus = SosStatusModel.fromJson(event.uuid, status.status);
+ emit(SosDeviceLoadedState(deviceStatus));
+ } catch (e) {
+ emit(SosDeviceErrorState(e.toString()));
+ }
+ }
+
+ FutureOr _getBatchStatus(GetBatchStatus event, Emitter emit) async {
+ emit(SosDeviceLoadingState());
+ try {
+ final status = await DevicesManagementApi().getBatchStatus(event.uuids);
+ deviceStatus = SosStatusModel.fromJson(event.uuids.first, status.status);
+ emit(SosDeviceLoadedState(deviceStatus));
+ } catch (e) {
+ emit(SosDeviceErrorState(e.toString()));
+ }
+ }
+
+ FutureOr _getDeviceRecords(GetDeviceRecords event, Emitter emit) async {
+ emit(SosReportLoadingState());
+ try {
+ final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
+ final to = DateTime.now().millisecondsSinceEpoch;
+ final DeviceReport records =
+ await DevicesManagementApi.getDeviceReportsByDate(event.uuid, 'sos', from.toString(), to.toString());
+ emit(SosReportLoadedState(records));
+ } catch (e) {
+ emit(SosReportErrorState(e.toString()));
+ }
+ }
+
+ FutureOr _getDeviceAutomationRecords(GetDeviceAutomationRecords event, Emitter emit) async {
+ emit(SosAutomationReportLoadingState());
+ try {
+ final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
+ final to = DateTime.now().millisecondsSinceEpoch;
+ final DeviceReport records = await DevicesManagementApi.getDeviceReportsByDate(
+ event.uuid, 'sos_automation', from.toString(), to.toString());
+ emit(SosAutomationReportLoadedState(records));
+ } catch (e) {
+ emit(SosAutomationReportErrorState(e.toString()));
+ }
+ }
+
+ FutureOr _backToSosStatusView(BackToSosStatusView event, Emitter emit) {
+ emit(SosDeviceLoadedState(deviceStatus));
+ }
+}
diff --git a/lib/pages/device_managment/sos/bloc/sos_device_event.dart b/lib/pages/device_managment/sos/bloc/sos_device_event.dart
new file mode 100644
index 00000000..c8bb28aa
--- /dev/null
+++ b/lib/pages/device_managment/sos/bloc/sos_device_event.dart
@@ -0,0 +1,39 @@
+part of 'sos_device_bloc.dart';
+
+sealed class SosDeviceEvent extends Equatable {
+ const SosDeviceEvent();
+}
+
+class GetDeviceStatus extends SosDeviceEvent {
+ final String uuid;
+ const GetDeviceStatus(this.uuid);
+ @override
+ List