Fix Aranet failure when the Bluetooth proxy is not providing a device name (#115298)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
012509f683
commit
a6b93ea8ac
6 changed files with 40 additions and 14 deletions
|
@ -2,10 +2,10 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from aranet4.client import Aranet4Advertisement, Version as AranetVersion
|
||||
from bluetooth_data_tools import human_readable_name
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.bluetooth import (
|
||||
|
@ -18,11 +18,15 @@ from homeassistant.data_entry_flow import AbortFlow
|
|||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
MIN_VERSION = AranetVersion(1, 2, 0)
|
||||
|
||||
|
||||
def _title(discovery_info: BluetoothServiceInfoBleak) -> str:
|
||||
return discovery_info.device.name or human_readable_name(
|
||||
None, "Aranet", discovery_info.address
|
||||
)
|
||||
|
||||
|
||||
class AranetConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Aranet."""
|
||||
|
||||
|
@ -61,11 +65,8 @@ class AranetConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Confirm discovery."""
|
||||
assert self._discovered_device is not None
|
||||
adv = self._discovered_device
|
||||
assert self._discovery_info is not None
|
||||
discovery_info = self._discovery_info
|
||||
title = adv.readings.name if adv.readings else discovery_info.name
|
||||
title = _title(self._discovery_info)
|
||||
if user_input is not None:
|
||||
return self.async_create_entry(title=title, data={})
|
||||
|
||||
|
@ -101,10 +102,7 @@ class AranetConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
discovery_info.device, discovery_info.advertisement
|
||||
)
|
||||
if adv.manufacturer_data:
|
||||
self._discovered_devices[address] = (
|
||||
adv.readings.name if adv.readings else discovery_info.name,
|
||||
adv,
|
||||
)
|
||||
self._discovered_devices[address] = (_title(discovery_info), adv)
|
||||
|
||||
if not self._discovered_devices:
|
||||
return self.async_abort(reason="no_devices_found")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue