远程开锁优化

第三方平台
This commit is contained in:
sky_min 2025-12-10 16:27:48 +08:00
parent 07fb7a6542
commit 3224fd342a
3 changed files with 57 additions and 71 deletions

View File

@ -225,7 +225,6 @@ class LockDetailLogic extends BaseGetXController {
StartChartManage().lockPeerId.isNotEmpty) {
sendStarChartOpenLockMessage(reply);
}
break;
case 0x16:
// ...
@ -277,6 +276,7 @@ class LockDetailLogic extends BaseGetXController {
//
// AppLog.log('开锁失败');
openDoorError();
showToast('开锁失败'.tr);
break;
}
}
@ -514,22 +514,39 @@ class LockDetailLogic extends BaseGetXController {
);
BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false);
// FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令');
IoSenderManage.senderOpenLock(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: getTokenList,
needAuthor: 1,
signKey: signKeyDataList,
privateKey: getPrivateKeyList,
);
});
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false);
// FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令');
IoSenderManage.senderOpenLock(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: getTokenList,
needAuthor: 1,
signKey: signKeyDataList,
privateKey: getPrivateKeyList,
);
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
cancelBlueConnetctToastTimer();
BuglyTool.uploadException(
message: '蓝牙连接失败-开锁失败', detail: '蓝牙连接失败,断开连接, 开锁失败--OpenLockCommand:$command', upload: true);
final String getMobile = (await Storage.getMobile())!;
ApmHelper.instance.trackEvent('open_lock', {
'lock_name': state.keyInfos.value.lockName!,
'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
'date': DateTool().getNowDateWithType(1),
'open_lock_result': '断开连接',
});
// if (state.ifCurrentScreen.value == true) {
// showBlueConnetctToast();
// }
resetOpenDoorState();
}
});
}
//
@ -683,14 +700,12 @@ class LockDetailLogic extends BaseGetXController {
var lockId = currentKeyInfo.lockId ?? 0;
var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0;
var lockPeerId = StartChartManage().lockPeerId;
if (lockPeerId.isEmpty) {
final network = currentKeyInfo.network;
if (network != null && network.peerId != null && network.peerId!.isNotEmpty) {
lockPeerId = network.peerId!;
StartChartManage().lockPeerId = lockPeerId;
}
// 使peerId使
final network = currentKeyInfo.network;
var lockPeerId = '';
if (network != null && network.peerId != null && network.peerId!.isNotEmpty) {
lockPeerId = network.peerId!;
StartChartManage().lockPeerId = lockPeerId;
}
if (remoteUnlock == 1) {
@ -762,7 +777,6 @@ class LockDetailLogic extends BaseGetXController {
if (userID == null || userID.isEmpty) {
throw Exception('未找到用户ID');
}
AppLog.log('用户ID: $userID');
//
final OpenLockCommand openLockCommand = OpenLockCommand(
@ -776,11 +790,9 @@ class LockDetailLogic extends BaseGetXController {
signKey: signKeyList,
privateKey: privateKeyList,
);
AppLog.log('构建开锁命令成功');
//
final List<int> messageDetail = openLockCommand.packageData();
final messageDetail = openLockCommand.packageData();
//
StartChartManage().sendRemoteUnLockMessage(
bluetoothDeviceName: bluetoothDeviceName,
@ -894,8 +906,6 @@ class LockDetailLogic extends BaseGetXController {
}
}
//
int _networkQualityScore = 5; // 1-55
///
void sendMonitorMessage() async {
final catEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig ?? [];
@ -909,30 +919,6 @@ class LockDetailLogic extends BaseGetXController {
return;
}
}
//
switch (_networkQualityScore) {
case 1:
state.networkQualityMessage.value = '很差';
break;
case 2:
state.networkQualityMessage.value = '较差';
break;
case 3:
state.networkQualityMessage.value = '一般';
break;
case 4:
state.networkQualityMessage.value = '良好';
break;
case 5:
state.networkQualityMessage.value = '优秀';
break;
default:
state.networkQualityMessage.value = '';
}
//
if (_networkQualityScore < 4) {
showToast('网络质量'.tr + ':${state.networkQualityMessage.value}');
}
if (catEyeConfig.isNotEmpty && catEyeConfig.length > 0 && catEyeConfig[0].catEyeMode != 0) {
if (network == null || network?.peerId == null || network?.peerId == '') {
showToast('设备未配网'.tr);

View File

@ -29,10 +29,10 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
super.onReady();
await getActivateInfo();
//
final savedIndex = await state.getSavedSelectedPlatformIndex();
if (savedIndex != null && savedIndex < state.platFormSet.length) {
state.selectPlatFormIndex.value = savedIndex;
}
// final savedIndex = await state.getSavedSelectedPlatformIndex();
// if (savedIndex != null && savedIndex < state.platFormSet.length) {
// state.selectPlatFormIndex.value = savedIndex;
// }
_initReplySubscription();
await getServerDatetime();
showEasyLoading();
@ -215,8 +215,8 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
if (state.selectPlatFormIndex.value == 1 || state.selectPlatFormIndex.value == 0) {
if (state.registerKey.isNotEmpty) {
//
state.saveSelectedPlatformIndex(state.selectPlatFormIndex.value);
_requestAuthorizationCode();
// state.saveSelectedPlatformIndex(state.selectPlatFormIndex.value);
// _requestAuthorizationCode();
}
} else {
showToast('目前只支持切换至涂鸦智能、锁通通协议'.tr);

View File

@ -35,14 +35,14 @@ class ThirdPartyPlatformState {
int serverTime = 0; // UTC+0
//
static const String _SELECTED_PLATFORM_INDEX_KEY = 'selected_platform_index';
Future<void> saveSelectedPlatformIndex(int index) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setInt(_SELECTED_PLATFORM_INDEX_KEY, index);
}
//
Future<int?> getSavedSelectedPlatformIndex() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getInt(_SELECTED_PLATFORM_INDEX_KEY);
}
// static const String _SELECTED_PLATFORM_INDEX_KEY = 'selected_platform_index';
// Future<void> saveSelectedPlatformIndex(int index) async {
// final prefs = await SharedPreferences.getInstance();
// await prefs.setInt(_SELECTED_PLATFORM_INDEX_KEY, index);
// }
// //
// Future<int?> getSavedSelectedPlatformIndex() async {
// final prefs = await SharedPreferences.getInstance();
// return prefs.getInt(_SELECTED_PLATFORM_INDEX_KEY);
// }
}