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:
@ -18,6 +18,7 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:theme="@style/LaunchTheme"
|
android:theme="@style/LaunchTheme"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
|
@ -553,7 +553,7 @@
|
|||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 20;
|
CURRENT_PROJECT_VERSION = 31;
|
||||||
DEVELOPMENT_TEAM = 48V27SBR8J;
|
DEVELOPMENT_TEAM = 48V27SBR8J;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@ -563,7 +563,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.5;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@ -745,7 +745,7 @@
|
|||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 20;
|
CURRENT_PROJECT_VERSION = 31;
|
||||||
DEVELOPMENT_TEAM = 48V27SBR8J;
|
DEVELOPMENT_TEAM = 48V27SBR8J;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@ -755,7 +755,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.5;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@ -775,7 +775,7 @@
|
|||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 20;
|
CURRENT_PROJECT_VERSION = 31;
|
||||||
DEVELOPMENT_TEAM = 48V27SBR8J;
|
DEVELOPMENT_TEAM = 48V27SBR8J;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@ -785,7 +785,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.5;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@ -862,7 +862,7 @@
|
|||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 20;
|
CURRENT_PROJECT_VERSION = 31;
|
||||||
DEVELOPMENT_TEAM = 48V27SBR8J;
|
DEVELOPMENT_TEAM = 48V27SBR8J;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@ -872,7 +872,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.5;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@ -965,7 +965,7 @@
|
|||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 20;
|
CURRENT_PROJECT_VERSION = 31;
|
||||||
DEVELOPMENT_TEAM = 48V27SBR8J;
|
DEVELOPMENT_TEAM = 48V27SBR8J;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@ -975,7 +975,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.5;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@ -1063,7 +1063,7 @@
|
|||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 20;
|
CURRENT_PROJECT_VERSION = 31;
|
||||||
DEVELOPMENT_TEAM = 48V27SBR8J;
|
DEVELOPMENT_TEAM = 48V27SBR8J;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@ -1073,7 +1073,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.5;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSPhotoLibraryUsageDescription</key>
|
|
||||||
<string>We need access to your photo library to allow you to select and upload photos.</string>
|
|
||||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
@ -28,6 +26,8 @@
|
|||||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
|
<string>We need access to your photo library to allow you to select and upload photos.</string>
|
||||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
@ -36,10 +36,7 @@
|
|||||||
<string>Main</string>
|
<string>Main</string>
|
||||||
<key>UISupportedInterfaceOrientations</key>
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -31,8 +31,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
List<GroupThreeGangModel> groupThreeGangList = [];
|
List<GroupThreeGangModel> groupThreeGangList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
ThreeGangBloc({required this.threeGangId, required this.switchCode})
|
ThreeGangBloc({required this.threeGangId, required this.switchCode}) : super(InitialState()) {
|
||||||
: super(InitialState()) {
|
|
||||||
on<InitialEvent>(_fetchThreeGangStatus);
|
on<InitialEvent>(_fetchThreeGangStatus);
|
||||||
on<ThreeGangUpdated>(_threeGangUpdated);
|
on<ThreeGangUpdated>(_threeGangUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -58,8 +57,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
on<ToggleCreateScheduleEvent>(toggleCreateSchedule);
|
on<ToggleCreateScheduleEvent>(toggleCreateSchedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchThreeGangStatus(
|
void _fetchThreeGangStatus(InitialEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
InitialEvent event, Emitter<ThreeGangState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
threeGangGroup = event.groupScreen;
|
threeGangGroup = event.groupScreen;
|
||||||
@ -71,8 +69,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '3G');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '3G');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response =
|
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -89,16 +86,13 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
|
|
||||||
if (groupThreeGangList.isNotEmpty) {
|
if (groupThreeGangList.isNotEmpty) {
|
||||||
groupThreeGangList.firstWhere((element) {
|
groupThreeGangList.firstWhere((element) {
|
||||||
if (!element.firstSwitch ||
|
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||||
!element.secondSwitch ||
|
|
||||||
!element.thirdSwitch) {
|
|
||||||
allSwitchesOn = false;
|
allSwitchesOn = false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesOn));
|
||||||
threeGangList: groupThreeGangList, allSwitches: allSwitchesOn));
|
|
||||||
} else {
|
} else {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
@ -117,21 +111,18 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
|
|
||||||
_listenToChanges() {
|
_listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref =
|
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeGangId');
|
||||||
FirebaseDatabase.instance.ref('device-status/$threeGangId');
|
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap =
|
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList
|
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
.add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = ThreeGangModel.fromJson(statusList);
|
deviceStatus = ThreeGangModel.fromJson(statusList);
|
||||||
@ -146,8 +137,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(
|
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
ChangeFirstSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
|
||||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeGangGroup) {
|
if (threeGangGroup) {
|
||||||
@ -156,14 +146,11 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.firstSwitch = !event.value;
|
element.firstSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch ||
|
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||||
!element.secondSwitch ||
|
|
||||||
!element.thirdSwitch) {
|
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||||
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
@ -173,7 +160,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||||
@ -200,14 +187,11 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.secondSwitch = !event.value;
|
element.secondSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch ||
|
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||||
!element.secondSwitch ||
|
|
||||||
!element.thirdSwitch) {
|
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||||
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
@ -216,7 +200,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||||
@ -233,8 +217,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeThirdSwitch(
|
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
ChangeThirdSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
|
||||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeGangGroup) {
|
if (threeGangGroup) {
|
||||||
@ -243,14 +226,11 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.thirdSwitch = !event.value;
|
element.thirdSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch ||
|
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||||
!element.secondSwitch ||
|
|
||||||
!element.thirdSwitch) {
|
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
||||||
threeGangList: groupThreeGangList, allSwitches: allSwitchesValue));
|
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.thirdSwitch = !event.value;
|
deviceStatus.thirdSwitch = !event.value;
|
||||||
emit(UpdateState(threeGangModel: deviceStatus));
|
emit(UpdateState(threeGangModel: deviceStatus));
|
||||||
@ -260,7 +240,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||||
@ -289,21 +269,15 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId,
|
deviceId: threeGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||||
code: 'switch_1',
|
|
||||||
value: deviceStatus.firstSwitch),
|
|
||||||
threeGangId),
|
threeGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId,
|
deviceId: threeGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||||
code: 'switch_2',
|
|
||||||
value: deviceStatus.secondSwitch),
|
|
||||||
threeGangId),
|
threeGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId,
|
deviceId: threeGangId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
||||||
code: 'switch_3',
|
|
||||||
value: deviceStatus.thirdSwitch),
|
|
||||||
threeGangId),
|
threeGangId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -329,21 +303,15 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId,
|
deviceId: threeGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||||
code: 'switch_1',
|
|
||||||
value: deviceStatus.firstSwitch),
|
|
||||||
threeGangId),
|
threeGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId,
|
deviceId: threeGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||||
code: 'switch_2',
|
|
||||||
value: deviceStatus.secondSwitch),
|
|
||||||
threeGangId),
|
threeGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeGangId,
|
deviceId: threeGangId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
||||||
code: 'switch_3',
|
|
||||||
value: deviceStatus.thirdSwitch),
|
|
||||||
threeGangId),
|
threeGangId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -365,11 +333,9 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
groupThreeGangList[i].secondSwitch = true;
|
groupThreeGangList[i].secondSwitch = true;
|
||||||
groupThreeGangList[i].thirdSwitch = true;
|
groupThreeGangList[i].thirdSwitch = true;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: true));
|
||||||
threeGangList: groupThreeGangList, allSwitches: true));
|
|
||||||
|
|
||||||
List<String> allDeviceIds =
|
List<String> allDeviceIds = groupThreeGangList.map((device) => device.deviceId).toList();
|
||||||
groupThreeGangList.map((device) => device.deviceId).toList();
|
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -399,8 +365,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _groupAllOff(
|
void _groupAllOff(GroupAllOffEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
GroupAllOffEvent event, Emitter<ThreeGangState> emit) async {
|
|
||||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < groupThreeGangList.length; i++) {
|
for (int i = 0; i < groupThreeGangList.length; i++) {
|
||||||
@ -408,10 +373,8 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
groupThreeGangList[i].secondSwitch = false;
|
groupThreeGangList[i].secondSwitch = false;
|
||||||
groupThreeGangList[i].thirdSwitch = false;
|
groupThreeGangList[i].thirdSwitch = false;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: false));
|
||||||
threeGangList: groupThreeGangList, allSwitches: false));
|
List<String> allDeviceIds = groupThreeGangList.map((device) => device.deviceId).toList();
|
||||||
List<String> allDeviceIds =
|
|
||||||
groupThreeGangList.map((device) => device.deviceId).toList();
|
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -441,20 +404,17 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(
|
void _changeSliding(ChangeSlidingSegment event, Emitter<ThreeGangState> emit) async {
|
||||||
ChangeSlidingSegment event, Emitter<ThreeGangState> emit) async {
|
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(
|
void _setCounterValue(SetCounterValue event, Emitter<ThreeGangState> emit) async {
|
||||||
SetCounterValue event, Emitter<ThreeGangState> emit) async {
|
|
||||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: threeGangId, code: event.deviceCode, value: seconds),
|
||||||
deviceId: threeGangId, code: event.deviceCode, value: seconds),
|
|
||||||
threeGangId);
|
threeGangId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -481,8 +441,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(
|
void _getCounterValue(GetCounterEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
GetCounterEvent event, Emitter<ThreeGangState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
||||||
@ -592,8 +551,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
deviceId: threeGangId,
|
deviceId: threeGangId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule =
|
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -604,13 +562,12 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
DateTime dateTimeWithoutSeconds =
|
||||||
dateTime.day, dateTime.hour, dateTime.minute);
|
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(
|
Future toggleChange(ToggleScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
ToggleScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -629,8 +586,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(
|
Future deleteSchedule(DeleteScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
||||||
DeleteScheduleEvent event, Emitter<ThreeGangState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -650,15 +606,13 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleSelectedIndex(
|
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<ThreeGangState> emit) {
|
||||||
ToggleSelectedEvent event, Emitter<ThreeGangState> emit) {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(
|
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<ThreeGangState> emit) {
|
||||||
ToggleCreateScheduleEvent event, Emitter<ThreeGangState> emit) {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
|
@ -38,8 +38,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
List<GroupThreeTouchModel> groupThreeTouchList = [];
|
List<GroupThreeTouchModel> groupThreeTouchList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
ThreeTouchBloc({required this.threeTouchId, required this.switchCode})
|
ThreeTouchBloc({required this.threeTouchId, required this.switchCode}) : super(InitialState()) {
|
||||||
: super(InitialState()) {
|
|
||||||
on<InitialEvent>(_fetchThreeTouchStatus);
|
on<InitialEvent>(_fetchThreeTouchStatus);
|
||||||
on<ThreeTouchUpdated>(_threeTouchUpdated);
|
on<ThreeTouchUpdated>(_threeTouchUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -64,8 +63,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
on<ChangeStatusEvent>(_changeStatus);
|
on<ChangeStatusEvent>(_changeStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchThreeTouchStatus(
|
void _fetchThreeTouchStatus(InitialEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
InitialEvent event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
threeTouchGroup = event.groupScreen;
|
threeTouchGroup = event.groupScreen;
|
||||||
@ -77,8 +75,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '3GT');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '3GT');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response =
|
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -95,16 +92,13 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
|
|
||||||
if (groupThreeTouchList.isNotEmpty) {
|
if (groupThreeTouchList.isNotEmpty) {
|
||||||
groupThreeTouchList.firstWhere((element) {
|
groupThreeTouchList.firstWhere((element) {
|
||||||
if (!element.firstSwitch ||
|
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||||
!element.secondSwitch ||
|
|
||||||
!element.thirdSwitch) {
|
|
||||||
allSwitchesOn = false;
|
allSwitchesOn = false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn));
|
||||||
threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn));
|
|
||||||
} else {
|
} else {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
@ -123,21 +117,18 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
|
|
||||||
_listenToChanges() {
|
_listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref =
|
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeTouchId');
|
||||||
FirebaseDatabase.instance.ref('device-status/$threeTouchId');
|
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap =
|
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList
|
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
.add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = ThreeTouchModel.fromJson(statusList);
|
deviceStatus = ThreeTouchModel.fromJson(statusList);
|
||||||
@ -152,8 +143,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(
|
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
ChangeFirstSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -162,15 +152,11 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.firstSwitch = !event.value;
|
element.firstSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch ||
|
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||||
!element.secondSwitch ||
|
|
||||||
!element.thirdSwitch) {
|
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
||||||
threeTouchList: groupThreeTouchList,
|
|
||||||
allSwitches: allSwitchesValue));
|
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -180,7 +166,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
||||||
@ -197,8 +183,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event,
|
void _changeSecondSwitch(
|
||||||
Emitter<ThreeTouchState> emit) async {
|
ChangeSecondSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -207,15 +193,11 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.secondSwitch = !event.value;
|
element.secondSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch ||
|
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||||
!element.secondSwitch ||
|
|
||||||
!element.thirdSwitch) {
|
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
||||||
threeTouchList: groupThreeTouchList,
|
|
||||||
allSwitches: allSwitchesValue));
|
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -224,7 +206,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
||||||
@ -241,8 +223,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeThirdSwitch(
|
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
ChangeThirdSwitchStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
if (threeTouchGroup) {
|
if (threeTouchGroup) {
|
||||||
@ -251,15 +232,11 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
if (element.deviceId == event.deviceId) {
|
if (element.deviceId == event.deviceId) {
|
||||||
element.thirdSwitch = !event.value;
|
element.thirdSwitch = !event.value;
|
||||||
}
|
}
|
||||||
if (!element.firstSwitch ||
|
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||||
!element.secondSwitch ||
|
|
||||||
!element.thirdSwitch) {
|
|
||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue));
|
||||||
threeTouchList: groupThreeTouchList,
|
|
||||||
allSwitches: allSwitchesValue));
|
|
||||||
} else {
|
} else {
|
||||||
deviceStatus.thirdSwitch = !event.value;
|
deviceStatus.thirdSwitch = !event.value;
|
||||||
emit(UpdateState(threeTouchModel: deviceStatus));
|
emit(UpdateState(threeTouchModel: deviceStatus));
|
||||||
@ -269,7 +246,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
deviceId: threeTouchGroup ? event.deviceId : threeTouchId,
|
||||||
@ -298,21 +275,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||||
code: 'switch_1',
|
|
||||||
value: deviceStatus.firstSwitch),
|
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||||
code: 'switch_2',
|
|
||||||
value: deviceStatus.secondSwitch),
|
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
||||||
code: 'switch_3',
|
|
||||||
value: deviceStatus.thirdSwitch),
|
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -338,21 +309,15 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||||
code: 'switch_1',
|
|
||||||
value: deviceStatus.firstSwitch),
|
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||||
code: 'switch_2',
|
|
||||||
value: deviceStatus.secondSwitch),
|
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch),
|
||||||
code: 'switch_3',
|
|
||||||
value: deviceStatus.thirdSwitch),
|
|
||||||
threeTouchId),
|
threeTouchId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -374,10 +339,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
groupThreeTouchList[i].secondSwitch = true;
|
groupThreeTouchList[i].secondSwitch = true;
|
||||||
groupThreeTouchList[i].thirdSwitch = true;
|
groupThreeTouchList[i].thirdSwitch = true;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: true));
|
||||||
threeTouchList: groupThreeTouchList, allSwitches: true));
|
List<String> allDeviceIds = groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||||
List<String> allDeviceIds =
|
|
||||||
groupThreeTouchList.map((device) => device.deviceId).toList();
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -406,8 +369,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _groupAllOff(
|
void _groupAllOff(GroupAllOffEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
GroupAllOffEvent event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
for (int i = 0; i < groupThreeTouchList.length; i++) {
|
||||||
@ -415,10 +377,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
groupThreeTouchList[i].secondSwitch = false;
|
groupThreeTouchList[i].secondSwitch = false;
|
||||||
groupThreeTouchList[i].thirdSwitch = false;
|
groupThreeTouchList[i].thirdSwitch = false;
|
||||||
}
|
}
|
||||||
List<String> allDeviceIds =
|
List<String> allDeviceIds = groupThreeTouchList.map((device) => device.deviceId).toList();
|
||||||
groupThreeTouchList.map((device) => device.deviceId).toList();
|
emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: false));
|
||||||
emit(UpdateGroupState(
|
|
||||||
threeTouchList: groupThreeTouchList, allSwitches: false));
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -447,20 +407,17 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(
|
void _changeSliding(ChangeSlidingSegment event, Emitter<ThreeTouchState> emit) async {
|
||||||
ChangeSlidingSegment event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(
|
void _setCounterValue(SetCounterValue event, Emitter<ThreeTouchState> emit) async {
|
||||||
SetCounterValue event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
emit(LoadingNewSate(threeTouchModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: threeTouchId, code: event.deviceCode, value: seconds),
|
||||||
deviceId: threeTouchId, code: event.deviceCode, value: seconds),
|
|
||||||
threeTouchId);
|
threeTouchId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -487,8 +444,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(
|
void _getCounterValue(GetCounterEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
GetCounterEvent event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
var response = await DevicesAPI.getDeviceStatus(threeTouchId);
|
||||||
@ -598,8 +554,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
deviceId: threeTouchId,
|
deviceId: threeTouchId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule =
|
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -610,13 +565,12 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
DateTime dateTimeWithoutSeconds =
|
||||||
dateTime.day, dateTime.hour, dateTime.minute);
|
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(
|
Future toggleChange(ToggleScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
ToggleScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -635,8 +589,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(
|
Future deleteSchedule(DeleteScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
DeleteScheduleEvent event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -656,15 +609,13 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleSelectedIndex(
|
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<ThreeTouchState> emit) {
|
||||||
ToggleSelectedEvent event, Emitter<ThreeTouchState> emit) {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(
|
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<ThreeTouchState> emit) {
|
||||||
ToggleCreateScheduleEvent event, Emitter<ThreeTouchState> emit) {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -682,8 +633,7 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
String statusSelected = '';
|
String statusSelected = '';
|
||||||
String optionSelected = '';
|
String optionSelected = '';
|
||||||
|
|
||||||
Future<void> _changeStatus(
|
Future<void> _changeStatus(ChangeStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
||||||
ChangeStatusEvent event, Emitter<ThreeTouchState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final Map<String, Map<String, String>> controlMap = {
|
final Map<String, Map<String, String>> controlMap = {
|
||||||
@ -717,15 +667,11 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
|||||||
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||||
if (selectedControl != null) {
|
if (selectedControl != null) {
|
||||||
await DevicesAPI.controlDevice(
|
await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: threeTouchId, code: optionSelected, value: selectedControl),
|
||||||
deviceId: threeTouchId,
|
|
||||||
code: optionSelected,
|
|
||||||
value: selectedControl),
|
|
||||||
threeTouchId,
|
threeTouchId,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
emit(const FailedState(
|
emit(const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
||||||
error: 'Invalid statusSelected or optionSelected'));
|
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
|
@ -35,8 +35,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
bool createSchedule = false;
|
bool createSchedule = false;
|
||||||
List<ScheduleModel> listSchedule = [];
|
List<ScheduleModel> listSchedule = [];
|
||||||
|
|
||||||
TwoGangBloc({required this.twoGangId, required this.switchCode})
|
TwoGangBloc({required this.twoGangId, required this.switchCode}) : super(InitialState()) {
|
||||||
: super(InitialState()) {
|
|
||||||
on<InitialEvent>(_fetchTwoGangStatus);
|
on<InitialEvent>(_fetchTwoGangStatus);
|
||||||
on<TwoGangUpdated>(_twoGangUpdated);
|
on<TwoGangUpdated>(_twoGangUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -66,15 +65,13 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
int selectedTabIndex = 0;
|
int selectedTabIndex = 0;
|
||||||
|
|
||||||
void toggleSelectedIndex(
|
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<TwoGangState> emit) {
|
||||||
ToggleSelectedEvent event, Emitter<TwoGangState> emit) {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(
|
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<TwoGangState> emit) {
|
||||||
ToggleCreateScheduleEvent event, Emitter<TwoGangState> emit) {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -82,8 +79,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
emit(UpdateCreateScheduleState(createSchedule));
|
emit(UpdateCreateScheduleState(createSchedule));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchTwoGangStatus(
|
void _fetchTwoGangStatus(InitialEvent event, Emitter<TwoGangState> emit) async {
|
||||||
InitialEvent event, Emitter<TwoGangState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(twoGangId);
|
var response = await DevicesAPI.getDeviceStatus(twoGangId);
|
||||||
@ -102,21 +98,18 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
_listenToChanges() {
|
_listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref =
|
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoGangId');
|
||||||
FirebaseDatabase.instance.ref('device-status/$twoGangId');
|
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap =
|
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList
|
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
.add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = TwoGangModel.fromJson(statusList);
|
deviceStatus = TwoGangModel.fromJson(statusList);
|
||||||
@ -131,8 +124,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
emit(UpdateState(twoGangModel: deviceStatus));
|
emit(UpdateState(twoGangModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(
|
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||||
ChangeFirstSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
@ -141,10 +133,9 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: twoGangId, code: 'switch_1', value: !event.value),
|
||||||
deviceId: twoGangId, code: 'switch_1', value: !event.value),
|
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -156,8 +147,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondSwitch(
|
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||||
ChangeSecondSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
@ -165,10 +155,9 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: twoGangId, code: 'switch_2', value: !event.value),
|
||||||
deviceId: twoGangId, code: 'switch_2', value: !event.value),
|
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -191,15 +180,11 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId,
|
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||||
code: 'switch_1',
|
|
||||||
value: deviceStatus.firstSwitch),
|
|
||||||
twoGangId),
|
twoGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId,
|
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||||
code: 'switch_2',
|
|
||||||
value: deviceStatus.secondSwitch),
|
|
||||||
twoGangId),
|
twoGangId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -222,15 +207,11 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId,
|
deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||||
code: 'switch_1',
|
|
||||||
value: deviceStatus.firstSwitch),
|
|
||||||
twoGangId),
|
twoGangId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoGangId,
|
deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||||
code: 'switch_2',
|
|
||||||
value: deviceStatus.secondSwitch),
|
|
||||||
twoGangId),
|
twoGangId),
|
||||||
]);
|
]);
|
||||||
if (response.every((element) => !element['success'])) {
|
if (response.every((element) => !element['success'])) {
|
||||||
@ -251,8 +232,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
groupTwoGangList[i].secondSwitch = true;
|
groupTwoGangList[i].secondSwitch = true;
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true));
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true));
|
||||||
List<String> allDeviceIds =
|
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
groupTwoGangList.map((device) => device.deviceId).toList();
|
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -287,8 +267,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false));
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false));
|
||||||
|
|
||||||
List<String> allDeviceIds =
|
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
groupTwoGangList.map((device) => device.deviceId).toList();
|
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -313,20 +292,17 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(
|
void _changeSliding(ChangeSlidingSegment event, Emitter<TwoGangState> emit) async {
|
||||||
ChangeSlidingSegment event, Emitter<TwoGangState> emit) async {
|
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(
|
void _setCounterValue(SetCounterValue event, Emitter<TwoGangState> emit) async {
|
||||||
SetCounterValue event, Emitter<TwoGangState> emit) async {
|
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: twoGangId, code: event.deviceCode, value: seconds),
|
||||||
deviceId: twoGangId, code: event.deviceCode, value: seconds),
|
|
||||||
twoGangId);
|
twoGangId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -351,8 +327,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(
|
void _getCounterValue(GetCounterEvent event, Emitter<TwoGangState> emit) async {
|
||||||
GetCounterEvent event, Emitter<TwoGangState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
add(GetScheduleEvent());
|
add(GetScheduleEvent());
|
||||||
@ -460,8 +435,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
deviceId: twoGangId,
|
deviceId: twoGangId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule =
|
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -472,13 +446,12 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
DateTime dateTimeWithoutSeconds =
|
||||||
dateTime.day, dateTime.hour, dateTime.minute);
|
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleRepeat(
|
Future toggleRepeat(ToggleScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||||
ToggleScheduleEvent event, Emitter<TwoGangState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -497,8 +470,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(
|
Future deleteSchedule(DeleteScheduleEvent event, Emitter<TwoGangState> emit) async {
|
||||||
DeleteScheduleEvent event, Emitter<TwoGangState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -518,8 +490,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchTwoGangWizardStatus(
|
void _fetchTwoGangWizardStatus(InitialWizardEvent event, Emitter<TwoGangState> emit) async {
|
||||||
InitialWizardEvent event, Emitter<TwoGangState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
devicesList = [];
|
devicesList = [];
|
||||||
@ -529,8 +500,7 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '2G');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '2G');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response =
|
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -553,16 +523,15 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
|
||||||
twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
void _changeFirstWizardSwitch(
|
||||||
Emitter<TwoGangState> emit) async {
|
ChangeFirstWizardSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -575,11 +544,9 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||||
twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
|
||||||
|
|
||||||
List<String> allDeviceIds =
|
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
groupTwoGangList.map((device) => device.deviceId).toList();
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: allDeviceIds,
|
devicesUuid: allDeviceIds,
|
||||||
@ -594,8 +561,8 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event,
|
void _changeSecondWizardSwitch(
|
||||||
Emitter<TwoGangState> emit) async {
|
ChangeSecondWizardSwitchStatusEvent event, Emitter<TwoGangState> emit) async {
|
||||||
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
emit(LoadingNewSate(twoGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -607,11 +574,9 @@ class TwoGangBloc extends Bloc<TwoGangEvent, TwoGangState> {
|
|||||||
allSwitchesValue = false;
|
allSwitchesValue = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
List<String> allDeviceIds =
|
List<String> allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList();
|
||||||
groupTwoGangList.map((device) => device.deviceId).toList();
|
|
||||||
|
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
||||||
twoGangList: groupTwoGangList, allSwitches: allSwitchesValue));
|
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_2',
|
code: 'switch_2',
|
||||||
|
@ -40,8 +40,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
bool createSchedule = false;
|
bool createSchedule = false;
|
||||||
List<ScheduleModel> listSchedule = [];
|
List<ScheduleModel> listSchedule = [];
|
||||||
|
|
||||||
TwoTouchBloc({required this.twoTouchId, required this.switchCode})
|
TwoTouchBloc({required this.twoTouchId, required this.switchCode}) : super(InitialState()) {
|
||||||
: super(InitialState()) {
|
|
||||||
on<InitialEvent>(_fetchTwoTouchStatus);
|
on<InitialEvent>(_fetchTwoTouchStatus);
|
||||||
on<TwoTouchUpdated>(_twoTouchUpdated);
|
on<TwoTouchUpdated>(_twoTouchUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -72,15 +71,13 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
|
|
||||||
int selectedTabIndex = 0;
|
int selectedTabIndex = 0;
|
||||||
|
|
||||||
void toggleSelectedIndex(
|
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<TwoTouchState> emit) {
|
||||||
ToggleSelectedEvent event, Emitter<TwoTouchState> emit) {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCreateSchedule(
|
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<TwoTouchState> emit) {
|
||||||
ToggleCreateScheduleEvent event, Emitter<TwoTouchState> emit) {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -88,8 +85,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
emit(UpdateCreateScheduleState(createSchedule));
|
emit(UpdateCreateScheduleState(createSchedule));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchTwoTouchStatus(
|
void _fetchTwoTouchStatus(InitialEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
InitialEvent event, Emitter<TwoTouchState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(twoTouchId);
|
var response = await DevicesAPI.getDeviceStatus(twoTouchId);
|
||||||
@ -108,21 +104,18 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
|
|
||||||
_listenToChanges() {
|
_listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref =
|
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoTouchId');
|
||||||
FirebaseDatabase.instance.ref('device-status/$twoTouchId');
|
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap =
|
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
event.snapshot.value as Map<dynamic, dynamic>;
|
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList
|
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
.add(StatusModel(code: element['code'], value: element['value']));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = TwoTouchModel.fromJson(statusList);
|
deviceStatus = TwoTouchModel.fromJson(statusList);
|
||||||
@ -137,8 +130,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
emit(UpdateState(twoTouchModel: deviceStatus));
|
emit(UpdateState(twoTouchModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(
|
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
ChangeFirstSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
|
||||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
@ -147,10 +139,9 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: twoTouchId, code: 'switch_1', value: !event.value),
|
||||||
deviceId: twoTouchId, code: 'switch_1', value: !event.value),
|
|
||||||
twoTouchId);
|
twoTouchId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -162,8 +153,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondSwitch(
|
void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
ChangeSecondSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
|
||||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.secondSwitch = !event.value;
|
deviceStatus.secondSwitch = !event.value;
|
||||||
@ -171,10 +161,9 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
}
|
}
|
||||||
_timer = Timer(const Duration(milliseconds: 500), () async {
|
_timer = Timer(const Duration(milliseconds: 100), () async {
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: twoTouchId, code: 'switch_2', value: !event.value),
|
||||||
deviceId: twoTouchId, code: 'switch_2', value: !event.value),
|
|
||||||
twoTouchId);
|
twoTouchId);
|
||||||
|
|
||||||
if (!response['success']) {
|
if (!response['success']) {
|
||||||
@ -197,15 +186,11 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoTouchId,
|
deviceId: twoTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||||
code: 'switch_1',
|
|
||||||
value: deviceStatus.firstSwitch),
|
|
||||||
twoTouchId),
|
twoTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoTouchId,
|
deviceId: twoTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||||
code: 'switch_2',
|
|
||||||
value: deviceStatus.secondSwitch),
|
|
||||||
twoTouchId),
|
twoTouchId),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -228,15 +213,11 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
final response = await Future.wait([
|
final response = await Future.wait([
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoTouchId,
|
deviceId: twoTouchId, code: 'switch_1', value: deviceStatus.firstSwitch),
|
||||||
code: 'switch_1',
|
|
||||||
value: deviceStatus.firstSwitch),
|
|
||||||
twoTouchId),
|
twoTouchId),
|
||||||
DevicesAPI.controlDevice(
|
DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(
|
||||||
deviceId: twoTouchId,
|
deviceId: twoTouchId, code: 'switch_2', value: deviceStatus.secondSwitch),
|
||||||
code: 'switch_2',
|
|
||||||
value: deviceStatus.secondSwitch),
|
|
||||||
twoTouchId),
|
twoTouchId),
|
||||||
]);
|
]);
|
||||||
if (response.every((element) => !element['success'])) {
|
if (response.every((element) => !element['success'])) {
|
||||||
@ -256,10 +237,8 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
groupTwoTouchList[i].firstSwitch = true;
|
groupTwoTouchList[i].firstSwitch = true;
|
||||||
groupTwoTouchList[i].secondSwitch = true;
|
groupTwoTouchList[i].secondSwitch = true;
|
||||||
}
|
}
|
||||||
emit(
|
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: true));
|
||||||
UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: true));
|
List<String> allDeviceIds = groupTwoTouchList.map((device) => device.deviceId).toList();
|
||||||
List<String> allDeviceIds =
|
|
||||||
groupTwoTouchList.map((device) => device.deviceId).toList();
|
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -292,11 +271,9 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
groupTwoTouchList[i].secondSwitch = false;
|
groupTwoTouchList[i].secondSwitch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: false));
|
||||||
twoTouchList: groupTwoTouchList, allSwitches: false));
|
|
||||||
|
|
||||||
List<String> allDeviceIds =
|
List<String> allDeviceIds = groupTwoTouchList.map((device) => device.deviceId).toList();
|
||||||
groupTwoTouchList.map((device) => device.deviceId).toList();
|
|
||||||
|
|
||||||
final response1 = await DevicesAPI.deviceBatchController(
|
final response1 = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -321,20 +298,17 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(
|
void _changeSliding(ChangeSlidingSegment event, Emitter<TwoTouchState> emit) async {
|
||||||
ChangeSlidingSegment event, Emitter<TwoTouchState> emit) async {
|
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(
|
void _setCounterValue(SetCounterValue event, Emitter<TwoTouchState> emit) async {
|
||||||
SetCounterValue event, Emitter<TwoTouchState> emit) async {
|
|
||||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: twoTouchId, code: event.deviceCode, value: seconds),
|
||||||
deviceId: twoTouchId, code: event.deviceCode, value: seconds),
|
|
||||||
twoTouchId);
|
twoTouchId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -359,8 +333,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(
|
void _getCounterValue(GetCounterEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
GetCounterEvent event, Emitter<TwoTouchState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
add(GetScheduleEvent());
|
add(GetScheduleEvent());
|
||||||
@ -468,8 +441,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
deviceId: twoTouchId,
|
deviceId: twoTouchId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule =
|
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -480,13 +452,12 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
DateTime dateTimeWithoutSeconds =
|
||||||
dateTime.day, dateTime.hour, dateTime.minute);
|
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleRepeat(
|
Future toggleRepeat(ToggleScheduleEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
ToggleScheduleEvent event, Emitter<TwoTouchState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -505,8 +476,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(
|
Future deleteSchedule(DeleteScheduleEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
DeleteScheduleEvent event, Emitter<TwoTouchState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -526,8 +496,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchTwoTouchWizardStatus(
|
void _fetchTwoTouchWizardStatus(InitialWizardEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
InitialWizardEvent event, Emitter<TwoTouchState> emit) async {
|
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
devicesList = [];
|
devicesList = [];
|
||||||
@ -537,8 +506,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '2GT');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '2GT');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response =
|
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -561,16 +529,15 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesOn));
|
||||||
twoTouchList: groupTwoTouchList, allSwitches: allSwitchesOn));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
void _changeFirstWizardSwitch(
|
||||||
Emitter<TwoTouchState> emit) async {
|
ChangeFirstWizardSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -583,8 +550,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
||||||
twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
devicesUuid: [event.deviceId],
|
devicesUuid: [event.deviceId],
|
||||||
@ -599,8 +565,8 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event,
|
void _changeSecondWizardSwitch(
|
||||||
Emitter<TwoTouchState> emit) async {
|
ChangeSecondWizardSwitchStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
emit(LoadingNewSate(twoTouchModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -613,8 +579,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
emit(UpdateGroupState(
|
emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
||||||
twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue));
|
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_2',
|
code: 'switch_2',
|
||||||
@ -633,8 +598,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
String statusSelected = '';
|
String statusSelected = '';
|
||||||
String optionSelected = '';
|
String optionSelected = '';
|
||||||
|
|
||||||
Future<void> _changeStatus(
|
Future<void> _changeStatus(ChangeStatusEvent event, Emitter<TwoTouchState> emit) async {
|
||||||
ChangeStatusEvent event, Emitter<TwoTouchState> emit) async {
|
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final Map<String, Map<String, String>> controlMap = {
|
final Map<String, Map<String, String>> controlMap = {
|
||||||
@ -663,14 +627,11 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
|||||||
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||||
if (selectedControl != null) {
|
if (selectedControl != null) {
|
||||||
await DevicesAPI.controlDevice(
|
await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(
|
DeviceControlModel(deviceId: twoTouchId, code: optionSelected, value: selectedControl),
|
||||||
deviceId: twoTouchId,
|
|
||||||
code: optionSelected,
|
|
||||||
value: selectedControl),
|
|
||||||
twoTouchId,
|
twoTouchId,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
emit( const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
emit(const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
|
@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for
|
|||||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
version: 1.0.5+30
|
version: 1.0.5+31
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.0.6 <4.0.0"
|
sdk: ">=3.0.6 <4.0.0"
|
||||||
|
Reference in New Issue
Block a user