Fix handling of non-supported devices in led-ble (#136300)

This commit is contained in:
J. Nick Koston 2025-01-22 22:09:11 -10:00 committed by GitHub
parent f5542450c4
commit b839a2e2bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -6,7 +6,7 @@ import logging
from typing import Any
from bluetooth_data_tools import human_readable_name
from led_ble import BLEAK_EXCEPTIONS, LEDBLE
from led_ble import BLEAK_EXCEPTIONS, LEDBLE, CharacteristicMissingError
import voluptuous as vol
from homeassistant.components.bluetooth import (
@ -66,6 +66,8 @@ class LedBleConfigFlow(ConfigFlow, domain=DOMAIN):
led_ble = LEDBLE(discovery_info.device)
try:
await led_ble.update()
except CharacteristicMissingError:
return self.async_abort(reason="not_supported")
except BLEAK_EXCEPTIONS:
errors["base"] = "cannot_connect"
except Exception:

View File

@ -3,6 +3,7 @@
from unittest.mock import patch
from bleak import BleakError
from led_ble import CharacteristicMissingError
from homeassistant import config_entries
from homeassistant.components.led_ble.const import DOMAIN
@ -202,6 +203,35 @@ async def test_user_step_unknown_exception(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1
async def test_user_step_not_supported(hass: HomeAssistant) -> None:
"""Test user step with a non supported device."""
with patch(
"homeassistant.components.led_ble.config_flow.async_discovered_service_info",
return_value=[LED_BLE_DISCOVERY_INFO],
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
with patch(
"homeassistant.components.led_ble.config_flow.LEDBLE.update",
side_effect=CharacteristicMissingError,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_ADDRESS: LED_BLE_DISCOVERY_INFO.address,
},
)
await hass.async_block_till_done()
assert result2["type"] is FlowResultType.ABORT
assert result2["reason"] == "not_supported"
async def test_bluetooth_step_success(hass: HomeAssistant) -> None:
"""Test bluetooth step success path."""
result = await hass.config_entries.flow.async_init(