SmartThings Component Enhancements/Fixes (#21085)

* Improve component setup error logging/notification

* Prevent capabilities from being represented my multiple platforms

* Improved logging of received updates

* Updates based on review feedback
This commit is contained in:
Andrew Sayre authored and Martin Hjelmare committed 2019-02-15 17:40:54 +01:00
1 parent 7d0f847f83
commit 93f84a5cd1
20 files changed
+196 -151

No files matched your search

@@ -1,8 +1,9 @@
"""Tests for the SmartThings config flow module."""
from unittest.mock import patch
from unittest.mock import Mock, patch
from uuid import uuid4
from aiohttp.client_exceptions import ClientResponseError
from aiohttp import ClientResponseError
from pysmartthings import APIResponseError
from homeassistant import data_entry_flow
from homeassistant.components.smartthings.config_flow import (
@@ -103,13 +104,50 @@ async def test_token_forbidden(hass, smartthings_mock):
assert result['errors'] == {'access_token': 'token_forbidden'}
async def test_webhook_error(hass, smartthings_mock):
"""Test an error is when there's an error with the webhook endpoint."""
flow = SmartThingsFlowHandler()
flow.hass = hass
data = {'error': {}}
error = APIResponseError(None, None, data=data, status=422)
error.is_target_error = Mock(return_value=True)
smartthings_mock.return_value.apps.return_value = mock_coro(
exception=error)
result = await flow.async_step_user({'access_token': str(uuid4())})
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'user'
assert result['errors'] == {'base': 'webhook_error'}
async def test_api_error(hass, smartthings_mock):
"""Test an error is shown when other API errors occur."""
flow = SmartThingsFlowHandler()
flow.hass = hass
data = {'error': {}}
error = APIResponseError(None, None, data=data, status=400)
smartthings_mock.return_value.apps.return_value = mock_coro(
exception=error)
result = await flow.async_step_user({'access_token': str(uuid4())})
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'user'
assert result['errors'] == {'base': 'app_setup_error'}
async def test_unknown_api_error(hass, smartthings_mock):
"""Test an error is shown when there is an unknown API error."""
flow = SmartThingsFlowHandler()
flow.hass = hass
smartthings_mock.return_value.apps.return_value = mock_coro(
exception=ClientResponseError(None, None, status=500))
exception=ClientResponseError(None, None, status=404))
result = await flow.async_step_user({'access_token': str(uuid4())})