mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
Fixed design issues
This commit is contained in:
@ -31,8 +31,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
List<GroupThreeGangModel> groupThreeGangList = [];
|
||||
bool allSwitchesOn = true;
|
||||
|
||||
ThreeGangBloc({required this.threeGangId, required this.switchCode})
|
||||
: super(InitialState()) {
|
||||
ThreeGangBloc({required this.threeGangId, required this.switchCode}) : super(InitialState()) {
|
||||
on<InitialEvent>(_fetchThreeGangStatus);
|
||||
on<ThreeGangUpdated>(_threeGangUpdated);
|
||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||
@ -58,8 +57,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
on<ToggleCreateScheduleEvent>(toggleCreateSchedule);
|
||||
}
|
||||
|
||||
void _fetchThreeGangStatus(
|
||||
InitialEvent event, Emitter<ThreeGangState> emit) async {
|
||||
void _fetchThreeGangStatus(InitialEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
threeGangGroup = event.groupScreen;
|
||||
@ -71,8 +69,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '3G');
|
||||
|
||||
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));
|
||||
@ -89,16 +86,13 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
|
||||
if (groupThreeGangList.isNotEmpty) {
|
||||
groupThreeGangList.firstWhere((element) {
|
||||
if (!element.firstSwitch ||
|
||||
!element.secondSwitch ||
|
||||
!element.thirdSwitch) {
|
||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||
allSwitchesOn = false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
emit(UpdateGroupState(
|
||||
threeGangList: groupThreeGangList, allSwitches: allSwitchesOn));
|
||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesOn));
|
||||
} else {
|
||||
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
@ -117,21 +111,18 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
|
||||
_listenToChanges() {
|
||||
try {
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$threeGangId');
|
||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeGangId');
|
||||
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 = ThreeGangModel.fromJson(statusList);
|
||||
@ -146,8 +137,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeFirstSwitch(
|
||||
ChangeFirstSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
try {
|
||||
if (threeGangGroup) {
|
||||
@ -156,14 +146,11 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
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(
|
||||
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||
} else {
|
||||
deviceStatus.firstSwitch = !event.value;
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
@ -173,7 +160,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
_timer!.cancel();
|
||||
}
|
||||
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||
@ -200,14 +187,11 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
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(
|
||||
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||
} else {
|
||||
deviceStatus.secondSwitch = !event.value;
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
@ -216,7 +200,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||
@ -233,8 +217,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeThirdSwitch(
|
||||
ChangeThirdSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
try {
|
||||
if (threeGangGroup) {
|
||||
@ -243,14 +226,11 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
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(
|
||||
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||
} else {
|
||||
deviceStatus.thirdSwitch = !event.value;
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
@ -260,7 +240,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
_timer!.cancel();
|
||||
}
|
||||
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||
@ -289,21 +269,15 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangId,
|
||||
code: 'switch_1',
|
||||
value: deviceStatus.firstSwitch),
|
||||
deviceId: threeGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||
threeGangId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangId,
|
||||
code: 'switch_2',
|
||||
value: deviceStatus.secondSwitch),
|
||||
deviceId: threeGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||
threeGangId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangId,
|
||||
code: 'switch_3',
|
||||
value: deviceStatus.thirdSwitch),
|
||||
deviceId: threeGangId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
||||
threeGangId),
|
||||
]);
|
||||
|
||||
@ -329,21 +303,15 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangId,
|
||||
code: 'switch_1',
|
||||
value: deviceStatus.firstSwitch),
|
||||
deviceId: threeGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||
threeGangId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangId,
|
||||
code: 'switch_2',
|
||||
value: deviceStatus.secondSwitch),
|
||||
deviceId: threeGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||
threeGangId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangId,
|
||||
code: 'switch_3',
|
||||
value: deviceStatus.thirdSwitch),
|
||||
deviceId: threeGangId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
||||
threeGangId),
|
||||
]);
|
||||
|
||||
@ -365,11 +333,9 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
groupThreeGangList[i].secondSwitch = true;
|
||||
groupThreeGangList[i].thirdSwitch = true;
|
||||
}
|
||||
emit(UpdateGroupState(
|
||||
threeGangList: groupThreeGangList, allSwitches: true));
|
||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: true));
|
||||
|
||||
List<String> allDeviceIds =
|
||||
groupThreeGangList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds = groupThreeGangList.map((device) => device.deviceId).toList();
|
||||
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
@ -399,8 +365,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _groupAllOff(
|
||||
GroupAllOffEvent event, Emitter<ThreeGangState> emit) async {
|
||||
void _groupAllOff(GroupAllOffEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
try {
|
||||
for (int i = 0; i < groupThreeGangList.length; i++) {
|
||||
@ -408,10 +373,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
groupThreeGangList[i].secondSwitch = false;
|
||||
groupThreeGangList[i].thirdSwitch = false;
|
||||
}
|
||||
emit(UpdateGroupState(
|
||||
threeGangList: groupThreeGangList, allSwitches: false));
|
||||
List<String> allDeviceIds =
|
||||
groupThreeGangList.map((device) => device.deviceId).toList();
|
||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: false));
|
||||
List<String> allDeviceIds = groupThreeGangList.map((device) => device.deviceId).toList();
|
||||
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
@ -441,20 +404,17 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSliding(
|
||||
ChangeSlidingSegment event, Emitter<ThreeGangState> emit) async {
|
||||
void _changeSliding(ChangeSlidingSegment event, Emitter<ThreeGangState> emit) async {
|
||||
emit(ChangeSlidingSegmentState(value: event.value));
|
||||
}
|
||||
|
||||
void _setCounterValue(
|
||||
SetCounterValue event, Emitter<ThreeGangState> emit) async {
|
||||
void _setCounterValue(SetCounterValue event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
int seconds = 0;
|
||||
try {
|
||||
seconds = event.duration.inSeconds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangId, code: event.deviceCode, value: seconds),
|
||||
DeviceControlModel(deviceId: threeGangId, code: event.deviceCode, value: seconds),
|
||||
threeGangId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
@ -481,8 +441,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _getCounterValue(
|
||||
GetCounterEvent event, Emitter<ThreeGangState> emit) async {
|
||||
void _getCounterValue(GetCounterEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
||||
@ -592,8 +551,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
deviceId: threeGangId,
|
||||
);
|
||||
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;
|
||||
@ -604,13 +562,12 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
|
||||
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<ThreeGangState> emit) async {
|
||||
Future toggleChange(ToggleScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.changeSchedule(
|
||||
@ -629,8 +586,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future deleteSchedule(
|
||||
DeleteScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.deleteSchedule(
|
||||
@ -650,15 +606,13 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void toggleSelectedIndex(
|
||||
ToggleSelectedEvent event, Emitter<ThreeGangState> emit) {
|
||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<ThreeGangState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
selectedTabIndex = event.index;
|
||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||
}
|
||||
|
||||
void toggleCreateSchedule(
|
||||
ToggleCreateScheduleEvent event, Emitter<ThreeGangState> emit) {
|
||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<ThreeGangState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
createSchedule = !createSchedule;
|
||||
selectedDays.clear();
|
||||
|
@ -38,8 +38,7 @@ 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);
|
||||
@ -64,8 +63,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
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,8 +75,7 @@ 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));
|
||||
@ -95,16 +92,13 @@ 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 = [];
|
||||
@ -123,21 +117,18 @@ 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);
|
||||
@ -152,8 +143,7 @@ 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) {
|
||||
@ -162,15 +152,11 @@ 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));
|
||||
@ -180,7 +166,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
_timer!.cancel();
|
||||
}
|
||||
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
||||
@ -197,8 +183,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) {
|
||||
@ -207,15 +193,11 @@ 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));
|
||||
@ -224,7 +206,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
||||
@ -241,8 +223,7 @@ 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) {
|
||||
@ -251,15 +232,11 @@ 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));
|
||||
@ -269,7 +246,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
_timer!.cancel();
|
||||
}
|
||||
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
||||
@ -298,21 +275,15 @@ 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),
|
||||
]);
|
||||
|
||||
@ -338,21 +309,15 @@ 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),
|
||||
]);
|
||||
|
||||
@ -374,10 +339,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
groupThreeTouchList[i].secondSwitch = true;
|
||||
groupThreeTouchList[i].thirdSwitch = true;
|
||||
}
|
||||
emit(UpdateGroupState(
|
||||
threeTouchList: groupThreeTouchList, allSwitches: true));
|
||||
List<String> allDeviceIds =
|
||||
groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||
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,
|
||||
@ -406,8 +369,7 @@ 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++) {
|
||||
@ -415,10 +377,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
groupThreeTouchList[i].secondSwitch = false;
|
||||
groupThreeTouchList[i].thirdSwitch = false;
|
||||
}
|
||||
List<String> allDeviceIds =
|
||||
groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||
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,
|
||||
@ -447,20 +407,17 @@ 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) {
|
||||
@ -487,8 +444,7 @@ 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);
|
||||
@ -598,8 +554,7 @@ 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;
|
||||
@ -610,13 +565,12 @@ 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(
|
||||
@ -635,8 +589,7 @@ 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(
|
||||
@ -656,15 +609,13 @@ 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();
|
||||
@ -682,8 +633,7 @@ 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 = {
|
||||
@ -717,15 +667,11 @@ 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 {
|
||||
emit(const FailedState(
|
||||
error: 'Invalid statusSelected or optionSelected'));
|
||||
emit(const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
|
@ -35,8 +35,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
bool createSchedule = false;
|
||||
List<ScheduleModel> listSchedule = [];
|
||||
|
||||
TwoGangBloc({required this.twoGangId, required this.switchCode})
|
||||
: super(InitialState()) {
|
||||
TwoGangBloc({required this.twoGangId, required this.switchCode}) : super(InitialState()) {
|
||||
on<InitialEvent>(_fetchTwoGangStatus);
|
||||
on<TwoGangUpdated>(_twoGangUpdated);
|
||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||
@ -66,15 +65,13 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
|
||||
int selectedTabIndex = 0;
|
||||
|
||||
void toggleSelectedIndex(
|
||||
ToggleSelectedEvent event, Emitter<TwoGangState> emit) {
|
||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<TwoGangState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
selectedTabIndex = event.index;
|
||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||
}
|
||||
|
||||
void toggleCreateSchedule(
|
||||
ToggleCreateScheduleEvent event, Emitter<TwoGangState> emit) {
|
||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<TwoGangState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
createSchedule = !createSchedule;
|
||||
selectedDays.clear();
|
||||
@ -82,8 +79,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
emit(UpdateCreateScheduleState(createSchedule));
|
||||
}
|
||||
|
||||
void _fetchTwoGangStatus(
|
||||
InitialEvent event, Emitter<TwoGangState> emit) async {
|
||||
void _fetchTwoGangStatus(InitialEvent event, Emitter<TwoGangState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(twoGangId);
|
||||
@ -102,21 +98,18 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
|
||||
_listenToChanges() {
|
||||
try {
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$twoGangId');
|
||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoGangId');
|
||||
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 = TwoGangModel.fromJson(statusList);
|
||||
@ -131,8 +124,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
emit(UpdateState(twoGangModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeFirstSwitch(
|
||||
ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||
try {
|
||||
deviceStatus.firstSwitch = !event.value;
|
||||
@ -141,10 +133,9 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
_timer!.cancel();
|
||||
}
|
||||
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoGangId, code: 'switch_1', value: !event.value),
|
||||
DeviceControlModel(deviceId: twoGangId, code: 'switch_1', value: !event.value),
|
||||
twoGangId);
|
||||
|
||||
if (!response['success']) {
|
||||
@ -156,8 +147,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSecondSwitch(
|
||||
ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||
try {
|
||||
deviceStatus.secondSwitch = !event.value;
|
||||
@ -165,10 +155,9 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoGangId, code: 'switch_2', value: !event.value),
|
||||
DeviceControlModel(deviceId: twoGangId, code: 'switch_2', value: !event.value),
|
||||
twoGangId);
|
||||
|
||||
if (!response['success']) {
|
||||
@ -191,15 +180,11 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoGangId,
|
||||
code: 'switch_1',
|
||||
value: deviceStatus.firstSwitch),
|
||||
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||
twoGangId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoGangId,
|
||||
code: 'switch_2',
|
||||
value: deviceStatus.secondSwitch),
|
||||
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||
twoGangId),
|
||||
]);
|
||||
|
||||
@ -222,15 +207,11 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoGangId,
|
||||
code: 'switch_1',
|
||||
value: deviceStatus.firstSwitch),
|
||||
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||
twoGangId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoGangId,
|
||||
code: 'switch_2',
|
||||
value: deviceStatus.secondSwitch),
|
||||
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||
twoGangId),
|
||||
]);
|
||||
if (response.every((element) => !element['success'])) {
|
||||
@ -251,8 +232,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
groupTwoGangList[i].secondSwitch = true;
|
||||
}
|
||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true));
|
||||
List<String> allDeviceIds =
|
||||
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
||||
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
@ -287,8 +267,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
|
||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false));
|
||||
|
||||
List<String> allDeviceIds =
|
||||
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
||||
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
@ -313,20 +292,17 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSliding(
|
||||
ChangeSlidingSegment event, Emitter<TwoGangState> emit) async {
|
||||
void _changeSliding(ChangeSlidingSegment event, Emitter<TwoGangState> emit) async {
|
||||
emit(ChangeSlidingSegmentState(value: event.value));
|
||||
}
|
||||
|
||||
void _setCounterValue(
|
||||
SetCounterValue event, Emitter<TwoGangState> emit) async {
|
||||
void _setCounterValue(SetCounterValue event, Emitter<TwoGangState> emit) async {
|
||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||
int seconds = 0;
|
||||
try {
|
||||
seconds = event.duration.inSeconds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoGangId, code: event.deviceCode, value: seconds),
|
||||
DeviceControlModel(deviceId: twoGangId, code: event.deviceCode, value: seconds),
|
||||
twoGangId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
@ -351,8 +327,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _getCounterValue(
|
||||
GetCounterEvent event, Emitter<TwoGangState> emit) async {
|
||||
void _getCounterValue(GetCounterEvent event, Emitter<TwoGangState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
add(GetScheduleEvent());
|
||||
@ -460,8 +435,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
deviceId: twoGangId,
|
||||
);
|
||||
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;
|
||||
@ -472,13 +446,12 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
|
||||
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 toggleRepeat(
|
||||
ToggleScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||
Future toggleRepeat(ToggleScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.changeSchedule(
|
||||
@ -497,8 +470,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future deleteSchedule(
|
||||
DeleteScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.deleteSchedule(
|
||||
@ -518,8 +490,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchTwoGangWizardStatus(
|
||||
InitialWizardEvent event, Emitter<TwoGangState> emit) async {
|
||||
void _fetchTwoGangWizardStatus(InitialWizardEvent event, Emitter<TwoGangState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
devicesList = [];
|
||||
@ -529,8 +500,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '2G');
|
||||
|
||||
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));
|
||||
@ -553,16 +523,15 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
emit(UpdateGroupState(
|
||||
twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
|
||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
|
||||
} catch (e) {
|
||||
emit(FailedState(error: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||
Emitter<TwoGangState> emit) async {
|
||||
void _changeFirstWizardSwitch(
|
||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||
try {
|
||||
bool allSwitchesValue = true;
|
||||
@ -575,11 +544,9 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
}
|
||||
});
|
||||
|
||||
emit(UpdateGroupState(
|
||||
twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||
|
||||
List<String> allDeviceIds =
|
||||
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
devicesUuid: allDeviceIds,
|
||||
@ -594,8 +561,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event,
|
||||
Emitter<TwoGangState> emit) async {
|
||||
void _changeSecondWizardSwitch(
|
||||
ChangeSecondWizardSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||
try {
|
||||
bool allSwitchesValue = true;
|
||||
@ -607,11 +574,9 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
||||
allSwitchesValue = false;
|
||||
}
|
||||
});
|
||||
List<String> allDeviceIds =
|
||||
groupTwoGangList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
||||
|
||||
emit(UpdateGroupState(
|
||||
twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2',
|
||||
|
@ -40,8 +40,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
bool createSchedule = false;
|
||||
List<ScheduleModel> listSchedule = [];
|
||||
|
||||
TwoTouchBloc({required this.twoTouchId, required this.switchCode})
|
||||
: super(InitialState()) {
|
||||
TwoTouchBloc({required this.twoTouchId, required this.switchCode}) : super(InitialState()) {
|
||||
on<InitialEvent>(_fetchTwoTouchStatus);
|
||||
on<TwoTouchUpdated>(_twoTouchUpdated);
|
||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||
@ -72,15 +71,13 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
|
||||
int selectedTabIndex = 0;
|
||||
|
||||
void toggleSelectedIndex(
|
||||
ToggleSelectedEvent event, Emitter<TwoTouchState> emit) {
|
||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<TwoTouchState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
selectedTabIndex = event.index;
|
||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||
}
|
||||
|
||||
void toggleCreateSchedule(
|
||||
ToggleCreateScheduleEvent event, Emitter<TwoTouchState> emit) {
|
||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<TwoTouchState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
createSchedule = !createSchedule;
|
||||
selectedDays.clear();
|
||||
@ -88,8 +85,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
emit(UpdateCreateScheduleState(createSchedule));
|
||||
}
|
||||
|
||||
void _fetchTwoTouchStatus(
|
||||
InitialEvent event, Emitter<TwoTouchState> emit) async {
|
||||
void _fetchTwoTouchStatus(InitialEvent event, Emitter<TwoTouchState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(twoTouchId);
|
||||
@ -108,21 +104,18 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
|
||||
_listenToChanges() {
|
||||
try {
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$twoTouchId');
|
||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoTouchId');
|
||||
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 = TwoTouchModel.fromJson(statusList);
|
||||
@ -137,8 +130,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
emit(UpdateState(twoTouchModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeFirstSwitch(
|
||||
ChangeFirstSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||
try {
|
||||
deviceStatus.firstSwitch = !event.value;
|
||||
@ -147,10 +139,9 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
_timer!.cancel();
|
||||
}
|
||||
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoTouchId, code: 'switch_1', value: !event.value),
|
||||
DeviceControlModel(deviceId: twoTouchId, code: 'switch_1', value: !event.value),
|
||||
twoTouchId);
|
||||
|
||||
if (!response['success']) {
|
||||
@ -162,8 +153,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSecondSwitch(
|
||||
ChangeSecondSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||
try {
|
||||
deviceStatus.secondSwitch = !event.value;
|
||||
@ -171,10 +161,9 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
||||
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoTouchId, code: 'switch_2', value: !event.value),
|
||||
DeviceControlModel(deviceId: twoTouchId, code: 'switch_2', value: !event.value),
|
||||
twoTouchId);
|
||||
|
||||
if (!response['success']) {
|
||||
@ -197,15 +186,11 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoTouchId,
|
||||
code: 'switch_1',
|
||||
value: deviceStatus.firstSwitch),
|
||||
deviceId: twoTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||
twoTouchId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoTouchId,
|
||||
code: 'switch_2',
|
||||
value: deviceStatus.secondSwitch),
|
||||
deviceId: twoTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||
twoTouchId),
|
||||
]);
|
||||
|
||||
@ -228,15 +213,11 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoTouchId,
|
||||
code: 'switch_1',
|
||||
value: deviceStatus.firstSwitch),
|
||||
deviceId: twoTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||
twoTouchId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoTouchId,
|
||||
code: 'switch_2',
|
||||
value: deviceStatus.secondSwitch),
|
||||
deviceId: twoTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||
twoTouchId),
|
||||
]);
|
||||
if (response.every((element) => !element['success'])) {
|
||||
@ -256,10 +237,8 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
groupTwoTouchList[i].firstSwitch = true;
|
||||
groupTwoTouchList[i].secondSwitch = true;
|
||||
}
|
||||
emit(
|
||||
UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: true));
|
||||
List<String> allDeviceIds =
|
||||
groupTwoTouchList.map((device) => device.deviceId).toList();
|
||||
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: true));
|
||||
List<String> allDeviceIds = groupTwoTouchList.map((device) => device.deviceId).toList();
|
||||
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
@ -292,11 +271,9 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
groupTwoTouchList[i].secondSwitch = false;
|
||||
}
|
||||
|
||||
emit(UpdateGroupState(
|
||||
twoTouchList: groupTwoTouchList, allSwitches: false));
|
||||
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: false));
|
||||
|
||||
List<String> allDeviceIds =
|
||||
groupTwoTouchList.map((device) => device.deviceId).toList();
|
||||
List<String> allDeviceIds = groupTwoTouchList.map((device) => device.deviceId).toList();
|
||||
|
||||
final response1 = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
@ -321,20 +298,17 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSliding(
|
||||
ChangeSlidingSegment event, Emitter<TwoTouchState> emit) async {
|
||||
void _changeSliding(ChangeSlidingSegment event, Emitter<TwoTouchState> emit) async {
|
||||
emit(ChangeSlidingSegmentState(value: event.value));
|
||||
}
|
||||
|
||||
void _setCounterValue(
|
||||
SetCounterValue event, Emitter<TwoTouchState> emit) async {
|
||||
void _setCounterValue(SetCounterValue event, Emitter<TwoTouchState> emit) async {
|
||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||
int seconds = 0;
|
||||
try {
|
||||
seconds = event.duration.inSeconds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoTouchId, code: event.deviceCode, value: seconds),
|
||||
DeviceControlModel(deviceId: twoTouchId, code: event.deviceCode, value: seconds),
|
||||
twoTouchId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
@ -359,8 +333,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _getCounterValue(
|
||||
GetCounterEvent event, Emitter<TwoTouchState> emit) async {
|
||||
void _getCounterValue(GetCounterEvent event, Emitter<TwoTouchState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
add(GetScheduleEvent());
|
||||
@ -468,8 +441,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
deviceId: twoTouchId,
|
||||
);
|
||||
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;
|
||||
@ -480,13 +452,12 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
|
||||
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 toggleRepeat(
|
||||
ToggleScheduleEvent event, Emitter<TwoTouchState> emit) async {
|
||||
Future toggleRepeat(ToggleScheduleEvent event, Emitter<TwoTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.changeSchedule(
|
||||
@ -505,8 +476,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future deleteSchedule(
|
||||
DeleteScheduleEvent event, Emitter<TwoTouchState> emit) async {
|
||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<TwoTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final response = await DevicesAPI.deleteSchedule(
|
||||
@ -526,8 +496,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchTwoTouchWizardStatus(
|
||||
InitialWizardEvent event, Emitter<TwoTouchState> emit) async {
|
||||
void _fetchTwoTouchWizardStatus(InitialWizardEvent event, Emitter<TwoTouchState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
devicesList = [];
|
||||
@ -537,8 +506,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '2GT');
|
||||
|
||||
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));
|
||||
@ -561,16 +529,15 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
emit(UpdateGroupState(
|
||||
twoTouchList: groupTwoTouchList, allSwitches: allSwitchesOn));
|
||||
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesOn));
|
||||
} catch (e) {
|
||||
emit(FailedState(error: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||
Emitter<TwoTouchState> emit) async {
|
||||
void _changeFirstWizardSwitch(
|
||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||
try {
|
||||
bool allSwitchesValue = true;
|
||||
@ -583,8 +550,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
}
|
||||
});
|
||||
|
||||
emit(UpdateGroupState(
|
||||
twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_1',
|
||||
devicesUuid: [event.deviceId],
|
||||
@ -599,8 +565,8 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event,
|
||||
Emitter<TwoTouchState> emit) async {
|
||||
void _changeSecondWizardSwitch(
|
||||
ChangeSecondWizardSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||
try {
|
||||
bool allSwitchesValue = true;
|
||||
@ -613,8 +579,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
}
|
||||
});
|
||||
|
||||
emit(UpdateGroupState(
|
||||
twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
||||
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
||||
|
||||
final response = await DevicesAPI.deviceBatchController(
|
||||
code: 'switch_2',
|
||||
@ -633,8 +598,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
String statusSelected = '';
|
||||
String optionSelected = '';
|
||||
|
||||
Future<void> _changeStatus(
|
||||
ChangeStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||
Future<void> _changeStatus(ChangeStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
final Map<String, Map<String, String>> controlMap = {
|
||||
@ -663,14 +627,11 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||
if (selectedControl != null) {
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: twoTouchId,
|
||||
code: optionSelected,
|
||||
value: selectedControl),
|
||||
DeviceControlModel(deviceId: twoTouchId, code: optionSelected, value: selectedControl),
|
||||
twoTouchId,
|
||||
);
|
||||
} else {
|
||||
emit( const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
||||
emit(const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
|
Reference in New Issue
Block a user