Enhance SmartThings component subscription (#21124)
* Move to config v2 to store SmartApp oauth keys * Add migration functionality. * Regenerate refresh token on periodic basis * Fix regenerate and misc. optimizations * Review feedback * Subscription sync logic now performs a difference operation * Removed config entry reloading.
This commit is contained in:
1 parent
d9712027e8
commit
8b38b82e73
14 files changed
+529
-275
No files matched your search
@@ -6,28 +6,13 @@ real HTTP calls are not initiated during testing.
|
||||
"""
|
||||
from pysmartthings import Attribute, Capability
|
||||
|
||||
from homeassistant.components.smartthings import DeviceBroker, switch
|
||||
from homeassistant.components.smartthings import switch
|
||||
from homeassistant.components.smartthings.const import (
|
||||
DATA_BROKERS, DOMAIN, SIGNAL_SMARTTHINGS_UPDATE)
|
||||
from homeassistant.config_entries import (
|
||||
CONN_CLASS_CLOUD_PUSH, SOURCE_USER, ConfigEntry)
|
||||
DOMAIN, SIGNAL_SMARTTHINGS_UPDATE)
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
|
||||
async def _setup_platform(hass, *devices):
|
||||
"""Set up the SmartThings switch platform and prerequisites."""
|
||||
hass.config.components.add(DOMAIN)
|
||||
broker = DeviceBroker(hass, devices, '')
|
||||
config_entry = ConfigEntry("1", DOMAIN, "Test", {},
|
||||
SOURCE_USER, CONN_CLASS_CLOUD_PUSH)
|
||||
hass.data[DOMAIN] = {
|
||||
DATA_BROKERS: {
|
||||
config_entry.entry_id: broker
|
||||
}
|
||||
}
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, 'switch')
|
||||
await hass.async_block_till_done()
|
||||
return config_entry
|
||||
from .conftest import setup_platform
|
||||
|
||||
|
||||
async def test_async_setup_platform():
|
||||
@@ -43,7 +28,7 @@ async def test_entity_and_device_attributes(hass, device_factory):
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
device_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
# Act
|
||||
await _setup_platform(hass, device)
|
||||
await setup_platform(hass, SWITCH_DOMAIN, device)
|
||||
# Assert
|
||||
entry = entity_registry.async_get('switch.switch_1')
|
||||
assert entry
|
||||
@@ -62,7 +47,7 @@ async def test_turn_off(hass, device_factory):
|
||||
# Arrange
|
||||
device = device_factory('Switch_1', [Capability.switch],
|
||||
{Attribute.switch: 'on'})
|
||||
await _setup_platform(hass, device)
|
||||
await setup_platform(hass, SWITCH_DOMAIN, device)
|
||||
# Act
|
||||
await hass.services.async_call(
|
||||
'switch', 'turn_off', {'entity_id': 'switch.switch_1'},
|
||||
@@ -78,7 +63,7 @@ async def test_turn_on(hass, device_factory):
|
||||
# Arrange
|
||||
device = device_factory('Switch_1', [Capability.switch],
|
||||
{Attribute.switch: 'off'})
|
||||
await _setup_platform(hass, device)
|
||||
await setup_platform(hass, SWITCH_DOMAIN, device)
|
||||
# Act
|
||||
await hass.services.async_call(
|
||||
'switch', 'turn_on', {'entity_id': 'switch.switch_1'},
|
||||
@@ -94,7 +79,7 @@ async def test_update_from_signal(hass, device_factory):
|
||||
# Arrange
|
||||
device = device_factory('Switch_1', [Capability.switch],
|
||||
{Attribute.switch: 'off'})
|
||||
await _setup_platform(hass, device)
|
||||
await setup_platform(hass, SWITCH_DOMAIN, device)
|
||||
await device.switch_on(True)
|
||||
# Act
|
||||
async_dispatcher_send(hass, SIGNAL_SMARTTHINGS_UPDATE,
|
||||
@@ -111,7 +96,7 @@ async def test_unload_config_entry(hass, device_factory):
|
||||
# Arrange
|
||||
device = device_factory('Switch 1', [Capability.switch],
|
||||
{Attribute.switch: 'on'})
|
||||
config_entry = await _setup_platform(hass, device)
|
||||
config_entry = await setup_platform(hass, SWITCH_DOMAIN, device)
|
||||
# Act
|
||||
await hass.config_entries.async_forward_entry_unload(
|
||||
config_entry, 'switch')
|
||||
|
||||
Reference in new issue
Block a user