mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Raise ConfigEntryError when board setup fails in firmata (#185007)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2a929d840b
commit
fb30208d32
@@ -18,6 +18,7 @@ from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryError
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
@@ -175,7 +176,11 @@ async def async_setup_entry(
|
||||
board = FirmataBoard(config_entry.data)
|
||||
|
||||
if not await board.async_setup():
|
||||
return False
|
||||
raise ConfigEntryError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="setup_failed",
|
||||
translation_placeholders={"name": board.name},
|
||||
)
|
||||
|
||||
config_entry.runtime_data = board
|
||||
|
||||
|
||||
@@ -4,5 +4,10 @@
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
},
|
||||
"step": {}
|
||||
},
|
||||
"exceptions": {
|
||||
"setup_failed": {
|
||||
"message": "Failed to set up Firmata board {name}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Tests for the Firmata integration setup."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.firmata.const import CONF_SERIAL_PORT, DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_setup_board_failed(hass: HomeAssistant) -> None:
|
||||
"""Test setup fails when the board can't be set up."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_NAME: "serial-/dev/nonExistent",
|
||||
CONF_SERIAL_PORT: "/dev/nonExistent",
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.firmata.board.PymataExpress.start_aio",
|
||||
side_effect=RuntimeError,
|
||||
):
|
||||
await async_setup_component(
|
||||
hass, DOMAIN, {DOMAIN: [{CONF_SERIAL_PORT: "/dev/nonExistent"}]}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
||||
assert entry.reason == "Failed to set up Firmata board serial-/dev/nonExistent"
|
||||
Reference in New Issue
Block a user