[bluetooth.generic] Enable BLE notification for linked channels (#10122)
* [bluetooth] Add BluetoothDevice.isNotifying() * [bluetooth] Improve Characteristic properties support * [bluez] Improve Characteristic properties support * [bluetooth] Add BluetoothDevice.canNotify() * [bluez] Also catch DBusExecutionException on read value * [bluetooth.generic] Activate notifications for linked channels where characteristics are able to notify * [bluez] Adjust javadoc * [bluegiga] Add BluetoothDevice.isNotifying() support * [bluegiga] Fix notification enabled check * [bluetooth] move canNotify() to Characteristic * [bluegiga] rename notificationEnabled to notifying * [bluetooth.generic] use handlerToChannels to subscribe to notifications * [bluetooth.generic] implement TODOs of canRead()/canWrite() * [bluetooth.generic] optimize ChannelUID * [bluetooth.generic] use channelUids for link check Signed-off-by: Peter Rosenberg <prosenb.dev@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ import org.openhab.binding.bluetooth.BluetoothCharacteristic;
|
||||
*/
|
||||
public class BlueGigaBluetoothCharacteristic extends BluetoothCharacteristic {
|
||||
|
||||
private boolean notificationEnabled;
|
||||
private boolean notifying;
|
||||
|
||||
public BlueGigaBluetoothCharacteristic(int handle) {
|
||||
super(null, handle);
|
||||
@@ -45,11 +45,11 @@ public class BlueGigaBluetoothCharacteristic extends BluetoothCharacteristic {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public boolean isNotificationEnabled() {
|
||||
return notificationEnabled;
|
||||
public boolean isNotifying() {
|
||||
return notifying;
|
||||
}
|
||||
|
||||
public void setNotificationEnabled(boolean enable) {
|
||||
this.notificationEnabled = enable;
|
||||
public void setNotifying(boolean enable) {
|
||||
this.notifying = enable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
||||
}
|
||||
|
||||
BlueGigaBluetoothCharacteristic ch = (BlueGigaBluetoothCharacteristic) characteristic;
|
||||
if (ch.isNotificationEnabled()) {
|
||||
if (ch.isNotifying()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -241,12 +241,12 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
||||
@Override
|
||||
public boolean disableNotifications(BluetoothCharacteristic characteristic) {
|
||||
if (connection == -1) {
|
||||
logger.debug("Cannot enable notifications, device not connected {}", this);
|
||||
logger.debug("Cannot disable notifications, device not connected {}", this);
|
||||
return false;
|
||||
}
|
||||
|
||||
BlueGigaBluetoothCharacteristic ch = (BlueGigaBluetoothCharacteristic) characteristic;
|
||||
if (ch.isNotificationEnabled()) {
|
||||
if (!ch.isNotifying()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -288,6 +288,12 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNotifying(BluetoothCharacteristic characteristic) {
|
||||
BlueGigaBluetoothCharacteristic ch = (BlueGigaBluetoothCharacteristic) characteristic;
|
||||
return ch.isNotifying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enableNotifications(BluetoothDescriptor descriptor) {
|
||||
// TODO will be implemented in a followup PR
|
||||
@@ -613,7 +619,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
||||
if (!success) {
|
||||
logger.debug("write to descriptor failed");
|
||||
}
|
||||
((BlueGigaBluetoothCharacteristic) procedureCharacteristic).setNotificationEnabled(success);
|
||||
((BlueGigaBluetoothCharacteristic) procedureCharacteristic).setNotifying(success);
|
||||
procedureProgress = BlueGigaProcedure.NONE;
|
||||
procedureCharacteristic = null;
|
||||
break;
|
||||
@@ -622,7 +628,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
||||
if (!success) {
|
||||
logger.debug("write to descriptor failed");
|
||||
}
|
||||
((BlueGigaBluetoothCharacteristic) procedureCharacteristic).setNotificationEnabled(!success);
|
||||
((BlueGigaBluetoothCharacteristic) procedureCharacteristic).setNotifying(!success);
|
||||
procedureProgress = BlueGigaProcedure.NONE;
|
||||
procedureCharacteristic = null;
|
||||
break;
|
||||
@@ -656,7 +662,7 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue
|
||||
}
|
||||
|
||||
for (BlueGigaBluetoothCharacteristic ch : handleToCharacteristic.values()) {
|
||||
ch.setNotificationEnabled(false);
|
||||
ch.setNotifying(false);
|
||||
}
|
||||
|
||||
cancelTimer(procedureTimer);
|
||||
|
||||
Reference in New Issue
Block a user