diff --git a/homeassistant/components/cloud/cloud_api.py b/homeassistant/components/cloud/cloud_api.py index 13575068a3e..c62768cc514 100644 --- a/homeassistant/components/cloud/cloud_api.py +++ b/homeassistant/components/cloud/cloud_api.py @@ -1,8 +1,11 @@ """Cloud APIs.""" from functools import wraps +import logging from . import auth_api +_LOGGER = logging.getLogger(__name__) + def _check_token(func): """Decorate a function to verify valid token.""" @@ -15,7 +18,21 @@ def _check_token(func): return check_token +def _log_response(func): + """Decorate a function to log bad responses.""" + @wraps(func) + async def log_response(*args): + """Log response if it's bad.""" + resp = await func(*args) + meth = _LOGGER.debug if resp.status < 400 else _LOGGER.warning + meth('Fetched %s (%s)', resp.url, resp.status) + return resp + + return log_response + + @_check_token +@_log_response async def async_create_cloudhook(cloud): """Create a cloudhook.""" websession = cloud.hass.helpers.aiohttp_client.async_get_clientsession() diff --git a/homeassistant/components/cloud/const.py b/homeassistant/components/cloud/const.py index 01d92c6f50f..a5019efaa8e 100644 --- a/homeassistant/components/cloud/const.py +++ b/homeassistant/components/cloud/const.py @@ -18,7 +18,7 @@ SERVERS = { 'amazonaws.com/prod/smart_home_sync'), 'subscription_info_url': ('https://stripe-api.nabucasa.com/payments/' 'subscription_info'), - 'cloudhook_create_url': 'https://webhook-api.nabucasa.com/generate' + 'cloudhook_create_url': 'https://webhooks-api.nabucasa.com/generate' } } diff --git a/tests/test_util/aiohttp.py b/tests/test_util/aiohttp.py index d662f3b1955..f5bf0b8a4f8 100644 --- a/tests/test_util/aiohttp.py +++ b/tests/test_util/aiohttp.py @@ -177,6 +177,11 @@ class AiohttpClientMockResponse: """Return dict of cookies.""" return self._cookies + @property + def url(self): + """Return yarl of URL.""" + return self._url + @property def content(self): """Return content."""