mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aranet4.client import Aranet4Advertisement, Version as AranetVersion
|
from aranet4.client import Aranet4Advertisement, Version as AranetVersion
|
||||||
|
from bluetooth_data_tools import human_readable_name
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.bluetooth import (
|
from homeassistant.components.bluetooth import (
|
||||||
@ -18,11 +18,15 @@ from homeassistant.data_entry_flow import AbortFlow
|
|||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
MIN_VERSION = AranetVersion(1, 2, 0)
|
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):
|
class AranetConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for Aranet."""
|
"""Handle a config flow for Aranet."""
|
||||||
|
|
||||||
@ -61,11 +65,8 @@ class AranetConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Confirm discovery."""
|
"""Confirm discovery."""
|
||||||
assert self._discovered_device is not None
|
|
||||||
adv = self._discovered_device
|
|
||||||
assert self._discovery_info is not None
|
assert self._discovery_info is not None
|
||||||
discovery_info = self._discovery_info
|
title = _title(self._discovery_info)
|
||||||
title = adv.readings.name if adv.readings else discovery_info.name
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(title=title, data={})
|
return self.async_create_entry(title=title, data={})
|
||||||
|
|
||||||
@ -101,10 +102,7 @@ class AranetConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
discovery_info.device, discovery_info.advertisement
|
discovery_info.device, discovery_info.advertisement
|
||||||
)
|
)
|
||||||
if adv.manufacturer_data:
|
if adv.manufacturer_data:
|
||||||
self._discovered_devices[address] = (
|
self._discovered_devices[address] = (_title(discovery_info), adv)
|
||||||
adv.readings.name if adv.readings else discovery_info.name,
|
|
||||||
adv,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not self._discovered_devices:
|
if not self._discovered_devices:
|
||||||
return self.async_abort(reason="no_devices_found")
|
return self.async_abort(reason="no_devices_found")
|
||||||
|
@ -19,5 +19,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/aranet",
|
"documentation": "https://www.home-assistant.io/integrations/aranet",
|
||||||
"integration_type": "device",
|
"integration_type": "device",
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"requirements": ["aranet4==2.2.2"]
|
"requirements": ["aranet4==2.3.3"]
|
||||||
}
|
}
|
||||||
|
@ -467,7 +467,7 @@ aprslib==0.7.2
|
|||||||
aqualogic==2.6
|
aqualogic==2.6
|
||||||
|
|
||||||
# homeassistant.components.aranet
|
# homeassistant.components.aranet
|
||||||
aranet4==2.2.2
|
aranet4==2.3.3
|
||||||
|
|
||||||
# homeassistant.components.arcam_fmj
|
# homeassistant.components.arcam_fmj
|
||||||
arcam-fmj==1.4.0
|
arcam-fmj==1.4.0
|
||||||
|
@ -428,7 +428,7 @@ apprise==1.7.4
|
|||||||
aprslib==0.7.2
|
aprslib==0.7.2
|
||||||
|
|
||||||
# homeassistant.components.aranet
|
# homeassistant.components.aranet
|
||||||
aranet4==2.2.2
|
aranet4==2.3.3
|
||||||
|
|
||||||
# homeassistant.components.arcam_fmj
|
# homeassistant.components.arcam_fmj
|
||||||
arcam-fmj==1.4.0
|
arcam-fmj==1.4.0
|
||||||
|
@ -58,6 +58,14 @@ VALID_DATA_SERVICE_INFO = fake_service_info(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
VALID_DATA_SERVICE_INFO_WITH_NO_NAME = fake_service_info(
|
||||||
|
None,
|
||||||
|
"0000fce0-0000-1000-8000-00805f9b34fb",
|
||||||
|
{
|
||||||
|
1794: b'\x21\x00\x02\x01\x00\x00\x00\x01\x8a\x02\xa5\x01\xb1&"Y\x01,\x01\xe8\x00\x88'
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
VALID_ARANET2_DATA_SERVICE_INFO = fake_service_info(
|
VALID_ARANET2_DATA_SERVICE_INFO = fake_service_info(
|
||||||
"Aranet2 12345",
|
"Aranet2 12345",
|
||||||
"0000fce0-0000-1000-8000-00805f9b34fb",
|
"0000fce0-0000-1000-8000-00805f9b34fb",
|
||||||
|
@ -12,6 +12,7 @@ from . import (
|
|||||||
NOT_ARANET4_SERVICE_INFO,
|
NOT_ARANET4_SERVICE_INFO,
|
||||||
OLD_FIRMWARE_SERVICE_INFO,
|
OLD_FIRMWARE_SERVICE_INFO,
|
||||||
VALID_DATA_SERVICE_INFO,
|
VALID_DATA_SERVICE_INFO,
|
||||||
|
VALID_DATA_SERVICE_INFO_WITH_NO_NAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
@ -36,6 +37,25 @@ async def test_async_step_bluetooth_valid_device(hass: HomeAssistant) -> None:
|
|||||||
assert result2["result"].unique_id == "aa:bb:cc:dd:ee:ff"
|
assert result2["result"].unique_id == "aa:bb:cc:dd:ee:ff"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_step_bluetooth_device_without_name(hass: HomeAssistant) -> None:
|
||||||
|
"""Test discovery via bluetooth with a valid device that has no name."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
context={"source": config_entries.SOURCE_BLUETOOTH},
|
||||||
|
data=VALID_DATA_SERVICE_INFO_WITH_NO_NAME,
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "bluetooth_confirm"
|
||||||
|
with patch("homeassistant.components.aranet.async_setup_entry", return_value=True):
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"], user_input={}
|
||||||
|
)
|
||||||
|
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
assert result2["title"] == "Aranet (EEFF)"
|
||||||
|
assert result2["data"] == {}
|
||||||
|
assert result2["result"].unique_id == "aa:bb:cc:dd:ee:ff"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_bluetooth_not_aranet4(hass: HomeAssistant) -> None:
|
async def test_async_step_bluetooth_not_aranet4(hass: HomeAssistant) -> None:
|
||||||
"""Test that we reject discovery via Bluetooth for an unrelated device."""
|
"""Test that we reject discovery via Bluetooth for an unrelated device."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user