Skip to content

Commit

Permalink
BLE WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
seime committed Jul 7, 2024
1 parent e06cc77 commit b14920a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public class ESPHomeBluetoothDevice extends BaseBluetoothDevice {

private final ESPHomeBluetoothProxyHandler proxyHandler;

public void setAddressType(int addressType) {
this.addressType = addressType;
}

private int addressType;

public ESPHomeBluetoothDevice(BluetoothAdapter adapter, BluetoothAddress address) {
super(adapter, address);
proxyHandler = (ESPHomeBluetoothProxyHandler) adapter;
Expand Down Expand Up @@ -101,14 +107,14 @@ public boolean connect() {
// notifyListeners(BluetoothEventType.CONNECTION_STATE,
// new BluetoothConnectionStatusNotification(ConnectionState.CONNECTING));
lockToHandler.sendBluetoothCommand(BluetoothDeviceRequest.newBuilder()
.setAddress(BluetoothAddressUtil.convertAddressToLong(address))
.setAddress(BluetoothAddressUtil.convertAddressToLong(address)).setAddressType(addressType)
.setRequestType(BluetoothDeviceRequestType.BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITHOUT_CACHE)
.build());

return true;
}

return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ private synchronized void updateESPHomeDeviceList() {
// Enable registration of BLE advertisements

ESPHomeHandler handler = (ESPHomeHandler) esphomeThing.getHandler();
if (handler != null) {
if (!espHomeHandlers.contains(handler)) {
handler.listenForBLEAdvertisements(this);
espHomeHandlers.add(handler);
}

if (!espHomeHandlers.contains(handler)) {
handler.listenForBLEAdvertisements(this);
espHomeHandlers.add(handler);
}

}
}
}
Expand Down Expand Up @@ -195,7 +198,7 @@ private void handleAdvertisement(BluetoothLEAdvertisementResponse rsp, ESPHomeHa
ESPHomeBluetoothDevice device = getDevice(address);

logger.debug("Received BLE advertisement from device {} via {}", address, handler.getThing().getUID());

device.setAddressType(rsp.getAddressType());
device.setName(rsp.getName());
device.setRssi(rsp.getRssi());

Expand Down

0 comments on commit b14920a

Please sign in to comment.