Skip to content

Commit 5eb5b93

Browse files
Shutgunabmantis
andauthored
Allow devolo Home Control remote gateways to be offline (home-assistant#152486)
Co-authored-by: Abílio Costa <[email protected]>
1 parent 7c6a39e commit 5eb5b93

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

homeassistant/components/devolo_home_control/__init__.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
from collections.abc import Mapping
77
from functools import partial
8+
import logging
89
from typing import Any
910

1011
from devolo_home_control_api.exceptions.gateway import GatewayOfflineError
@@ -22,6 +23,8 @@
2223

2324
type DevoloHomeControlConfigEntry = ConfigEntry[list[HomeControl]]
2425

26+
_LOGGER = logging.getLogger(__name__)
27+
2528

2629
async def async_setup_entry(
2730
hass: HomeAssistant, entry: DevoloHomeControlConfigEntry
@@ -44,26 +47,29 @@ def shutdown(event: Event) -> None:
4447
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown)
4548
)
4649

47-
try:
48-
zeroconf_instance = await zeroconf.async_get_instance(hass)
49-
entry.runtime_data = []
50-
for gateway_id in gateway_ids:
50+
zeroconf_instance = await zeroconf.async_get_instance(hass)
51+
entry.runtime_data = []
52+
offline_gateways = 0
53+
for gateway_id in gateway_ids:
54+
try:
5155
entry.runtime_data.append(
5256
await hass.async_add_executor_job(
5357
partial(
5458
HomeControl,
55-
gateway_id=str(gateway_id),
59+
gateway_id=gateway_id,
5660
mydevolo_instance=mydevolo,
5761
zeroconf_instance=zeroconf_instance,
5862
)
5963
)
6064
)
61-
except GatewayOfflineError as err:
65+
except GatewayOfflineError:
66+
offline_gateways += 1
67+
_LOGGER.info("Central unit %s cannot be reached locally", gateway_id)
68+
if len(gateway_ids) == offline_gateways:
6269
raise ConfigEntryNotReady(
6370
translation_domain=DOMAIN,
6471
translation_key="connection_failed",
65-
translation_placeholders={"gateway_id": gateway_id},
66-
) from err
72+
)
6773

6874
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
6975

homeassistant/components/devolo_home_control/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"documentation": "https://www.home-assistant.io/integrations/devolo_home_control",
88
"integration_type": "hub",
99
"iot_class": "local_push",
10-
"loggers": ["devolo_home_control_api"],
10+
"loggers": ["HomeControl", "Mydevolo", "MprmRest", "MprmWebsocket", "Mprm"],
1111
"requirements": ["devolo-home-control-api==0.19.0"],
1212
"zeroconf": ["_dvl-deviceapi._tcp.local."]
1313
}

homeassistant/components/devolo_home_control/strings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
},
5959
"exceptions": {
6060
"connection_failed": {
61-
"message": "Failed to connect to devolo Home Control central unit {gateway_id}."
61+
"message": "Failed to connect to any devolo Home Control central unit."
6262
},
6363
"invalid_auth": {
6464
"message": "Authentication failed. Please re-authenticate with your mydevolo account."

tests/components/devolo_home_control/test_init.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ async def test_setup_entry_maintenance(
4747

4848

4949
async def test_setup_gateway_offline(hass: HomeAssistant) -> None:
50-
"""Test setup entry fails on gateway offline."""
50+
"""Test setup entry with one gateway online and one gateway offline."""
51+
entry = configure_integration(hass)
52+
test_gateway = HomeControlMock()
53+
with patch(
54+
"homeassistant.components.devolo_home_control.HomeControl",
55+
side_effect=[test_gateway, GatewayOfflineError],
56+
):
57+
await hass.config_entries.async_setup(entry.entry_id)
58+
assert entry.state is ConfigEntryState.LOADED
59+
60+
61+
async def test_setup_all_gateways_offline(hass: HomeAssistant) -> None:
62+
"""Test setup entry fails on all gateways offline."""
5163
entry = configure_integration(hass)
5264
with patch(
5365
"homeassistant.components.devolo_home_control.HomeControl",

0 commit comments

Comments
 (0)