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:
1 parent
7d0f847f83
commit
93f84a5cd1
20 files changed
+196
-151
No files matched your search
@@ -100,19 +100,6 @@ async def test_async_setup_platform():
|
||||
await climate.async_setup_platform(None, None, None)
|
||||
|
||||
|
||||
def test_is_climate(device_factory, legacy_thermostat,
|
||||
basic_thermostat, thermostat):
|
||||
"""Test climate devices are correctly identified."""
|
||||
other_devices = [
|
||||
device_factory('Unknown', ['Unknown']),
|
||||
device_factory("Switch 1", [Capability.switch])
|
||||
]
|
||||
for device in [legacy_thermostat, basic_thermostat, thermostat]:
|
||||
assert climate.is_climate(device), device.name
|
||||
for device in other_devices:
|
||||
assert not climate.is_climate(device), device.name
|
||||
|
||||
|
||||
async def test_legacy_thermostat_entity_state(hass, legacy_thermostat):
|
||||
"""Tests the state attributes properly match the thermostat type."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, legacy_thermostat)
|
||||
|
||||
@@ -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())})
|
||||
|
||||
|
||||
@@ -39,26 +39,6 @@ async def test_async_setup_platform():
|
||||
await fan.async_setup_platform(None, None, None)
|
||||
|
||||
|
||||
def test_is_fan(device_factory):
|
||||
"""Test fans are correctly identified."""
|
||||
non_fans = [
|
||||
device_factory('Unknown', ['Unknown']),
|
||||
device_factory("Switch 1", [Capability.switch]),
|
||||
device_factory("Non-Switchable Fan", [Capability.fan_speed]),
|
||||
device_factory("Color Light",
|
||||
[Capability.switch, Capability.switch_level,
|
||||
Capability.color_control,
|
||||
Capability.color_temperature])
|
||||
]
|
||||
fan_device = device_factory(
|
||||
"Fan 1", [Capability.switch, Capability.switch_level,
|
||||
Capability.fan_speed])
|
||||
|
||||
assert fan.is_fan(fan_device), fan_device.name
|
||||
for device in non_fans:
|
||||
assert not fan.is_fan(device), device.name
|
||||
|
||||
|
||||
async def test_entity_state(hass, device_factory):
|
||||
"""Tests the state attributes properly match the fan types."""
|
||||
device = device_factory(
|
||||
|
||||
@@ -65,25 +65,6 @@ async def test_async_setup_platform():
|
||||
await light.async_setup_platform(None, None, None)
|
||||
|
||||
|
||||
def test_is_light(device_factory, light_devices):
|
||||
"""Test lights are correctly identified."""
|
||||
non_lights = [
|
||||
device_factory('Unknown', ['Unknown']),
|
||||
device_factory("Fan 1",
|
||||
[Capability.switch, Capability.switch_level,
|
||||
Capability.fan_speed]),
|
||||
device_factory("Switch 1", [Capability.switch]),
|
||||
device_factory("Can't be turned off",
|
||||
[Capability.switch_level, Capability.color_control,
|
||||
Capability.color_temperature])
|
||||
]
|
||||
|
||||
for device in light_devices:
|
||||
assert light.is_light(device), device.name
|
||||
for device in non_lights:
|
||||
assert not light.is_light(device), device.name
|
||||
|
||||
|
||||
async def test_entity_state(hass, light_devices):
|
||||
"""Tests the state attributes properly match the light types."""
|
||||
await _setup_platform(hass, *light_devices)
|
||||
|
||||
@@ -20,12 +20,6 @@ async def test_async_setup_platform():
|
||||
await lock.async_setup_platform(None, None, None)
|
||||
|
||||
|
||||
def test_is_lock(device_factory):
|
||||
"""Test locks are correctly identified."""
|
||||
lock_device = device_factory('Lock', [Capability.lock])
|
||||
assert lock.is_lock(lock_device)
|
||||
|
||||
|
||||
async def test_entity_and_device_attributes(hass, device_factory):
|
||||
"""Test the attributes of the entity are correct."""
|
||||
# Arrange
|
||||
|
||||
@@ -35,23 +35,6 @@ async def test_async_setup_platform():
|
||||
await switch.async_setup_platform(None, None, None)
|
||||
|
||||
|
||||
def test_is_switch(device_factory):
|
||||
"""Test switches are correctly identified."""
|
||||
switch_device = device_factory('Switch', [Capability.switch])
|
||||
non_switch_devices = [
|
||||
device_factory('Light', [Capability.switch, Capability.switch_level]),
|
||||
device_factory('Fan', [Capability.switch, Capability.fan_speed]),
|
||||
device_factory('Color Light', [Capability.switch,
|
||||
Capability.color_control]),
|
||||
device_factory('Temp Light', [Capability.switch,
|
||||
Capability.color_temperature]),
|
||||
device_factory('Unknown', ['Unknown']),
|
||||
]
|
||||
assert switch.is_switch(switch_device)
|
||||
for non_switch_device in non_switch_devices:
|
||||
assert not switch.is_switch(non_switch_device)
|
||||
|
||||
|
||||
async def test_entity_and_device_attributes(hass, device_factory):
|
||||
"""Test the attributes of the entity are correct."""
|
||||
# Arrange
|
||||
|
||||
Reference in new issue
Block a user