diff --git a/libnymea-app/wifisetup/bluetoothdeviceinfo.cpp b/libnymea-app/wifisetup/bluetoothdeviceinfo.cpp index 850e9f4f..af66b870 100644 --- a/libnymea-app/wifisetup/bluetoothdeviceinfo.cpp +++ b/libnymea-app/wifisetup/bluetoothdeviceinfo.cpp @@ -67,6 +67,11 @@ bool BluetoothDeviceInfo::isLowEnergy() const return m_deviceInfo.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration; } +int BluetoothDeviceInfo::signalStrength() const +{ + return (m_deviceInfo.rssi() + 100) * 2; +} + QBluetoothDeviceInfo BluetoothDeviceInfo::bluetoothDeviceInfo() const { return m_deviceInfo; diff --git a/libnymea-app/wifisetup/bluetoothdeviceinfo.h b/libnymea-app/wifisetup/bluetoothdeviceinfo.h index f72363d2..39b14ace 100644 --- a/libnymea-app/wifisetup/bluetoothdeviceinfo.h +++ b/libnymea-app/wifisetup/bluetoothdeviceinfo.h @@ -41,6 +41,7 @@ class BluetoothDeviceInfo : public QObject Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY deviceChanged) Q_PROPERTY(QString address READ address NOTIFY deviceChanged) + Q_PROPERTY(int signalStrength READ signalStrength NOTIFY deviceChanged) public: BluetoothDeviceInfo(); @@ -50,6 +51,7 @@ public: QString address() const; QString name() const; bool isLowEnergy() const; + int signalStrength() const; QBluetoothDeviceInfo bluetoothDeviceInfo() const; void setBluetoothDeviceInfo(const QBluetoothDeviceInfo &deviceInfo); diff --git a/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp b/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp index 10ae6eda..f23ef63b 100644 --- a/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp +++ b/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp @@ -60,6 +60,8 @@ QVariant BluetoothDeviceInfos::data(const QModelIndex &index, int role) const return deviceInfo->address(); } else if (role == BluetoothDeviceInfoRoleLe) { return deviceInfo->isLowEnergy(); + } else if (role == BluetoothDeviceInfoRoleSignalStrength) { + return deviceInfo->signalStrength(); } return QVariant(); @@ -103,5 +105,6 @@ QHash BluetoothDeviceInfos::roleNames() const roles[BluetoothDeviceInfoRoleName] = "name"; roles[BluetoothDeviceInfoRoleAddress] = "address"; roles[BluetoothDeviceInfoRoleLe] = "lowEnergy"; + roles[BluetoothDeviceInfoRoleSignalStrength] = "signalStrength"; return roles; } diff --git a/libnymea-app/wifisetup/bluetoothdeviceinfos.h b/libnymea-app/wifisetup/bluetoothdeviceinfos.h index 9c8dae37..0271d12f 100644 --- a/libnymea-app/wifisetup/bluetoothdeviceinfos.h +++ b/libnymea-app/wifisetup/bluetoothdeviceinfos.h @@ -44,8 +44,10 @@ public: enum BluetoothDeviceInfoRole { BluetoothDeviceInfoRoleName = Qt::DisplayRole, BluetoothDeviceInfoRoleAddress, - BluetoothDeviceInfoRoleLe + BluetoothDeviceInfoRoleLe, + BluetoothDeviceInfoRoleSignalStrength }; + Q_ENUM(BluetoothDeviceInfoRole) explicit BluetoothDeviceInfos(QObject *parent = nullptr); diff --git a/libnymea-app/wifisetup/bluetoothdiscovery.cpp b/libnymea-app/wifisetup/bluetoothdiscovery.cpp index 1e4703e5..41857bb7 100644 --- a/libnymea-app/wifisetup/bluetoothdiscovery.cpp +++ b/libnymea-app/wifisetup/bluetoothdiscovery.cpp @@ -176,16 +176,19 @@ void BluetoothDiscovery::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo { if (!deviceInfo.isValid() || !deviceInfo.coreConfigurations().testFlag(QBluetoothDeviceInfo::LowEnergyCoreConfiguration) - || deviceInfo.name().isEmpty()) { + || deviceInfo.name().isEmpty() + || deviceInfo.isCached()) { return; } foreach (BluetoothDeviceInfo *di, m_deviceInfos->deviceInfos()) { if (di->address() == deviceInfo.address().toString()) { + di->setBluetoothDeviceInfo(deviceInfo); return; } } + BluetoothDeviceInfo *deviceInformation = new BluetoothDeviceInfo(deviceInfo); // qDebug() << "BluetoothDiscovery: [+]" << deviceInformation->name() << "(" << deviceInformation->address() << ")" << (isLowEnergy ? "LE" : "") << deviceInfo.majorDeviceClass() << deviceInfo.minorDeviceClass() << deviceInfo.serviceClasses(); m_deviceInfos->addBluetoothDeviceInfo(deviceInformation);