From 188cdd1bacd7ef2393cf29f6ce8dd0036d3fea20 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 23 Nov 2022 03:07:05 -0600 Subject: [PATCH] Ensure esphome client tasks await cancelation (#82547) --- homeassistant/components/esphome/bluetooth/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/homeassistant/components/esphome/bluetooth/client.py b/homeassistant/components/esphome/bluetooth/client.py index 666700bfc86..a5075da0bf9 100644 --- a/homeassistant/components/esphome/bluetooth/client.py +++ b/homeassistant/components/esphome/bluetooth/client.py @@ -3,6 +3,7 @@ from __future__ import annotations import asyncio from collections.abc import Callable, Coroutine +import contextlib import logging from typing import Any, TypeVar, cast import uuid @@ -66,6 +67,8 @@ def verify_connected(func: _WrapFuncType) -> _WrapFuncType: ) if disconnected_event.is_set(): task.cancel() + with contextlib.suppress(asyncio.CancelledError): + await task raise BleakError( f"{self._source}: {self._ble_device.name} - {self._ble_device.address}: " # pylint: disable=protected-access "Disconnected during operation"