Upgrade to use new version of HASS-nabucasa (#30506)

* Upgrade to use new version of HASS-nabucasa

* Update hass-nabucasa to 0.31
This commit is contained in:
Paulus Schoutsen 2020-01-07 13:25:57 +01:00 committed by Pascal Vizeli
parent 6dc49a44d9
commit c963128306
10 changed files with 31 additions and 45 deletions

View file

@ -33,7 +33,6 @@ from .const import (
CONF_FILTER,
CONF_GOOGLE_ACTIONS,
CONF_GOOGLE_ACTIONS_REPORT_STATE_URL,
CONF_GOOGLE_ACTIONS_SYNC_URL,
CONF_RELAYER,
CONF_REMOTE_API_URL,
CONF_SUBSCRIPTION_INFO_URL,
@ -93,7 +92,6 @@ CONFIG_SCHEMA = vol.Schema(
vol.Optional(CONF_USER_POOL_ID): str,
vol.Optional(CONF_REGION): str,
vol.Optional(CONF_RELAYER): str,
vol.Optional(CONF_GOOGLE_ACTIONS_SYNC_URL): vol.Url(),
vol.Optional(CONF_SUBSCRIPTION_INFO_URL): vol.Url(),
vol.Optional(CONF_CLOUDHOOK_CREATE_URL): vol.Url(),
vol.Optional(CONF_REMOTE_API_URL): vol.Url(),

View file

@ -31,7 +31,6 @@ CONF_FILTER = "filter"
CONF_GOOGLE_ACTIONS = "google_actions"
CONF_RELAYER = "relayer"
CONF_USER_POOL_ID = "user_pool_id"
CONF_GOOGLE_ACTIONS_SYNC_URL = "google_actions_sync_url"
CONF_SUBSCRIPTION_INFO_URL = "subscription_info_url"
CONF_CLOUDHOOK_CREATE_URL = "cloudhook_create_url"
CONF_REMOTE_API_URL = "remote_api_url"

View file

@ -2,7 +2,7 @@
import asyncio
import logging
import async_timeout
from hass_nabucasa import cloud_api
from hass_nabucasa.google_report_state import ErrorResponse
from homeassistant.components.google_assistant.helpers import AbstractConfig
@ -126,21 +126,9 @@ class CloudGoogleConfig(AbstractConfig):
if self._sync_entities_lock.locked():
return 200
websession = self.hass.helpers.aiohttp_client.async_get_clientsession()
async with self._sync_entities_lock:
with async_timeout.timeout(10):
await self._cloud.auth.async_check_token()
_LOGGER.debug("Requesting sync")
with async_timeout.timeout(30):
req = await websession.post(
self._cloud.google_actions_sync_url,
headers={"authorization": self._cloud.id_token},
)
_LOGGER.debug("Finished requesting syncing: %s", req.status)
return req.status
resp = await cloud_api.async_google_actions_request_sync(self._cloud)
return resp.status
async def _async_prefs_updated(self, prefs):
"""Handle updated preferences."""

View file

@ -2,7 +2,7 @@
"domain": "cloud",
"name": "Home Assistant Cloud",
"documentation": "https://www.home-assistant.io/integrations/cloud",
"requirements": ["hass-nabucasa==0.30"],
"requirements": ["hass-nabucasa==0.31"],
"dependencies": ["http", "webhook"],
"after_dependencies": ["alexa", "google_assistant"],
"codeowners": ["@home-assistant/cloud"]

View file

@ -10,7 +10,7 @@ certifi>=2019.11.28
cryptography==2.8
defusedxml==0.6.0
distro==1.4.0
hass-nabucasa==0.30
hass-nabucasa==0.31
home-assistant-frontend==20191204.1
importlib-metadata==1.3.0
jinja2>=2.10.3

View file

@ -649,7 +649,7 @@ habitipy==0.2.0
hangups==0.4.9
# homeassistant.components.cloud
hass-nabucasa==0.30
hass-nabucasa==0.31
# homeassistant.components.mqtt
hbmqtt==0.9.5

View file

@ -226,7 +226,7 @@ ha-ffmpeg==2.0
hangups==0.4.9
# homeassistant.components.cloud
hass-nabucasa==0.30
hass-nabucasa==0.31
# homeassistant.components.mqtt
hbmqtt==0.9.5

View file

@ -36,19 +36,20 @@ async def test_google_update_report_state(hass, cloud_prefs):
async def test_sync_entities(aioclient_mock, hass, cloud_prefs):
"""Test sync devices."""
aioclient_mock.post("http://example.com", status=404)
config = CloudGoogleConfig(
hass,
GACTIONS_SCHEMA({}),
"mock-user-id",
cloud_prefs,
Mock(
google_actions_sync_url="http://example.com",
auth=Mock(async_check_token=Mock(side_effect=mock_coro)),
),
Mock(auth=Mock(async_check_token=Mock(side_effect=mock_coro)),),
)
with patch(
"hass_nabucasa.cloud_api.async_google_actions_request_sync",
return_value=mock_coro(Mock(status=404)),
) as mock_request_sync:
assert await config.async_sync_entities("user") == 404
assert len(mock_request_sync.mock_calls) == 1
async def test_google_update_expose_trigger_sync(hass, cloud_prefs):

View file

@ -1,7 +1,7 @@
"""Tests for the HTTP API for the cloud component."""
import asyncio
from ipaddress import ip_network
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock, Mock, patch
from hass_nabucasa import thingtalk
from hass_nabucasa.auth import Unauthenticated, UnknownError
@ -21,7 +21,6 @@ from . import mock_cloud, mock_cloud_prefs
from tests.common import mock_coro
from tests.components.google_assistant import MockConfig
GOOGLE_ACTIONS_SYNC_URL = "https://api-test.hass.io/google_actions_sync"
SUBSCRIPTION_INFO_URL = "https://api-test.hass.io/subscription_info"
@ -59,7 +58,6 @@ def setup_api(hass, aioclient_mock):
"user_pool_id": "user_pool_id",
"region": "region",
"relayer": "relayer",
"google_actions_sync_url": GOOGLE_ACTIONS_SYNC_URL,
"subscription_info_url": SUBSCRIPTION_INFO_URL,
"google_actions": {"filter": {"include_domains": "light"}},
"alexa": {
@ -85,22 +83,26 @@ def mock_cognito():
yield mock_cog()
async def test_google_actions_sync(
mock_cognito, mock_cloud_login, cloud_client, aioclient_mock
):
async def test_google_actions_sync(mock_cognito, mock_cloud_login, cloud_client):
"""Test syncing Google Actions."""
aioclient_mock.post(GOOGLE_ACTIONS_SYNC_URL)
with patch(
"hass_nabucasa.cloud_api.async_google_actions_request_sync",
return_value=mock_coro(Mock(status=200)),
) as mock_request_sync:
req = await cloud_client.post("/api/cloud/google_actions/sync")
assert req.status == 200
assert len(mock_request_sync.mock_calls) == 1
async def test_google_actions_sync_fails(
mock_cognito, mock_cloud_login, cloud_client, aioclient_mock
):
async def test_google_actions_sync_fails(mock_cognito, mock_cloud_login, cloud_client):
"""Test syncing Google Actions gone bad."""
aioclient_mock.post(GOOGLE_ACTIONS_SYNC_URL, status=403)
with patch(
"hass_nabucasa.cloud_api.async_google_actions_request_sync",
return_value=mock_coro(Mock(status=500)),
) as mock_request_sync:
req = await cloud_client.post("/api/cloud/google_actions/sync")
assert req.status == 403
assert req.status == 500
assert len(mock_request_sync.mock_calls) == 1
async def test_login_view(hass, cloud_client):

View file

@ -28,7 +28,6 @@ async def test_constructor_loads_info_from_config(hass):
"user_pool_id": "test-user_pool_id",
"region": "test-region",
"relayer": "test-relayer",
"google_actions_sync_url": "http://test-google_actions_sync_url",
"subscription_info_url": "http://test-subscription-info-url",
"cloudhook_create_url": "http://test-cloudhook_create_url",
"remote_api_url": "http://test-remote_api_url",
@ -46,7 +45,6 @@ async def test_constructor_loads_info_from_config(hass):
assert cl.user_pool_id == "test-user_pool_id"
assert cl.region == "test-region"
assert cl.relayer == "test-relayer"
assert cl.google_actions_sync_url == "http://test-google_actions_sync_url"
assert cl.subscription_info_url == "http://test-subscription-info-url"
assert cl.cloudhook_create_url == "http://test-cloudhook_create_url"
assert cl.remote_api_url == "http://test-remote_api_url"