diff --git a/assets/icons/water_heater.svg b/assets/icons/water_heater.svg
new file mode 100644
index 00000000..aa58e3fc
--- /dev/null
+++ b/assets/icons/water_heater.svg
@@ -0,0 +1,22 @@
+
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 5065ec31..80a00094 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,7 @@ import 'package:syncrow_web/pages/device_managment/two_gang_switch/view/wall_lig
import 'package:syncrow_web/pages/device_managment/two_gang_switch/view/wall_light_device_control.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/view/wall_sensor_batch_control.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/view/wall_sensor_conrtols.dart';
+import 'package:syncrow_web/pages/device_managment/water_heater/view/water_heater_batch_control.dart';
import 'package:syncrow_web/pages/device_managment/water_heater/view/water_heater_device_control.dart';
mixin RouteControlsBasedCode {
@@ -56,7 +57,7 @@ mixin RouteControlsBasedCode {
case 'AC':
return AcDeviceControlsView(device: device);
case 'WH':
- return WaterHeaterDeviceControl(
+ return WaterHeaterDeviceControlView(
device: device,
);
case 'DS':
@@ -140,6 +141,14 @@ mixin RouteControlsBasedCode {
.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(),
+ );
+
default:
return const SizedBox();
}
diff --git a/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart b/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart
index 1eb88912..2e84c011 100644
--- a/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart
+++ b/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart
@@ -17,6 +17,8 @@ class WaterHeaterBloc extends Bloc {
WaterHeaterBloc() : super(WaterHeaterInitial()) {
on(_fetchWaterHeaterStatus);
on(_controlWaterHeater);
+ on(_batchFetchWaterHeater);
+ on(_batchControlWaterHeater);
on(_updateScheduleEvent);
on(_stopScheduleEvent);
on(_onDecrementCountdown);
@@ -145,6 +147,7 @@ class WaterHeaterBloc extends Bloc {
value: event.value,
oldValue: oldValue,
emit: emit,
+ isBatch: false,
);
if (success) {
@@ -395,19 +398,29 @@ class WaterHeaterBloc extends Bloc {
// }
Future _runDebounce({
- required String deviceId,
+ required dynamic deviceId,
required String code,
required dynamic value,
required dynamic oldValue,
required Emitter emit,
+ required bool isBatch,
}) async {
try {
+ late bool status;
await Future.delayed(const Duration(milliseconds: 500));
- final status = await DevicesManagementApi().deviceControl(
- deviceId,
- Status(code: code, value: value),
- );
+ if (isBatch) {
+ status = await DevicesManagementApi().deviceBatchControl(
+ deviceId,
+ code,
+ value,
+ );
+ } else {
+ status = await DevicesManagementApi().deviceControl(
+ deviceId,
+ Status(code: code, value: value),
+ );
+ }
if (!status) {
_revertValue(code, oldValue, emit.call);
@@ -580,4 +593,54 @@ class WaterHeaterBloc extends Bloc {
}
}
}
+
+ FutureOr _batchFetchWaterHeater(FetchWaterHeaterBatchStatusEvent event,
+ Emitter emit) async {
+ emit(WaterHeaterLoadingState());
+
+ try {
+ final status =
+ await DevicesManagementApi().getBatchStatus(event.devicesUuid);
+ deviceStatus = WaterHeaterStatusModel.fromJson(
+ event.devicesUuid.first, status.status);
+
+ emit(WaterHeaterDeviceStatusLoaded(deviceStatus));
+ } catch (e) {
+ emit(WaterHeaterDeviceStatusLoaded(deviceStatus));
+ }
+ }
+
+ FutureOr _batchControlWaterHeater(ControlWaterHeaterBatchEvent event,
+ Emitter emit) async {
+ if (state is WaterHeaterDeviceStatusLoaded) {
+ final currentState = state as WaterHeaterDeviceStatusLoaded;
+
+ final oldValue = _getValueByCode(event.code);
+
+ _updateLocalValue(event.code, event.value);
+
+ emit(currentState.copyWith(
+ status: deviceStatus,
+ ));
+
+ final success = await _runDebounce(
+ deviceId: event.devicesUuid,
+ code: event.code,
+ value: event.value,
+ oldValue: oldValue,
+ emit: emit,
+ isBatch: true,
+ );
+
+ if (success) {
+ if (event.code == "switch_1") {
+ emit(currentState.copyWith(
+ status: deviceStatus,
+ ));
+ }
+ } else {
+ _updateLocalValue(event.code, oldValue);
+ }
+ }
+ }
}
diff --git a/lib/pages/device_managment/water_heater/bloc/water_heater_event.dart b/lib/pages/device_managment/water_heater/bloc/water_heater_event.dart
index bc0909ab..e2e718ae 100644
--- a/lib/pages/device_managment/water_heater/bloc/water_heater_event.dart
+++ b/lib/pages/device_managment/water_heater/bloc/water_heater_event.dart
@@ -52,15 +52,6 @@ final class WaterHeaterFetchStatusEvent extends WaterHeaterEvent {
List