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
@@ -4,8 +4,8 @@ from unittest.mock import Mock, patch
|
||||
from uuid import uuid4
|
||||
|
||||
from pysmartthings import (
|
||||
CLASSIFICATION_AUTOMATION, AppEntity, AppSettings, DeviceEntity,
|
||||
InstalledApp, Location)
|
||||
CLASSIFICATION_AUTOMATION, AppEntity, AppOAuthClient, AppSettings,
|
||||
DeviceEntity, InstalledApp, Location, Subscription)
|
||||
from pysmartthings.api import Api
|
||||
import pytest
|
||||
|
||||
@@ -13,8 +13,9 @@ from homeassistant.components import webhook
|
||||
from homeassistant.components.smartthings import DeviceBroker
|
||||
from homeassistant.components.smartthings.const import (
|
||||
APP_NAME_PREFIX, CONF_APP_ID, CONF_INSTALLED_APP_ID, CONF_INSTANCE_ID,
|
||||
CONF_LOCATION_ID, DATA_BROKERS, DOMAIN, SETTINGS_INSTANCE_ID, STORAGE_KEY,
|
||||
STORAGE_VERSION)
|
||||
CONF_LOCATION_ID, CONF_OAUTH_CLIENT_ID, CONF_OAUTH_CLIENT_SECRET,
|
||||
CONF_REFRESH_TOKEN, DATA_BROKERS, DOMAIN, SETTINGS_INSTANCE_ID,
|
||||
STORAGE_KEY, STORAGE_VERSION)
|
||||
from homeassistant.config_entries import (
|
||||
CONN_CLASS_CLOUD_PUSH, SOURCE_USER, ConfigEntry)
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_WEBHOOK_ID
|
||||
@@ -26,9 +27,11 @@ from tests.common import mock_coro
|
||||
async def setup_platform(hass, platform: str, *devices):
|
||||
"""Set up the SmartThings platform and prerequisites."""
|
||||
hass.config.components.add(DOMAIN)
|
||||
broker = DeviceBroker(hass, devices, '')
|
||||
config_entry = ConfigEntry("1", DOMAIN, "Test", {},
|
||||
config_entry = ConfigEntry(2, DOMAIN, "Test",
|
||||
{CONF_INSTALLED_APP_ID: str(uuid4())},
|
||||
SOURCE_USER, CONN_CLASS_CLOUD_PUSH)
|
||||
broker = DeviceBroker(hass, config_entry, Mock(), Mock(), devices)
|
||||
|
||||
hass.data[DOMAIN] = {
|
||||
DATA_BROKERS: {
|
||||
config_entry.entry_id: broker
|
||||
@@ -98,6 +101,15 @@ def app_fixture(hass, config_file):
|
||||
return app
|
||||
|
||||
|
||||
@pytest.fixture(name="app_oauth_client")
|
||||
def app_oauth_client_fixture():
|
||||
"""Fixture for a single app's oauth."""
|
||||
return AppOAuthClient({
|
||||
'oauthClientId': str(uuid4()),
|
||||
'oauthClientSecret': str(uuid4())
|
||||
})
|
||||
|
||||
|
||||
@pytest.fixture(name='app_settings')
|
||||
def app_settings_fixture(app, config_file):
|
||||
"""Fixture for an app settings."""
|
||||
@@ -225,12 +237,25 @@ def config_entry_fixture(hass, installed_app, location):
|
||||
CONF_ACCESS_TOKEN: str(uuid4()),
|
||||
CONF_INSTALLED_APP_ID: installed_app.installed_app_id,
|
||||
CONF_APP_ID: installed_app.app_id,
|
||||
CONF_LOCATION_ID: location.location_id
|
||||
CONF_LOCATION_ID: location.location_id,
|
||||
CONF_REFRESH_TOKEN: str(uuid4()),
|
||||
CONF_OAUTH_CLIENT_ID: str(uuid4()),
|
||||
CONF_OAUTH_CLIENT_SECRET: str(uuid4())
|
||||
}
|
||||
return ConfigEntry("1", DOMAIN, location.name, data, SOURCE_USER,
|
||||
return ConfigEntry(2, DOMAIN, location.name, data, SOURCE_USER,
|
||||
CONN_CLASS_CLOUD_PUSH)
|
||||
|
||||
|
||||
@pytest.fixture(name="subscription_factory")
|
||||
def subscription_factory_fixture():
|
||||
"""Fixture for creating mock subscriptions."""
|
||||
def _factory(capability):
|
||||
sub = Subscription()
|
||||
sub.capability = capability
|
||||
return sub
|
||||
return _factory
|
||||
|
||||
|
||||
@pytest.fixture(name="device_factory")
|
||||
def device_factory_fixture():
|
||||
"""Fixture for creating mock devices."""
|
||||
|
||||
Reference in new issue
Block a user