mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
fiz wizard issue
This commit is contained in:
@ -29,7 +29,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
bool oneTouchGroup = false;
|
||||
List<DeviceModel> devicesList = [];
|
||||
|
||||
OneTouchBloc({required this.oneTouchId, required this.switchCode}) : super(InitialState()) {
|
||||
OneTouchBloc({required this.oneTouchId, required this.switchCode})
|
||||
: super(InitialState()) {
|
||||
on<InitialEvent>(_fetchOneTouchStatus);
|
||||
on<OneTouchUpdated>(_oneTouchUpdated);
|
||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||
@ -52,7 +53,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
on<ChangeStatusEvent>(_changeStatus);
|
||||
}
|
||||
|
||||
void _fetchOneTouchStatus(InitialEvent event, Emitter<OneTouchState> emit) async {
|
||||
void _fetchOneTouchStatus(
|
||||
InitialEvent event, Emitter<OneTouchState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(oneTouchId);
|
||||
@ -71,18 +73,21 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
|
||||
_listenToChanges() {
|
||||
try {
|
||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$oneTouchId');
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$oneTouchId');
|
||||
Stream<DatabaseEvent> stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) async {
|
||||
if (_timer != null) {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
}
|
||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
List<StatusModel> statusList = [];
|
||||
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
||||
statusList
|
||||
.add(StatusModel(code: element['code'], value: element['value']));
|
||||
});
|
||||
|
||||
deviceStatus = OneTouchModel.fromJson(statusList);
|
||||
@ -97,7 +102,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||
void _changeFirstSwitch(
|
||||
ChangeFirstSwitchStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||
try {
|
||||
deviceStatus.firstSwitch = !event.value;
|
||||
@ -122,17 +128,20 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSliding(ChangeSlidingSegment event, Emitter<OneTouchState> emit) async {
|
||||
void _changeSliding(
|
||||
ChangeSlidingSegment event, Emitter<OneTouchState> emit) async {
|
||||
emit(ChangeSlidingSegmentState(value: event.value));
|
||||
}
|
||||
|
||||
void _setCounterValue(SetCounterValue event, Emitter<OneTouchState> emit) async {
|
||||
void _setCounterValue(
|
||||
SetCounterValue event, Emitter<OneTouchState> emit) async {
|
||||
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||
int seconds = 0;
|
||||
try {
|
||||
seconds = event.duration.inSeconds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: oneTouchId, code: event.deviceCode, value: seconds),
|
||||
DeviceControlModel(
|
||||
deviceId: oneTouchId, code: event.deviceCode, value: seconds),
|
||||
oneTouchId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
@ -155,7 +164,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _getCounterValue(GetCounterEvent event, Emitter<OneTouchState> emit) async {
|
||||
void _getCounterValue(
|
||||
GetCounterEvent event, Emitter<OneTouchState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(oneTouchId);
|
||||
@ -244,7 +254,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
deviceId: oneTouchId,
|
||||
);
|
||||
List<dynamic> jsonData = response;
|
||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||
listSchedule =
|
||||
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||
emit(InitialState());
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
@ -255,12 +266,13 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
|
||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||
if (dateTime == null) return null;
|
||||
DateTime dateTimeWithoutSeconds =
|
||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
||||
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||
dateTime.day, dateTime.hour, dateTime.minute);
|
||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||
}
|
||||
|
||||
Future toggleChange(ToggleScheduleEvent event, Emitter<OneTouchState> emit) async {
|
||||
Future toggleChange(
|
||||
ToggleScheduleEvent event, Emitter<OneTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.changeSchedule(
|
||||
@ -279,7 +291,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<OneTouchState> emit) async {
|
||||
Future deleteSchedule(
|
||||
DeleteScheduleEvent event, Emitter<OneTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.deleteSchedule(
|
||||
@ -299,7 +312,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<OneTouchState> emit) {
|
||||
void toggleCreateSchedule(
|
||||
ToggleCreateScheduleEvent event, Emitter<OneTouchState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
createSchedule = !createSchedule;
|
||||
selectedDays.clear();
|
||||
@ -328,7 +342,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
|
||||
int selectedTabIndex = 0;
|
||||
|
||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<OneTouchState> emit) {
|
||||
void toggleSelectedIndex(
|
||||
ToggleSelectedEvent event, Emitter<OneTouchState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
selectedTabIndex = event.index;
|
||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||
@ -337,7 +352,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
List<GroupOneTouchModel> groupOneTouchList = [];
|
||||
bool allSwitchesOn = true;
|
||||
|
||||
void _fetchOneTouchWizardStatus(InitialWizardEvent event, Emitter<OneTouchState> emit) async {
|
||||
void _fetchOneTouchWizardStatus(
|
||||
InitialWizardEvent event, Emitter<OneTouchState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
devicesList = [];
|
||||
@ -347,7 +363,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '1GT');
|
||||
|
||||
for (int i = 0; i < devicesList.length; i++) {
|
||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
var response =
|
||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
@ -368,15 +385,16 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
emit(UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: allSwitchesOn));
|
||||
emit(UpdateGroupState(
|
||||
oneTouchList: groupOneTouchList, allSwitches: allSwitchesOn));
|
||||
} catch (e) {
|
||||
emit(FailedState(error: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _changeFirstWizardSwitch(
|
||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||
Emitter<OneTouchState> emit) async {
|
||||
emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||
try {
|
||||
bool allSwitchesValue = true;
|
||||
@ -394,8 +412,9 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
value: !event.value,
|
||||
);
|
||||
|
||||
emit(UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: allSwitchesValue));
|
||||
if (!response['success']) {
|
||||
emit(UpdateGroupState(
|
||||
oneTouchList: groupOneTouchList, allSwitches: allSwitchesValue));
|
||||
if (response['success']) {
|
||||
add(InitialEvent(groupScreen: oneTouchGroup));
|
||||
}
|
||||
} catch (_) {
|
||||
@ -412,10 +431,12 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
}
|
||||
|
||||
// Emit the state with updated values
|
||||
emit(UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: true));
|
||||
emit(
|
||||
UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: true));
|
||||
|
||||
// Get a list of all device IDs
|
||||
List<String> allDeviceIds = groupOneTouchList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds =
|
||||
groupOneTouchList.map((device) => device.deviceId).toList();
|
||||
|
||||
// First call for switch_1
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
@ -423,20 +444,12 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true, // true (on) or false (off) depending on the event value
|
||||
);
|
||||
|
||||
// Second call for switch_2
|
||||
final response2 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2', // Controls second switch for all devices
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true, // true (on) or false (off) depending on the event value
|
||||
);
|
||||
|
||||
// Check if either response is unsuccessful, then reset to initial state
|
||||
if (!response1['success'] || !response2['success']) {
|
||||
if (response1['failedResults'].toString() != '[]') {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
} catch (_) {
|
||||
emit(FailedState(error: _.toString()));
|
||||
// In case of an error, delay and reset the screen to initial state
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
@ -452,31 +465,27 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
}
|
||||
|
||||
// Emit the state with updated values
|
||||
emit(UpdateGroupState(oneTouchList: groupOneTouchList, allSwitches: false));
|
||||
emit(UpdateGroupState(
|
||||
oneTouchList: groupOneTouchList, allSwitches: false));
|
||||
|
||||
// Get a list of all device IDs
|
||||
List<String> allDeviceIds = groupOneTouchList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds =
|
||||
groupOneTouchList.map((device) => device.deviceId).toList();
|
||||
|
||||
// First call for switch_1
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1', // Controls first switch for all devices
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true, // true (on) or false (off) depending on the event value
|
||||
value: false, // true (on) or false (off) depending on the event value
|
||||
);
|
||||
|
||||
// Second call for switch_2
|
||||
final response2 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2', // Controls second switch for all devices
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true, // true (on) or false (off) depending on the event value
|
||||
);
|
||||
// Check if either response is unsuccessful, then reset to initial state
|
||||
if (!response1['success'] || !response2['success']) {
|
||||
if (response1['failedResults'].toString() != '[]') {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
} catch (_) {
|
||||
// In case of an error, delay and reset the screen to initial state
|
||||
emit(FailedState(error: _.toString()));
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
@ -485,7 +494,8 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
String statusSelected = '';
|
||||
String optionSelected = '';
|
||||
|
||||
Future<void> _changeStatus(ChangeStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||
Future<void> _changeStatus(
|
||||
ChangeStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
|
||||
@ -510,7 +520,10 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||
if (selectedControl != null) {
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: oneTouchId, code: optionSelected, value: selectedControl),
|
||||
DeviceControlModel(
|
||||
deviceId: oneTouchId,
|
||||
code: optionSelected,
|
||||
value: selectedControl),
|
||||
oneTouchId,
|
||||
);
|
||||
} else {
|
||||
|
@ -107,7 +107,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
deviceStatus = ThreeGangModel.fromJson(statusModelList);
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
_listenToChanges();
|
||||
// _listenToChanges();
|
||||
}
|
||||
} catch (e) {
|
||||
emit(FailedState(error: e.toString()));
|
||||
@ -368,33 +368,30 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
emit(UpdateGroupState(
|
||||
threeGangList: groupThreeGangList, allSwitches: true));
|
||||
|
||||
for (int i = 0; i < groupThreeGangList.length; i++) {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId,
|
||||
code: 'switch_1',
|
||||
value: true),
|
||||
groupThreeGangList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId,
|
||||
code: 'switch_2',
|
||||
value: true),
|
||||
groupThreeGangList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId,
|
||||
code: 'switch_3',
|
||||
value: true),
|
||||
groupThreeGangList[i].deviceId),
|
||||
]);
|
||||
List<String> allDeviceIds =
|
||||
groupThreeGangList.map((device) => device.deviceId).toList();
|
||||
|
||||
if (response.every((element) => !element['success'])) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
break;
|
||||
}
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true,
|
||||
);
|
||||
final response2 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true,
|
||||
);
|
||||
final response3 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_3',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true,
|
||||
);
|
||||
|
||||
if (response1['failedResults'].toString() != '[]' ||
|
||||
response2['failedResults'].toString() != '[]' ||
|
||||
response3['failedResults'].toString() != '[]') {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
} catch (_) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
@ -413,34 +410,30 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
emit(UpdateGroupState(
|
||||
threeGangList: groupThreeGangList, allSwitches: false));
|
||||
List<String> allDeviceIds =
|
||||
groupThreeGangList.map((device) => device.deviceId).toList();
|
||||
|
||||
for (int i = 0; i < groupThreeGangList.length; i++) {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId,
|
||||
code: 'switch_1',
|
||||
value: false),
|
||||
groupThreeGangList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId,
|
||||
code: 'switch_2',
|
||||
value: false),
|
||||
groupThreeGangList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId,
|
||||
code: 'switch_3',
|
||||
value: false),
|
||||
groupThreeGangList[i].deviceId),
|
||||
]);
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: false,
|
||||
);
|
||||
final response2 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: false,
|
||||
);
|
||||
final response3 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_3',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: false,
|
||||
);
|
||||
|
||||
if (response.every((element) => !element['success'])) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
break;
|
||||
}
|
||||
if (response1['failedResults'].toString() != '[]' ||
|
||||
response2['failedResults'].toString() != '[]' ||
|
||||
response3['failedResults'].toString() != '[]') {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
} catch (_) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
@ -592,8 +585,6 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
GetScheduleEvent event,
|
||||
Emitter<ThreeGangState> emit,
|
||||
) async {
|
||||
print('getSchedule=${switchCode}');
|
||||
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.getSchedule(
|
||||
|
@ -38,7 +38,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
List<GroupThreeTouchModel> groupThreeTouchList = [];
|
||||
bool allSwitchesOn = true;
|
||||
|
||||
ThreeTouchBloc({required this.threeTouchId, required this.switchCode}) : super(InitialState()) {
|
||||
ThreeTouchBloc({required this.threeTouchId, required this.switchCode})
|
||||
: super(InitialState()) {
|
||||
on<InitialEvent>(_fetchThreeTouchStatus);
|
||||
on<ThreeTouchUpdated>(_threeTouchUpdated);
|
||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||
@ -53,19 +54,18 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
on<OnClose>(_onClose);
|
||||
on<GroupAllOnEvent>(_groupAllOn);
|
||||
on<GroupAllOffEvent>(_groupAllOff);
|
||||
|
||||
on<ToggleDaySelectionEvent>(toggleDaySelection);
|
||||
on<ThreeTouchSave>(saveSchedule);
|
||||
on<GetScheduleEvent>(getSchedule);
|
||||
on<ToggleScheduleEvent>(toggleChange);
|
||||
on<DeleteScheduleEvent>(deleteSchedule);
|
||||
|
||||
on<ToggleSelectedEvent>(toggleSelectedIndex);
|
||||
on<ToggleCreateScheduleEvent>(toggleCreateSchedule);
|
||||
on<ChangeStatusEvent>(_changeStatus);
|
||||
}
|
||||
|
||||
void _fetchThreeTouchStatus(InitialEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
void _fetchThreeTouchStatus(
|
||||
InitialEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
threeTouchGroup = event.groupScreen;
|
||||
@ -77,7 +77,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '3GT');
|
||||
|
||||
for (int i = 0; i < devicesList.length; i++) {
|
||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
var response =
|
||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
@ -94,13 +95,16 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
|
||||
if (groupThreeTouchList.isNotEmpty) {
|
||||
groupThreeTouchList.firstWhere((element) {
|
||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||
if (!element.firstSwitch ||
|
||||
!element.secondSwitch ||
|
||||
!element.thirdSwitch) {
|
||||
allSwitchesOn = false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn));
|
||||
emit(UpdateGroupState(
|
||||
threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn));
|
||||
} else {
|
||||
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
@ -109,7 +113,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
}
|
||||
deviceStatus = ThreeTouchModel.fromJson(statusModelList);
|
||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||
_listenToChanges();
|
||||
// _listenToChanges();
|
||||
}
|
||||
} catch (e) {
|
||||
emit(FailedState(error: e.toString()));
|
||||
@ -119,18 +123,21 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
|
||||
_listenToChanges() {
|
||||
try {
|
||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeTouchId');
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$threeTouchId');
|
||||
Stream<DatabaseEvent> stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) async {
|
||||
if (_timer != null) {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
}
|
||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
List<StatusModel> statusList = [];
|
||||
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
||||
statusList
|
||||
.add(StatusModel(code: element['code'], value: element['value']));
|
||||
});
|
||||
|
||||
deviceStatus = ThreeTouchModel.fromJson(statusList);
|
||||
@ -145,7 +152,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
void _changeFirstSwitch(
|
||||
ChangeFirstSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||
try {
|
||||
if (threeTouchGroup) {
|
||||
@ -154,11 +162,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
if (element.deviceId == event.deviceId) {
|
||||
element.firstSwitch = !event.value;
|
||||
}
|
||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||
if (!element.firstSwitch ||
|
||||
!element.secondSwitch ||
|
||||
!element.thirdSwitch) {
|
||||
allSwitchesValue = false;
|
||||
}
|
||||
});
|
||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(
|
||||
threeTouchList: groupThreeTouchList,
|
||||
allSwitches: allSwitchesValue));
|
||||
} else {
|
||||
deviceStatus.firstSwitch = !event.value;
|
||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||
@ -185,8 +197,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSecondSwitch(
|
||||
ChangeSecondSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event,
|
||||
Emitter<ThreeTouchState> emit) async {
|
||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||
try {
|
||||
if (threeTouchGroup) {
|
||||
@ -195,11 +207,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
if (element.deviceId == event.deviceId) {
|
||||
element.secondSwitch = !event.value;
|
||||
}
|
||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||
if (!element.firstSwitch ||
|
||||
!element.secondSwitch ||
|
||||
!element.thirdSwitch) {
|
||||
allSwitchesValue = false;
|
||||
}
|
||||
});
|
||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(
|
||||
threeTouchList: groupThreeTouchList,
|
||||
allSwitches: allSwitchesValue));
|
||||
} else {
|
||||
deviceStatus.secondSwitch = !event.value;
|
||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||
@ -225,7 +241,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
void _changeThirdSwitch(
|
||||
ChangeThirdSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||
try {
|
||||
if (threeTouchGroup) {
|
||||
@ -234,11 +251,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
if (element.deviceId == event.deviceId) {
|
||||
element.thirdSwitch = !event.value;
|
||||
}
|
||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||
if (!element.firstSwitch ||
|
||||
!element.secondSwitch ||
|
||||
!element.thirdSwitch) {
|
||||
allSwitchesValue = false;
|
||||
}
|
||||
});
|
||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(
|
||||
threeTouchList: groupThreeTouchList,
|
||||
allSwitches: allSwitchesValue));
|
||||
} else {
|
||||
deviceStatus.thirdSwitch = !event.value;
|
||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||
@ -277,15 +298,21 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||
deviceId: threeTouchId,
|
||||
code: 'switch_1',
|
||||
value: deviceStatus.firstSwitch),
|
||||
threeTouchId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||
deviceId: threeTouchId,
|
||||
code: 'switch_2',
|
||||
value: deviceStatus.secondSwitch),
|
||||
threeTouchId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
||||
deviceId: threeTouchId,
|
||||
code: 'switch_3',
|
||||
value: deviceStatus.thirdSwitch),
|
||||
threeTouchId),
|
||||
]);
|
||||
|
||||
@ -311,15 +338,21 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||
deviceId: threeTouchId,
|
||||
code: 'switch_1',
|
||||
value: deviceStatus.firstSwitch),
|
||||
threeTouchId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||
deviceId: threeTouchId,
|
||||
code: 'switch_2',
|
||||
value: deviceStatus.secondSwitch),
|
||||
threeTouchId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
||||
deviceId: threeTouchId,
|
||||
code: 'switch_3',
|
||||
value: deviceStatus.thirdSwitch),
|
||||
threeTouchId),
|
||||
]);
|
||||
|
||||
@ -341,29 +374,31 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
groupThreeTouchList[i].secondSwitch = true;
|
||||
groupThreeTouchList[i].thirdSwitch = true;
|
||||
}
|
||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: true));
|
||||
emit(UpdateGroupState(
|
||||
threeTouchList: groupThreeTouchList, allSwitches: true));
|
||||
List<String> allDeviceIds =
|
||||
groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true,
|
||||
);
|
||||
final response2 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true,
|
||||
);
|
||||
final response3 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_3',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: true,
|
||||
);
|
||||
|
||||
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeTouchList[i].deviceId, code: 'switch_1', value: true),
|
||||
groupThreeTouchList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeTouchList[i].deviceId, code: 'switch_2', value: true),
|
||||
groupThreeTouchList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeTouchList[i].deviceId, code: 'switch_3', value: true),
|
||||
groupThreeTouchList[i].deviceId),
|
||||
]);
|
||||
|
||||
if (response.every((element) => !element['success'])) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
break;
|
||||
}
|
||||
if (response1['failedResults'].toString() != '[]' ||
|
||||
response2['failedResults'].toString() != '[]' ||
|
||||
response3['failedResults'].toString() != '[]') {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
} catch (_) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
@ -371,7 +406,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _groupAllOff(GroupAllOffEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
void _groupAllOff(
|
||||
GroupAllOffEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||
try {
|
||||
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
||||
@ -379,29 +415,31 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
groupThreeTouchList[i].secondSwitch = false;
|
||||
groupThreeTouchList[i].thirdSwitch = false;
|
||||
}
|
||||
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: false));
|
||||
List<String> allDeviceIds =
|
||||
groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||
emit(UpdateGroupState(
|
||||
threeTouchList: groupThreeTouchList, allSwitches: false));
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: false,
|
||||
);
|
||||
final response2 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: false,
|
||||
);
|
||||
final response3 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_3',
|
||||
devicesUuid: allDeviceIds,
|
||||
value: false,
|
||||
);
|
||||
|
||||
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeTouchList[i].deviceId, code: 'switch_1', value: false),
|
||||
groupThreeTouchList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeTouchList[i].deviceId, code: 'switch_2', value: false),
|
||||
groupThreeTouchList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeTouchList[i].deviceId, code: 'switch_3', value: false),
|
||||
groupThreeTouchList[i].deviceId),
|
||||
]);
|
||||
|
||||
if (response.every((element) => !element['success'])) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
break;
|
||||
}
|
||||
if (response1['failedResults'].toString() != '[]' ||
|
||||
response2['failedResults'].toString() != '[]' ||
|
||||
response3['failedResults'].toString() != '[]') {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
} catch (_) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
@ -409,17 +447,20 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSliding(ChangeSlidingSegment event, Emitter<ThreeTouchState> emit) async {
|
||||
void _changeSliding(
|
||||
ChangeSlidingSegment event, Emitter<ThreeTouchState> emit) async {
|
||||
emit(ChangeSlidingSegmentState(value: event.value));
|
||||
}
|
||||
|
||||
void _setCounterValue(SetCounterValue event, Emitter<ThreeTouchState> emit) async {
|
||||
void _setCounterValue(
|
||||
SetCounterValue event, Emitter<ThreeTouchState> emit) async {
|
||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||
int seconds = 0;
|
||||
try {
|
||||
seconds = event.duration.inSeconds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: threeTouchId, code: event.deviceCode, value: seconds),
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchId, code: event.deviceCode, value: seconds),
|
||||
threeTouchId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
@ -446,7 +487,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _getCounterValue(GetCounterEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
void _getCounterValue(
|
||||
GetCounterEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
||||
@ -556,7 +598,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
deviceId: threeTouchId,
|
||||
);
|
||||
List<dynamic> jsonData = response;
|
||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||
listSchedule =
|
||||
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||
emit(InitialState());
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
@ -567,12 +610,13 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
|
||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||
if (dateTime == null) return null;
|
||||
DateTime dateTimeWithoutSeconds =
|
||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
||||
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||
dateTime.day, dateTime.hour, dateTime.minute);
|
||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||
}
|
||||
|
||||
Future toggleChange(ToggleScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
Future toggleChange(
|
||||
ToggleScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.changeSchedule(
|
||||
@ -591,7 +635,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
Future deleteSchedule(
|
||||
DeleteScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.deleteSchedule(
|
||||
@ -611,13 +656,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<ThreeTouchState> emit) {
|
||||
void toggleSelectedIndex(
|
||||
ToggleSelectedEvent event, Emitter<ThreeTouchState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
selectedTabIndex = event.index;
|
||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||
}
|
||||
|
||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<ThreeTouchState> emit) {
|
||||
void toggleCreateSchedule(
|
||||
ToggleCreateScheduleEvent event, Emitter<ThreeTouchState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
createSchedule = !createSchedule;
|
||||
selectedDays.clear();
|
||||
@ -635,7 +682,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
String statusSelected = '';
|
||||
String optionSelected = '';
|
||||
|
||||
Future<void> _changeStatus(ChangeStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
Future<void> _changeStatus(
|
||||
ChangeStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final Map<String, Map<String, String>> controlMap = {
|
||||
@ -669,7 +717,10 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||
if (selectedControl != null) {
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: threeTouchId, code: optionSelected, value: selectedControl),
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchId,
|
||||
code: optionSelected,
|
||||
value: selectedControl),
|
||||
threeTouchId,
|
||||
);
|
||||
} else {
|
||||
|
@ -3,7 +3,6 @@ import 'package:dio/dio.dart';
|
||||
import 'package:firebase_database/firebase_database.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/bloc/two_touch_bloc/two_touch_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/two_touch_bloc/two_touch_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
@ -30,14 +29,14 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
relay_status_2: status.off,
|
||||
);
|
||||
Timer? _timer;
|
||||
|
||||
|
||||
bool twoTouchGroup = false;
|
||||
List<DeviceModel> devicesList = [];
|
||||
List<GroupTwoTouchModel> groupTwoTouchList = [];
|
||||
bool allSwitchesOn = true;
|
||||
bool toggleSchedule = true;
|
||||
List<String> selectedDays = [];
|
||||
|
||||
|
||||
bool createSchedule = false;
|
||||
List<ScheduleModel> listSchedule = [];
|
||||
|
||||
@ -586,12 +585,9 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
|
||||
emit(UpdateGroupState(
|
||||
twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
||||
|
||||
List<String> allDeviceIds =
|
||||
groupTwoTouchList.map((device) => device.deviceId).toList();
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
devicesUuid: allDeviceIds,
|
||||
devicesUuid: [event.deviceId],
|
||||
value: !event.value,
|
||||
);
|
||||
|
||||
@ -616,15 +612,13 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
allSwitchesValue = false;
|
||||
}
|
||||
});
|
||||
List<String> allDeviceIds =
|
||||
groupTwoTouchList.map((device) => device.deviceId).toList();
|
||||
|
||||
emit(UpdateGroupState(
|
||||
twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
||||
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2',
|
||||
devicesUuid: allDeviceIds,
|
||||
devicesUuid: [event.deviceId],
|
||||
value: !event.value,
|
||||
);
|
||||
|
||||
|
@ -385,11 +385,13 @@ class DevicesAPI {
|
||||
String? code,
|
||||
bool? value,
|
||||
}) async {
|
||||
print({"devicesUuid": devicesUuid, "code": code, "value": value});
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.controlBatch,
|
||||
body: {"devicesUuid": devicesUuid, "code": code, "value": value},
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
print('json===$json');
|
||||
return json;
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user