mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Cloud: Recover when internet is not available yet (#42877)
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
"""Test the cloud.iot module."""
|
||||
from datetime import timedelta
|
||||
|
||||
import aiohttp
|
||||
from aiohttp import web
|
||||
import pytest
|
||||
|
||||
@@ -8,10 +11,12 @@ from homeassistant.components.cloud.const import PREF_ENABLE_ALEXA, PREF_ENABLE_
|
||||
from homeassistant.const import CONTENT_TYPE_JSON
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import mock_cloud, mock_cloud_prefs
|
||||
|
||||
from tests.async_mock import AsyncMock, MagicMock, patch
|
||||
from tests.async_mock import AsyncMock, MagicMock, Mock, patch
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.components.alexa import test_smart_home as test_alexa
|
||||
|
||||
|
||||
@@ -260,3 +265,25 @@ async def test_set_username(hass):
|
||||
|
||||
assert len(prefs.async_set_username.mock_calls) == 1
|
||||
assert prefs.async_set_username.mock_calls[0][1][0] == "mock-username"
|
||||
|
||||
|
||||
async def test_login_recovers_bad_internet(hass, caplog):
|
||||
"""Test Alexa can recover bad auth."""
|
||||
prefs = Mock(
|
||||
alexa_enabled=True,
|
||||
google_enabled=False,
|
||||
async_set_username=AsyncMock(return_value=None),
|
||||
)
|
||||
client = CloudClient(hass, prefs, None, {}, {})
|
||||
client.cloud = Mock()
|
||||
client._alexa_config = Mock(
|
||||
async_enable_proactive_mode=Mock(side_effect=aiohttp.ClientError)
|
||||
)
|
||||
await client.logged_in()
|
||||
assert len(client._alexa_config.async_enable_proactive_mode.mock_calls) == 1
|
||||
assert "Unable to activate Alexa Report State" in caplog.text
|
||||
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(client._alexa_config.async_enable_proactive_mode.mock_calls) == 2
|
||||
|
||||
Reference in New Issue
Block a user