From f2d016c30432ac16dbb42349fec859eed89178a2 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 15 Mar 2019 13:29:57 +0100 Subject: [PATCH 1/2] Bump version 0.7 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6e581d877..f951f41d3 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -VERSION = "0.6" +VERSION = "0.7" setup( name="hass-nabucasa", From e3d5bfe5093eb4612aeee807f3f5ffb1b7085a8f Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 15 Mar 2019 14:12:23 +0100 Subject: [PATCH 2/2] Send also notifcation about backend (#31) --- hass_nabucasa/const.py | 2 ++ hass_nabucasa/remote.py | 3 +++ tests/test_remote.py | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/hass_nabucasa/const.py b/hass_nabucasa/const.py index d8190bea9..7598fa0e1 100644 --- a/hass_nabucasa/const.py +++ b/hass_nabucasa/const.py @@ -12,6 +12,8 @@ DISPATCH_REMOTE_CONNECT = "remote_connect" DISPATCH_REMOTE_DISCONNECT = "remote_disconnect" +DISPATCH_REMOTE_BACKEND_UP = "remote_backend_up" +DISPATCH_REMOTE_BACKEND_DOWN = "remote_backend_down" SERVERS = { "production": { diff --git a/hass_nabucasa/remote.py b/hass_nabucasa/remote.py index 53779c118..93373356b 100644 --- a/hass_nabucasa/remote.py +++ b/hass_nabucasa/remote.py @@ -175,6 +175,7 @@ async def load_backend(self) -> None: self._snitun_server = server await self._snitun.start() + self.cloud.client.dispatcher_message(const.DISPATCH_REMOTE_BACKEND_UP) # Connect to remote is autostart enabled if self.cloud.client.remote_autostart: @@ -201,6 +202,8 @@ async def close_backend(self) -> None: self._instance_domain = None self._snitun_server = None + self.cloud.client.dispatcher_message(const.DISPATCH_REMOTE_BACKEND_DOWN) + async def handle_connection_requests(self, caller_ip: str) -> None: """Handle connection requests.""" if not self._snitun: diff --git a/tests/test_remote.py b/tests/test_remote.py index 4608299e1..311b975e9 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -1,15 +1,20 @@ """Test remote sni handler.""" import asyncio -from unittest.mock import patch, MagicMock, Mock from datetime import timedelta +from unittest.mock import MagicMock, Mock, patch import pytest +from hass_nabucasa.const import ( + DISPATCH_REMOTE_BACKEND_DOWN, + DISPATCH_REMOTE_BACKEND_UP, + DISPATCH_REMOTE_CONNECT, + DISPATCH_REMOTE_DISCONNECT, +) from hass_nabucasa.remote import RemoteUI from hass_nabucasa.utils import utcnow -from hass_nabucasa.const import DISPATCH_REMOTE_CONNECT, DISPATCH_REMOTE_DISCONNECT -from .common import mock_coro, MockAcme, MockSnitun +from .common import MockAcme, MockSnitun, mock_coro @pytest.fixture(autouse=True) @@ -93,6 +98,9 @@ async def test_load_backend_exists_cert( assert remote._acme_task assert remote._reconnect_task + assert cloud_mock.client.mock_dispatcher[0][0] == DISPATCH_REMOTE_BACKEND_UP + assert cloud_mock.client.mock_dispatcher[1][0] == DISPATCH_REMOTE_CONNECT + async def test_load_backend_not_exists_cert( cloud_mock, acme_mock, mock_cognito, aioclient_mock, snitun_mock @@ -198,6 +206,8 @@ async def test_load_and_unload_backend( assert not remote._acme_task assert not remote._reconnect_task + assert cloud_mock.client.mock_dispatcher[-1][0] == DISPATCH_REMOTE_BACKEND_DOWN + async def test_load_backend_exists_wrong_cert( cloud_mock, acme_mock, mock_cognito, aioclient_mock, snitun_mock