mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
push curtain batch control
This commit is contained in:
@ -1,9 +1,6 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.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/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
@ -12,6 +9,7 @@ class CurtainToggle extends StatelessWidget {
|
|||||||
final String code;
|
final String code;
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
final String label;
|
final String label;
|
||||||
|
final Null Function(dynamic value) onChanged;
|
||||||
|
|
||||||
const CurtainToggle({
|
const CurtainToggle({
|
||||||
super.key,
|
super.key,
|
||||||
@ -19,6 +17,7 @@ class CurtainToggle extends StatelessWidget {
|
|||||||
required this.code,
|
required this.code,
|
||||||
required this.deviceId,
|
required this.deviceId,
|
||||||
required this.label,
|
required this.label,
|
||||||
|
required this.onChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -54,15 +53,7 @@ class CurtainToggle extends StatelessWidget {
|
|||||||
child: CupertinoSwitch(
|
child: CupertinoSwitch(
|
||||||
value: value,
|
value: value,
|
||||||
activeColor: ColorsManager.dialogBlueTitle,
|
activeColor: ColorsManager.dialogBlueTitle,
|
||||||
onChanged: (newValue) {
|
onChanged: onChanged,
|
||||||
context.read<CurtainBloc>().add(
|
|
||||||
CurtainControl(
|
|
||||||
deviceId: deviceId,
|
|
||||||
code: code,
|
|
||||||
value: newValue,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -14,6 +14,7 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
on<CurtainFetchDeviceStatus>(_onFetchDeviceStatus);
|
on<CurtainFetchDeviceStatus>(_onFetchDeviceStatus);
|
||||||
on<CurtainFetchBatchStatus>(_onFetchBatchStatus);
|
on<CurtainFetchBatchStatus>(_onFetchBatchStatus);
|
||||||
on<CurtainControl>(_onCurtainControl);
|
on<CurtainControl>(_onCurtainControl);
|
||||||
|
on<CurtainBatchControl>(_onCurtainBatchControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onFetchDeviceStatus(
|
FutureOr<void> _onFetchDeviceStatus(
|
||||||
@ -45,16 +46,26 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
value: event.value,
|
value: event.value,
|
||||||
oldValue: oldValue,
|
oldValue: oldValue,
|
||||||
emit: emit,
|
emit: emit,
|
||||||
|
isBatch: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _runDebounce({
|
Future<void> _runDebounce({
|
||||||
required String deviceId,
|
required dynamic deviceId,
|
||||||
required String code,
|
required String code,
|
||||||
required bool value,
|
required bool value,
|
||||||
required bool oldValue,
|
required bool oldValue,
|
||||||
required Emitter<CurtainState> emit,
|
required Emitter<CurtainState> emit,
|
||||||
|
required bool isBatch,
|
||||||
}) async {
|
}) async {
|
||||||
|
late String id;
|
||||||
|
|
||||||
|
if (deviceId is List) {
|
||||||
|
id = deviceId.first;
|
||||||
|
} else {
|
||||||
|
id = deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
@ -62,14 +73,20 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
try {
|
try {
|
||||||
final controlValue = value ? 'open' : 'close';
|
final controlValue = value ? 'open' : 'close';
|
||||||
|
|
||||||
final response = await DevicesManagementApi()
|
late bool response;
|
||||||
.deviceControl(deviceId, Status(code: code, value: controlValue));
|
if (isBatch) {
|
||||||
|
response = await DevicesManagementApi()
|
||||||
|
.deviceBatchControl(deviceId, code, controlValue);
|
||||||
|
} else {
|
||||||
|
response = await DevicesManagementApi()
|
||||||
|
.deviceControl(deviceId, Status(code: code, value: controlValue));
|
||||||
|
}
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
_revertValueAndEmit(deviceId, oldValue, emit);
|
_revertValueAndEmit(id, oldValue, emit);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_revertValueAndEmit(deviceId, oldValue, emit);
|
_revertValueAndEmit(id, oldValue, emit);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -95,7 +112,7 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
emit(CurtainStatusLoading());
|
emit(CurtainStatusLoading());
|
||||||
try {
|
try {
|
||||||
final status =
|
final status =
|
||||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||||
|
|
||||||
deviceStatus = _checkStatus(status.status[0].value);
|
deviceStatus = _checkStatus(status.status[0].value);
|
||||||
|
|
||||||
@ -104,4 +121,22 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
|||||||
emit(CurtainError(e.toString()));
|
emit(CurtainError(e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onCurtainBatchControl(
|
||||||
|
CurtainBatchControl event, Emitter<CurtainState> emit) async {
|
||||||
|
final oldValue = deviceStatus;
|
||||||
|
|
||||||
|
_updateLocalValue(event.value, emit);
|
||||||
|
|
||||||
|
emit(CurtainStatusLoaded(deviceStatus));
|
||||||
|
|
||||||
|
await _runDebounce(
|
||||||
|
deviceId: event.devicesIds,
|
||||||
|
code: event.code,
|
||||||
|
value: event.value,
|
||||||
|
oldValue: oldValue,
|
||||||
|
emit: emit,
|
||||||
|
isBatch: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,12 @@ class CurtainFetchDeviceStatus extends CurtainEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CurtainFetchBatchStatus extends CurtainEvent {
|
class CurtainFetchBatchStatus extends CurtainEvent {
|
||||||
final String deviceId;
|
final List<String> devicesIds;
|
||||||
|
|
||||||
const CurtainFetchBatchStatus(this.deviceId);
|
const CurtainFetchBatchStatus(this.devicesIds);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [deviceId];
|
List<Object> get props => [devicesIds];
|
||||||
}
|
}
|
||||||
|
|
||||||
class CurtainControl extends CurtainEvent {
|
class CurtainControl extends CurtainEvent {
|
||||||
@ -36,3 +36,15 @@ class CurtainControl extends CurtainEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [deviceId, code, value];
|
List<Object> get props => [deviceId, code, value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CurtainBatchControl extends CurtainEvent {
|
||||||
|
final List<String> devicesIds;
|
||||||
|
final String code;
|
||||||
|
final bool value;
|
||||||
|
|
||||||
|
const CurtainBatchControl(
|
||||||
|
{required this.devicesIds, required this.code, required this.value});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [devicesIds, code, value];
|
||||||
|
}
|
||||||
|
@ -18,7 +18,7 @@ class CurtainBatchStatusView extends StatelessWidget
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CurtainBloc(deviceId: devicesIds.first)
|
create: (context) => CurtainBloc(deviceId: devicesIds.first)
|
||||||
..add(CurtainFetchDeviceStatus(devicesIds.first)),
|
..add(CurtainFetchBatchStatus(devicesIds)),
|
||||||
child: BlocBuilder<CurtainBloc, CurtainState>(
|
child: BlocBuilder<CurtainBloc, CurtainState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is CurtainStatusLoading) {
|
if (state is CurtainStatusLoading) {
|
||||||
@ -59,6 +59,13 @@ class CurtainBatchStatusView extends StatelessWidget
|
|||||||
code: 'control',
|
code: 'control',
|
||||||
deviceId: devicesIds.first,
|
deviceId: devicesIds.first,
|
||||||
label: 'Curtains',
|
label: 'Curtains',
|
||||||
|
onChanged: (value) {
|
||||||
|
context.read<CurtainBloc>().add(CurtainBatchControl(
|
||||||
|
devicesIds: devicesIds,
|
||||||
|
code: 'control',
|
||||||
|
value: value,
|
||||||
|
));
|
||||||
|
},
|
||||||
),
|
),
|
||||||
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 5),
|
FirmwareUpdateWidget(deviceId: devicesIds.first, version: 5),
|
||||||
FactoryResetWidget(deviceId: devicesIds.first),
|
FactoryResetWidget(deviceId: devicesIds.first),
|
||||||
|
@ -58,6 +58,15 @@ class CurtainStatusControlsView extends StatelessWidget
|
|||||||
code: 'control',
|
code: 'control',
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
label: 'Curtains',
|
label: 'Curtains',
|
||||||
|
onChanged: (value) {
|
||||||
|
context.read<CurtainBloc>().add(
|
||||||
|
CurtainControl(
|
||||||
|
deviceId: deviceId,
|
||||||
|
code: 'control',
|
||||||
|
value: value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
const SizedBox.shrink(),
|
const SizedBox.shrink(),
|
||||||
],
|
],
|
||||||
|
@ -4,6 +4,7 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/device_rep
|
|||||||
import 'package:syncrow_web/pages/device_managment/shared/table/table_cell_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/table/table_cell_widget.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/table/table_header.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/table/table_header.dart';
|
||||||
|
|
||||||
|
// ignore: must_be_immutable
|
||||||
class ReportsTable extends StatelessWidget {
|
class ReportsTable extends StatelessWidget {
|
||||||
final DeviceReport report;
|
final DeviceReport report;
|
||||||
final String? thirdColumnTitle;
|
final String? thirdColumnTitle;
|
||||||
|
Reference in New Issue
Block a user