Skip to content

Commit

Permalink
Send back BLE address type when connecting via esphome proxies (home-…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 29, 2022
1 parent 1748a19 commit 46b1836
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion homeassistant/components/bluetooth/base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async def async_diagnostics(self) -> dict[str, Any]:
"address": device_adv[0].address,
"rssi": device_adv[0].rssi,
"advertisement_data": device_adv[1],
"details": device_adv[0].details,
}
for device_adv in self.discovered_devices_and_advertisement_data.values()
],
Expand Down Expand Up @@ -162,6 +163,7 @@ def _async_on_advertisement(
service_data: dict[str, bytes],
manufacturer_data: dict[int, bytes],
tx_power: int | None,
details: dict[Any, Any],
) -> None:
"""Call the registered callback."""
now = MONOTONIC_TIME()
Expand Down Expand Up @@ -201,7 +203,7 @@ def _async_on_advertisement(
device = BLEDevice( # type: ignore[no-untyped-call]
address=address,
name=local_name,
details=self._details,
details=self._details | details,
rssi=rssi, # deprecated, will be removed in newer bleak
)
self._discovered_device_advertisement_datas[address] = (
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/esphome/bluetooth/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def __init__(
device_info = self.entry_data.device_info
assert device_info is not None
self._connection_version = device_info.bluetooth_proxy_version
self._address_type = address_or_ble_device.details["address_type"]

def __str__(self) -> str:
"""Return the string representation of the client."""
Expand Down Expand Up @@ -292,6 +293,7 @@ def _on_bluetooth_connection_state(
timeout=timeout,
has_cache=has_cache,
version=self._connection_version,
address_type=self._address_type,
)
)
except Exception: # pylint: disable=broad-except
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/esphome/bluetooth/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def async_on_advertisement(self, adv: BluetoothLEAdvertisement) -> None:
adv.service_data,
adv.manufacturer_data,
None,
{"address_type": adv.address_type},
)

async def async_diagnostics(self) -> dict[str, Any]:
Expand All @@ -39,6 +40,7 @@ async def async_diagnostics(self) -> dict[str, Any]:
"address": device_adv[0].address,
"rssi": device_adv[0].rssi,
"advertisement_data": device_adv[1],
"details": device_adv[0].details,
}
for device_adv in self.discovered_devices_and_advertisement_data.values()
],
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/esphome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "ESPHome",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/esphome",
"requirements": ["aioesphomeapi==12.1.0"],
"requirements": ["aioesphomeapi==12.2.0"],
"zeroconf": ["_esphomelib._tcp.local."],
"dhcp": [{ "registered_devices": true }],
"codeowners": ["@OttoWinter", "@jesserockz"],
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/shelly/bluetooth/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ def async_on_event(self, event: dict[str, Any]) -> None:
parsed.service_data,
parsed.manufacturer_data,
parsed.tx_power,
{},
)
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ aioecowitt==2022.09.3
aioemonitor==1.0.5

# homeassistant.components.esphome
aioesphomeapi==12.1.0
aioesphomeapi==12.2.0

# homeassistant.components.flo
aioflo==2021.11.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ aioecowitt==2022.09.3
aioemonitor==1.0.5

# homeassistant.components.esphome
aioesphomeapi==12.1.0
aioesphomeapi==12.2.0

# homeassistant.components.flo
aioflo==2021.11.0
Expand Down
4 changes: 4 additions & 0 deletions tests/components/bluetooth/test_base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def inject_advertisement(
advertisement_data.service_data,
advertisement_data.manufacturer_data,
advertisement_data.tx_power,
{"scanner_specific_data": "test"},
)

new_info_callback = manager.scanner_adv_received
Expand Down Expand Up @@ -134,6 +135,7 @@ def inject_advertisement(
advertisement_data.service_data,
advertisement_data.manufacturer_data,
advertisement_data.tx_power,
{"scanner_specific_data": "test"},
)

new_info_callback = manager.scanner_adv_received
Expand Down Expand Up @@ -204,6 +206,7 @@ def inject_advertisement(
advertisement_data.service_data,
advertisement_data.manufacturer_data,
advertisement_data.tx_power,
{"scanner_specific_data": "test"},
)

new_info_callback = manager.scanner_adv_received
Expand Down Expand Up @@ -297,6 +300,7 @@ def inject_advertisement(
advertisement_data.service_data,
advertisement_data.manufacturer_data,
advertisement_data.tx_power,
{"scanner_specific_data": "test"},
)

new_info_callback = manager.scanner_adv_received
Expand Down
4 changes: 4 additions & 0 deletions tests/components/bluetooth/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ async def test_diagnostics(
],
"name": "x",
"rssi": -60,
"details": None,
}
],
"last_detection": ANY,
Expand All @@ -179,6 +180,7 @@ async def test_diagnostics(
],
"name": "x",
"rssi": -60,
"details": None,
}
],
"last_detection": ANY,
Expand All @@ -203,6 +205,7 @@ async def test_diagnostics(
],
"name": "x",
"rssi": -60,
"details": None,
}
],
"last_detection": ANY,
Expand Down Expand Up @@ -366,6 +369,7 @@ async def test_diagnostics_macos(
],
"name": "x",
"rssi": -60,
"details": None,
}
],
"last_detection": ANY,
Expand Down

0 comments on commit 46b1836

Please sign in to comment.