Do not fire the esphome ble disconnected callback if we were not connected (#81286)

This commit is contained in:
J. Nick Koston 2022-10-30 22:10:30 -05:00 committed by GitHub
parent 1d94fbb176
commit ccefc510c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -127,13 +127,15 @@ class ESPHomeClient(BaseBleakClient):
def _async_ble_device_disconnected(self) -> None:
"""Handle the BLE device disconnecting from the ESP."""
_LOGGER.debug("%s: BLE device disconnected", self._source)
self._is_connected = False
was_connected = self._is_connected
self.services = BleakGATTServiceCollection() # type: ignore[no-untyped-call]
self._is_connected = False
if self._disconnected_event:
self._disconnected_event.set()
self._disconnected_event = None
self._async_call_bleak_disconnected_callback()
if was_connected:
_LOGGER.debug("%s: BLE device disconnected", self._source)
self._async_call_bleak_disconnected_callback()
self._unsubscribe_connection_state()
def _async_esp_disconnected(self) -> None: