Fix bluetooth calls from automations in esphome (#80683)

This commit is contained in:
J. Nick Koston 2022-10-20 13:35:38 -05:00 committed by GitHub
parent 92eaa539b6
commit 5589edd814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -284,6 +284,7 @@ class HaBleakClientWrapper(BleakClient):
async def connect(self, **kwargs: Any) -> bool:
"""Connect to the specified GATT server."""
if not self._backend:
assert MANAGER is not None
wrapped_backend = (
self._async_get_backend() or self._async_get_fallback_backend()
)
@ -292,6 +293,7 @@ class HaBleakClientWrapper(BleakClient):
or wrapped_backend.device,
disconnected_callback=self.__disconnected_callback,
timeout=self.__timeout,
hass=MANAGER.hass,
)
return await super().connect(**kwargs)

View File

@ -15,7 +15,7 @@ from bleak.backends.device import BLEDevice
from bleak.backends.service import BleakGATTServiceCollection
from bleak.exc import BleakError
from homeassistant.core import CALLBACK_TYPE, async_get_hass
from homeassistant.core import CALLBACK_TYPE
from ..domain_data import DomainData
from .characteristic import BleakGATTCharacteristicESPHome
@ -83,7 +83,7 @@ class ESPHomeClient(BaseBleakClient):
self._address_as_int = mac_to_int(self._ble_device.address)
assert self._ble_device.details is not None
self._source = self._ble_device.details["source"]
self.domain_data = DomainData.get(async_get_hass())
self.domain_data = DomainData.get(kwargs["hass"])
config_entry = self.domain_data.get_by_unique_id(self._source)
self.entry_data = self.domain_data.get_entry_data(config_entry)
self._client = self.entry_data.client