mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Raise ConfigEntryError when hub is not primary in hunterdouglas_powerview (#185066)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9a513bcc74
commit
6ea4ca57df
@@ -11,7 +11,7 @@ from aiopvapi.shades import Shades
|
||||
|
||||
from homeassistant.const import CONF_API_VERSION, CONF_HOST, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from .const import DOMAIN, HUB_EXCEPTIONS, MANUFACTURER
|
||||
@@ -55,14 +55,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: PowerviewConfigEntry) ->
|
||||
if hub.role != "Primary":
|
||||
# this should be caught in config_flow, but account for a hub changing roles
|
||||
# this will only happen manually by a user
|
||||
_LOGGER.error(
|
||||
"%s (%s) is performing role of %s Hub. "
|
||||
"Only the Primary Hub can manage shades",
|
||||
hub.name,
|
||||
hub.hub_address,
|
||||
hub.role,
|
||||
raise ConfigEntryError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="not_primary_hub",
|
||||
translation_placeholders={
|
||||
"name": hub.name,
|
||||
"address": hub.hub_address,
|
||||
"role": hub.role,
|
||||
},
|
||||
)
|
||||
return False
|
||||
|
||||
# manual registration of the hub
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
@@ -62,5 +62,10 @@
|
||||
"name": "[%key:component::sensor::entity_component::signal_strength::name%]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"not_primary_hub": {
|
||||
"message": "{name} ({address}) is performing role of {role} Hub. Only the Primary Hub can manage shades"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Tests for the Hunter Douglas PowerView integration setup."""
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from homeassistant.components.hunterdouglas_powerview.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import MOCK_MAC
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_setup_not_primary_hub(hass: HomeAssistant) -> None:
|
||||
"""Test setup fails when the hub is not the primary hub."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, data={"host": "1.2.3.4"}, unique_id=MOCK_MAC)
|
||||
entry.add_to_hass(hass)
|
||||
hub = MagicMock(hub_address="1.2.3.4", role="Secondary")
|
||||
hub.name = "PowerView Hub"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.hunterdouglas_powerview.async_connect_hub",
|
||||
AsyncMock(return_value=MagicMock(hub=hub)),
|
||||
):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
||||
assert entry.reason == (
|
||||
"PowerView Hub (1.2.3.4) is performing role of Secondary Hub. Only the"
|
||||
" Primary Hub can manage shades"
|
||||
)
|
||||
Reference in New Issue
Block a user