Hide unsupported devices in Airthings BLE config flow (#107648)
parent
4229c35fcd
commit
effd5b8ddd
|
@ -23,6 +23,13 @@ from .const import DOMAIN, MFCT_ID
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SERVICE_UUIDS = [
|
||||
"b42e1f6e-ade7-11e4-89d3-123b93f75cba",
|
||||
"b42e4a8e-ade7-11e4-89d3-123b93f75cba",
|
||||
"b42e1c08-ade7-11e4-89d3-123b93f75cba",
|
||||
"b42e3882-ade7-11e4-89d3-123b93f75cba",
|
||||
]
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Discovery:
|
||||
|
@ -147,6 +154,9 @@ class AirthingsConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
if MFCT_ID not in discovery_info.manufacturer_data:
|
||||
continue
|
||||
|
||||
if not any(uuid in SERVICE_UUIDS for uuid in discovery_info.service_uuids):
|
||||
continue
|
||||
|
||||
try:
|
||||
device = await self._get_device_data(discovery_info)
|
||||
except AirthingsDeviceUpdateError:
|
||||
|
|
|
@ -93,6 +93,50 @@ WAVE_SERVICE_INFO = BluetoothServiceInfoBleak(
|
|||
time=0,
|
||||
)
|
||||
|
||||
VIEW_PLUS_SERVICE_INFO = BluetoothServiceInfoBleak(
|
||||
name="cc-cc-cc-cc-cc-cc",
|
||||
address="cc:cc:cc:cc:cc:cc",
|
||||
device=generate_ble_device(
|
||||
address="cc:cc:cc:cc:cc:cc",
|
||||
name="Airthings View Plus",
|
||||
),
|
||||
rssi=-61,
|
||||
manufacturer_data={820: b"\xe4/\xa5\xae\t\x00"},
|
||||
service_data={
|
||||
"b42eb4a6-ade7-11e4-89d3-123b93f75cba": bytearray(
|
||||
b"\x01\x02\x03\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0A"
|
||||
),
|
||||
# Manufacturer
|
||||
"00002a29-0000-1000-8000-00805f9b34fb": bytearray(b"Airthings AS"),
|
||||
# Model
|
||||
"00002a24-0000-1000-8000-00805f9b34fb": bytearray(b"2960"),
|
||||
# Identifier
|
||||
"00002a25-0000-1000-8000-00805f9b34fb": bytearray(b"123456"),
|
||||
# SW Version
|
||||
"00002a26-0000-1000-8000-00805f9b34fb": bytearray(b"A-BLE-1.12.1-master+0"),
|
||||
# HW Version
|
||||
"00002a27-0000-1000-8000-00805f9b34fb": bytearray(b"REV 1,0"),
|
||||
},
|
||||
service_uuids=[
|
||||
"b42eb4a6-ade7-11e4-89d3-123b93f75cba",
|
||||
"b42e90a2-ade7-11e4-89d3-123b93f75cba",
|
||||
"b42e2a68-ade7-11e4-89d3-123b93f75cba",
|
||||
"00002a29-0000-1000-8000-00805f9b34fb",
|
||||
"00002a24-0000-1000-8000-00805f9b34fb",
|
||||
"00002a25-0000-1000-8000-00805f9b34fb",
|
||||
"00002a26-0000-1000-8000-00805f9b34fb",
|
||||
"00002a27-0000-1000-8000-00805f9b34fb",
|
||||
"b42e2d06-ade7-11e4-89d3-123b93f75cba",
|
||||
],
|
||||
source="local",
|
||||
advertisement=generate_advertisement_data(
|
||||
manufacturer_data={820: b"\xe4/\xa5\xae\t\x00"},
|
||||
service_uuids=["b42e90a2-ade7-11e4-89d3-123b93f75cba"],
|
||||
),
|
||||
connectable=True,
|
||||
time=0,
|
||||
)
|
||||
|
||||
UNKNOWN_SERVICE_INFO = BluetoothServiceInfoBleak(
|
||||
name="unknown",
|
||||
address="00:cc:cc:cc:cc:cc",
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.data_entry_flow import FlowResultType
|
|||
|
||||
from . import (
|
||||
UNKNOWN_SERVICE_INFO,
|
||||
VIEW_PLUS_SERVICE_INFO,
|
||||
WAVE_DEVICE_INFO,
|
||||
WAVE_SERVICE_INFO,
|
||||
patch_airthings_ble,
|
||||
|
@ -204,3 +205,16 @@ async def test_user_setup_unable_to_connect(hass: HomeAssistant) -> None:
|
|||
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
|
||||
async def test_unsupported_device(hass: HomeAssistant) -> None:
|
||||
"""Test the user initiated form with an unsupported device."""
|
||||
with patch(
|
||||
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
|
||||
return_value=[UNKNOWN_SERVICE_INFO, VIEW_PLUS_SERVICE_INFO],
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "no_devices_found"
|
||||
|
|
Loading…
Reference in New Issue