mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 05:47:10 +00:00
Handle error fetching available account link services (#35485)
This commit is contained in:
parent
f4ab5ee54f
commit
c401949af8
@ -3,6 +3,7 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
from hass_nabucasa import account_link
|
from hass_nabucasa import account_link
|
||||||
|
|
||||||
from homeassistant.const import MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION
|
from homeassistant.const import MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION
|
||||||
@ -73,7 +74,10 @@ async def _get_services(hass):
|
|||||||
if services is not None:
|
if services is not None:
|
||||||
return services
|
return services
|
||||||
|
|
||||||
services = await account_link.async_fetch_available_services(hass.data[DOMAIN])
|
try:
|
||||||
|
services = await account_link.async_fetch_available_services(hass.data[DOMAIN])
|
||||||
|
except (aiohttp.ClientError, asyncio.TimeoutError):
|
||||||
|
return []
|
||||||
|
|
||||||
hass.data[DATA_SERVICES] = services
|
hass.data[DATA_SERVICES] = services
|
||||||
|
|
||||||
|
@ -96,6 +96,18 @@ async def test_get_services_cached(hass):
|
|||||||
assert await account_link._get_services(hass) == 4
|
assert await account_link._get_services(hass) == 4
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_services_error(hass):
|
||||||
|
"""Test that we cache services."""
|
||||||
|
hass.data["cloud"] = None
|
||||||
|
|
||||||
|
with patch.object(account_link, "CACHE_TIMEOUT", 0), patch(
|
||||||
|
"hass_nabucasa.account_link.async_fetch_available_services",
|
||||||
|
side_effect=asyncio.TimeoutError,
|
||||||
|
):
|
||||||
|
assert await account_link._get_services(hass) == []
|
||||||
|
assert account_link.DATA_SERVICES not in hass.data
|
||||||
|
|
||||||
|
|
||||||
async def test_implementation(hass, flow_handler):
|
async def test_implementation(hass, flow_handler):
|
||||||
"""Test Cloud OAuth2 implementation."""
|
"""Test Cloud OAuth2 implementation."""
|
||||||
hass.data["cloud"] = None
|
hass.data["cloud"] = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user