mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix handling of non-supported devices in led-ble (#136300)
This commit is contained in:
parent
f5542450c4
commit
b839a2e2bd
@ -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:
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user