Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions homeassistant/components/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
CONF_MODE,
CONF_NAME,
CONF_REGION,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import callback
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -230,17 +225,11 @@ async def _on_connect():
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)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cloud/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def async_added_to_hass(self):
async def async_state_update(data):
"""Update callback."""
await asyncio.sleep(WAIT_UNTIL_CHANGE)
self.async_schedule_update_ha_state()
self.async_write_ha_state()

self._unsub_dispatcher = async_dispatcher_connect(
self.hass, DISPATCHER_REMOTE_UPDATE, async_state_update
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/cloud/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions tests/components/cloud/test_binary_sensor.py
Original file line number Diff line number Diff line change
@@ -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(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nicer if we didn't have to mock integration code directly but could mock things in the periphery instead to have the platform load.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, our cloud mocks have not kept up over time.

"binary_sensor", "cloud", {}, {"cloud": {}}
)

# Mock test env
cloud = hass.data["cloud"] = Mock()
Expand All @@ -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"
8 changes: 1 addition & 7 deletions tests/components/cloud/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand Down Expand Up @@ -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()
Expand Down