From a95c2c7850462478f7d2cbe1d5b36bb3c2cd7d90 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 17 Jul 2022 16:13:12 -0500 Subject: [PATCH] Avoid throwing on unsupported bleak client filter (#75378) * Avoid throwing on unsupported bleak client filter * Avoid throwing on unsupported bleak client filter --- homeassistant/components/bluetooth/models.py | 5 +++-- tests/components/bluetooth/test_init.py | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/bluetooth/models.py b/homeassistant/components/bluetooth/models.py index 43d4d0cb923..eda94305aa9 100644 --- a/homeassistant/components/bluetooth/models.py +++ b/homeassistant/components/bluetooth/models.py @@ -113,9 +113,10 @@ class HaBleakScannerWrapper(BaseBleakScanner): # type: ignore[misc] """Map the filters.""" mapped_filters = {} if filters := kwargs.get("filters"): - if FILTER_UUIDS not in filters: + if filter_uuids := filters.get(FILTER_UUIDS): + mapped_filters[FILTER_UUIDS] = set(filter_uuids) + else: _LOGGER.warning("Only %s filters are supported", FILTER_UUIDS) - mapped_filters = {k: set(v) for k, v in filters.items()} if service_uuids := kwargs.get("service_uuids"): mapped_filters[FILTER_UUIDS] = set(service_uuids) if mapped_filters == self._mapped_filters: diff --git a/tests/components/bluetooth/test_init.py b/tests/components/bluetooth/test_init.py index 1d348f42f0e..ec737cef593 100644 --- a/tests/components/bluetooth/test_init.py +++ b/tests/components/bluetooth/test_init.py @@ -686,6 +686,9 @@ async def test_wrapped_instance_unsupported_filter( assert models.HA_BLEAK_SCANNER is not None scanner = models.HaBleakScannerWrapper() scanner.set_scanning_filter( - filters={"unsupported": ["cba20d00-224d-11e6-9fb8-0002a5d5c51b"]} + filters={ + "unsupported": ["cba20d00-224d-11e6-9fb8-0002a5d5c51b"], + "DuplicateData": True, + } ) assert "Only UUIDs filters are supported" in caplog.text