Cloud do checks during setup (#33507)
* Update cloud to do more tasks during async_setup * Upgrade hass_nabucasa to 0.33
This commit is contained in:
parent
aaa1d06809
commit
7ae802bb0d
7 changed files with 27 additions and 44 deletions
|
@ -10,7 +10,6 @@ from homeassistant.const import (
|
|||
CONF_MODE,
|
||||
CONF_NAME,
|
||||
CONF_REGION,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
|
@ -191,11 +190,7 @@ async def async_setup(hass, config):
|
|||
client = CloudClient(hass, prefs, websession, alexa_conf, google_conf)
|
||||
cloud = hass.data[DOMAIN] = Cloud(client, **kwargs)
|
||||
|
||||
async def _startup(event):
|
||||
"""Startup event."""
|
||||
await cloud.start()
|
||||
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _startup)
|
||||
await cloud.start()
|
||||
|
||||
async def _shutdown(event):
|
||||
"""Shutdown event."""
|
||||
|
@ -230,17 +225,11 @@ async def async_setup(hass, config):
|
|||
return
|
||||
loaded = True
|
||||
|
||||
hass.async_create_task(
|
||||
hass.helpers.discovery.async_load_platform(
|
||||
"binary_sensor", DOMAIN, {}, config
|
||||
)
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.helpers.discovery.async_load_platform("stt", DOMAIN, {}, config)
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.helpers.discovery.async_load_platform("tts", DOMAIN, {}, config)
|
||||
await hass.helpers.discovery.async_load_platform(
|
||||
"binary_sensor", DOMAIN, {}, config
|
||||
)
|
||||
await hass.helpers.discovery.async_load_platform("stt", DOMAIN, {}, config)
|
||||
await hass.helpers.discovery.async_load_platform("tts", DOMAIN, {}, config)
|
||||
|
||||
cloud.iot.register_on_connect(_on_connect)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"domain": "cloud",
|
||||
"name": "Home Assistant Cloud",
|
||||
"documentation": "https://www.home-assistant.io/integrations/cloud",
|
||||
"requirements": ["hass-nabucasa==0.32.2"],
|
||||
"requirements": ["hass-nabucasa==0.33.0"],
|
||||
"dependencies": ["http", "webhook", "alexa"],
|
||||
"after_dependencies": ["google_assistant"],
|
||||
"codeowners": ["@home-assistant/cloud"]
|
||||
|
|
|
@ -11,7 +11,7 @@ ciso8601==2.1.3
|
|||
cryptography==2.8
|
||||
defusedxml==0.6.0
|
||||
distro==1.4.0
|
||||
hass-nabucasa==0.32.2
|
||||
hass-nabucasa==0.33.0
|
||||
home-assistant-frontend==20200401.0
|
||||
importlib-metadata==1.5.0
|
||||
jinja2>=2.11.1
|
||||
|
|
|
@ -674,7 +674,7 @@ habitipy==0.2.0
|
|||
hangups==0.4.9
|
||||
|
||||
# homeassistant.components.cloud
|
||||
hass-nabucasa==0.32.2
|
||||
hass-nabucasa==0.33.0
|
||||
|
||||
# homeassistant.components.mqtt
|
||||
hbmqtt==0.9.5
|
||||
|
|
|
@ -264,7 +264,7 @@ ha-ffmpeg==2.0
|
|||
hangups==0.4.9
|
||||
|
||||
# homeassistant.components.cloud
|
||||
hass-nabucasa==0.32.2
|
||||
hass-nabucasa==0.33.0
|
||||
|
||||
# homeassistant.components.mqtt
|
||||
hbmqtt==0.9.5
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
"""Tests for the cloud binary sensor."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.components.cloud.const import DISPATCHER_REMOTE_UPDATE
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
async def test_remote_connection_sensor(hass):
|
||||
"""Test the remote connection sensor."""
|
||||
from homeassistant.components.cloud import binary_sensor as bin_sensor
|
||||
|
||||
bin_sensor.WAIT_UNTIL_CHANGE = 0
|
||||
|
||||
assert await async_setup_component(hass, "cloud", {"cloud": {}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("binary_sensor.remote_ui") is None
|
||||
|
||||
# Fake connection/discovery
|
||||
org_cloud = hass.data["cloud"]
|
||||
await org_cloud.iot._on_connect[-1]()
|
||||
await hass.helpers.discovery.async_load_platform(
|
||||
"binary_sensor", "cloud", {}, {"cloud": {}}
|
||||
)
|
||||
|
||||
# Mock test env
|
||||
cloud = hass.data["cloud"] = Mock()
|
||||
|
@ -29,17 +28,18 @@ async def test_remote_connection_sensor(hass):
|
|||
assert state is not None
|
||||
assert state.state == "unavailable"
|
||||
|
||||
cloud.remote.is_connected = False
|
||||
cloud.remote.certificate = object()
|
||||
hass.helpers.dispatcher.async_dispatcher_send(DISPATCHER_REMOTE_UPDATE, {})
|
||||
await hass.async_block_till_done()
|
||||
with patch("homeassistant.components.cloud.binary_sensor.WAIT_UNTIL_CHANGE", 0):
|
||||
cloud.remote.is_connected = False
|
||||
cloud.remote.certificate = object()
|
||||
hass.helpers.dispatcher.async_dispatcher_send(DISPATCHER_REMOTE_UPDATE, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.remote_ui")
|
||||
assert state.state == "off"
|
||||
state = hass.states.get("binary_sensor.remote_ui")
|
||||
assert state.state == "off"
|
||||
|
||||
cloud.remote.is_connected = True
|
||||
hass.helpers.dispatcher.async_dispatcher_send(DISPATCHER_REMOTE_UPDATE, {})
|
||||
await hass.async_block_till_done()
|
||||
cloud.remote.is_connected = True
|
||||
hass.helpers.dispatcher.async_dispatcher_send(DISPATCHER_REMOTE_UPDATE, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.remote_ui")
|
||||
assert state.state == "on"
|
||||
state = hass.states.get("binary_sensor.remote_ui")
|
||||
assert state.state == "on"
|
||||
|
|
|
@ -6,7 +6,7 @@ import pytest
|
|||
from homeassistant.components import cloud
|
||||
from homeassistant.components.cloud.const import DOMAIN
|
||||
from homeassistant.components.cloud.prefs import STORAGE_KEY
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import Context
|
||||
from homeassistant.exceptions import Unauthorized
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
@ -103,12 +103,6 @@ async def test_remote_services(hass, mock_cloud_fixture, hass_read_only_user):
|
|||
|
||||
async def test_startup_shutdown_events(hass, mock_cloud_fixture):
|
||||
"""Test if the cloud will start on startup event."""
|
||||
with patch("hass_nabucasa.Cloud.start", return_value=mock_coro()) as mock_start:
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_start.called
|
||||
|
||||
with patch("hass_nabucasa.Cloud.stop", return_value=mock_coro()) as mock_stop:
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Add table
Reference in a new issue