diff --git a/assets/icons/main_door.svg b/assets/icons/main_door.svg
new file mode 100644
index 00000000..5f378012
--- /dev/null
+++ b/assets/icons/main_door.svg
@@ -0,0 +1,23 @@
+
diff --git a/assets/icons/main_door_notifi.svg b/assets/icons/main_door_notifi.svg
new file mode 100644
index 00000000..34d44e1c
--- /dev/null
+++ b/assets/icons/main_door_notifi.svg
@@ -0,0 +1,10 @@
+
diff --git a/assets/icons/main_door_reports.svg b/assets/icons/main_door_reports.svg
new file mode 100644
index 00000000..f0eb413a
--- /dev/null
+++ b/assets/icons/main_door_reports.svg
@@ -0,0 +1,18 @@
+
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 2872ee6d..5065ec31 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
@@ -11,6 +11,7 @@ import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_batc
import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_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_view.dart';
+import 'package:syncrow_web/pages/device_managment/main_door_sensor/view/main_door_control_view.dart';
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_batch_control.dart';
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_device_control.dart';
import 'package:syncrow_web/pages/device_managment/three_gang_switch/view/living_room_batch_controls.dart';
@@ -55,7 +56,11 @@ mixin RouteControlsBasedCode {
case 'AC':
return AcDeviceControlsView(device: device);
case 'WH':
- return WaterHeaterDeviceControl(device: device,);
+ return WaterHeaterDeviceControl(
+ device: device,
+ );
+ case 'DS':
+ return MainDoorSensorControlView(device: device);
default:
return const SizedBox();
}
diff --git a/lib/pages/device_managment/main_door_sensor/bloc/main_door_sensor_bloc.dart b/lib/pages/device_managment/main_door_sensor/bloc/main_door_sensor_bloc.dart
new file mode 100644
index 00000000..bb72f1d3
--- /dev/null
+++ b/lib/pages/device_managment/main_door_sensor/bloc/main_door_sensor_bloc.dart
@@ -0,0 +1,139 @@
+import 'dart:async';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
+import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_event.dart';
+import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_state.dart';
+import 'package:syncrow_web/pages/device_managment/main_door_sensor/models/main_door_status_model.dart';
+import 'package:syncrow_web/services/devices_mang_api.dart';
+
+class MainDoorSensorBloc
+ extends Bloc {
+ MainDoorSensorBloc() : super(MainDoorSensorInitial()) {
+ on(_onFetchDeviceStatus);
+ on(_onControl);
+ on(_onFetchBatchStatus);
+ on(_fetchReports);
+ }
+
+ late MainDoorSensorStatusModel deviceStatus;
+ Timer? _timer;
+
+ FutureOr _onFetchDeviceStatus(MainDoorSensorFetchDeviceEvent event,
+ Emitter emit) async {
+ emit(MainDoorSensorLoadingState());
+ try {
+ final status = await DevicesManagementApi()
+ .getDeviceStatus(event.deviceId)
+ .then((value) => value.status);
+
+ deviceStatus = MainDoorSensorStatusModel.fromJson(event.deviceId, status);
+ emit(MainDoorSensorDeviceStatusLoaded(deviceStatus));
+ } catch (e) {
+ emit(MainDoorSensorFailedState(error: e.toString()));
+ }
+ }
+
+ FutureOr _onControl(
+ MainDoorSensorControl event, Emitter emit) async {
+ final oldValue = _getValueByCode(event.code);
+
+ _updateLocalValue(event.code, event.value);
+
+ emit(MainDoorSensorDeviceStatusLoaded(deviceStatus));
+
+ await _runDebounce(
+ deviceId: event.deviceId,
+ code: event.code,
+ value: event.value,
+ oldValue: oldValue,
+ emit: emit,
+ );
+ }
+
+ Future _runDebounce({
+ required String deviceId,
+ required String code,
+ required bool value,
+ required bool oldValue,
+ required Emitter emit,
+ }) async {
+ if (_timer != null) {
+ _timer!.cancel();
+ }
+
+ _timer = Timer(const Duration(milliseconds: 500), () async {
+ try {
+ final status = await DevicesManagementApi()
+ .deviceControl(deviceId, Status(code: code, value: value));
+
+ if (!status) {
+ _revertValueAndEmit(deviceId, code, oldValue, emit);
+ }
+
+ emit(MainDoorSensorDeviceStatusLoaded(deviceStatus));
+ } catch (e) {
+ emit(MainDoorSensorFailedState(error: e.toString()));
+ }
+ });
+ }
+
+ void _revertValueAndEmit(String deviceId, String code, bool oldValue,
+ Emitter emit) {
+ _updateLocalValue(code, oldValue);
+ emit(MainDoorSensorDeviceStatusLoaded(deviceStatus));
+ }
+
+ void _updateLocalValue(String code, bool value) {
+ switch (code) {
+ case 'doorcontact_state':
+ deviceStatus = deviceStatus.copyWith(doorContactState: value);
+ break;
+ default:
+ break;
+ }
+ }
+
+ // Retrieve the current value by code
+ bool _getValueByCode(String code) {
+ switch (code) {
+ case 'doorcontact_state':
+ return deviceStatus.doorContactState;
+ default:
+ return false;
+ }
+ }
+
+ // Fetch batch status for multiple devices (if needed)
+ FutureOr _onFetchBatchStatus(MainDoorSensorFetchBatchEvent event,
+ Emitter emit) async {
+ emit(MainDoorSensorLoadingState());
+ try {
+ // final batchStatus =
+ // await DevicesManagementApi().getBatchDeviceStatus(event.deviceIds);
+ // Assuming you need to update multiple devices status here
+ // You might need a list or map of MainDoorSensorStatusModel for batch processing
+ // emit(MainDoorSensorBatchStatusLoaded(batchStatus));
+ } catch (e) {
+ emit(MainDoorSensorBatchFailedState(error: e.toString()));
+ }
+ }
+
+ // Fetch reports related to the main door sensor
+ FutureOr _fetchReports(MainDoorSensorReportsEvent event,
+ Emitter emit) async {
+ emit(MainDoorSensorLoadingState());
+ try {
+ final reports = await DevicesManagementApi.getDeviceReports(
+ event.deviceId, event.code);
+ emit(MainDoorSensorReportLoaded(reports));
+ } catch (e) {
+ emit(MainDoorSensorFailedState(error: e.toString()));
+ }
+ }
+
+ @override
+ Future close() {
+ _timer?.cancel();
+ return super.close();
+ }
+}
diff --git a/lib/pages/device_managment/main_door_sensor/bloc/main_door_sensor_event.dart b/lib/pages/device_managment/main_door_sensor/bloc/main_door_sensor_event.dart
new file mode 100644
index 00000000..4db304b0
--- /dev/null
+++ b/lib/pages/device_managment/main_door_sensor/bloc/main_door_sensor_event.dart
@@ -0,0 +1,55 @@
+import 'package:equatable/equatable.dart';
+
+class MainDoorSensorEvent extends Equatable {
+ @override
+ List