2019-01-31 01:31:59 +00:00
|
|
|
"""Test configuration and mocks for the SmartThings component."""
|
2024-03-08 18:16:21 +00:00
|
|
|
|
2019-12-12 15:46:33 +00:00
|
|
|
import secrets
|
2024-06-03 08:20:57 +00:00
|
|
|
from typing import Any
|
2021-01-01 21:31:56 +00:00
|
|
|
from unittest.mock import Mock, patch
|
2019-01-31 01:31:59 +00:00
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
from pysmartthings import (
|
2019-07-31 19:25:30 +00:00
|
|
|
CLASSIFICATION_AUTOMATION,
|
|
|
|
AppEntity,
|
|
|
|
AppOAuthClient,
|
|
|
|
AppSettings,
|
|
|
|
DeviceEntity,
|
|
|
|
DeviceStatus,
|
|
|
|
InstalledApp,
|
|
|
|
InstalledAppStatus,
|
|
|
|
InstalledAppType,
|
|
|
|
Location,
|
|
|
|
SceneEntity,
|
|
|
|
SmartThings,
|
|
|
|
Subscription,
|
|
|
|
)
|
2019-01-31 01:31:59 +00:00
|
|
|
from pysmartthings.api import Api
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.components import webhook
|
2019-02-08 04:51:17 +00:00
|
|
|
from homeassistant.components.smartthings import DeviceBroker
|
2019-01-31 01:31:59 +00:00
|
|
|
from homeassistant.components.smartthings.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
APP_NAME_PREFIX,
|
|
|
|
CONF_APP_ID,
|
|
|
|
CONF_INSTALLED_APP_ID,
|
|
|
|
CONF_INSTANCE_ID,
|
|
|
|
CONF_LOCATION_ID,
|
|
|
|
CONF_REFRESH_TOKEN,
|
|
|
|
DATA_BROKERS,
|
|
|
|
DOMAIN,
|
|
|
|
SETTINGS_INSTANCE_ID,
|
|
|
|
STORAGE_KEY,
|
|
|
|
STORAGE_VERSION,
|
|
|
|
)
|
2020-05-08 15:52:32 +00:00
|
|
|
from homeassistant.config import async_process_ha_core_config
|
Ensure config entries are not unloaded while their platforms are setting up (#118767)
* Report non-awaited/non-locked config entry platform forwards
Its currently possible for config entries to be reloaded while their platforms
are being forwarded if platform forwards are not awaited or done after the
config entry is setup since the lock will not be held in this case.
In https://developers.home-assistant.io/blog/2022/07/08/config_entry_forwards
we advised to await platform forwards to ensure this does not happen, however
for sleeping devices and late discovered devices, platform forwards may happen
later.
If config platform forwards are happening during setup, they should be awaited
If config entry platform forwards are not happening during setup, instead
async_late_forward_entry_setups should be used which will hold the lock to
prevent the config entry from being unloaded while its platforms are being
setup
* Report non-awaited/non-locked config entry platform forwards
Its currently possible for config entries to be reloaded while their platforms
are being forwarded if platform forwards are not awaited or done after the
config entry is setup since the lock will not be held in this case.
In https://developers.home-assistant.io/blog/2022/07/08/config_entry_forwards
we advised to await platform forwards to ensure this does not happen, however
for sleeping devices and late discovered devices, platform forwards may happen
later.
If config platform forwards are happening during setup, they should be awaited
If config entry platform forwards are not happening during setup, instead
async_late_forward_entry_setups should be used which will hold the lock to
prevent the config entry from being unloaded while its platforms are being
setup
* run with error on to find them
* cert_exp, hold lock
* cert_exp, hold lock
* shelly async_late_forward_entry_setups
* compact
* compact
* found another
* patch up mobileapp
* patch up hue tests
* patch up smartthings
* fix mqtt
* fix esphome
* zwave_js
* mqtt
* rework
* fixes
* fix mocking
* fix mocking
* do not call async_forward_entry_setup directly
* docstrings
* docstrings
* docstrings
* add comments
* doc strings
* fixed all in core, turn off strict
* coverage
* coverage
* missing
* coverage
2024-06-05 01:34:39 +00:00
|
|
|
from homeassistant.config_entries import SOURCE_USER, ConfigEntryState
|
2020-05-30 15:27:20 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
CONF_ACCESS_TOKEN,
|
|
|
|
CONF_CLIENT_ID,
|
|
|
|
CONF_CLIENT_SECRET,
|
|
|
|
CONF_WEBHOOK_ID,
|
|
|
|
)
|
2024-06-03 08:20:57 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-01-31 01:31:59 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
2019-07-16 21:51:30 +00:00
|
|
|
from tests.common import MockConfigEntry
|
2021-03-02 08:02:04 +00:00
|
|
|
from tests.components.light.conftest import mock_light_profiles # noqa: F401
|
2019-07-16 21:51:30 +00:00
|
|
|
|
2019-07-01 02:29:21 +00:00
|
|
|
COMPONENT_PREFIX = "homeassistant.components.smartthings."
|
|
|
|
|
2019-01-31 01:31:59 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def setup_platform(hass, platform: str, *, devices=None, scenes=None):
|
2019-02-08 04:51:17 +00:00
|
|
|
"""Set up the SmartThings platform and prerequisites."""
|
|
|
|
hass.config.components.add(DOMAIN)
|
2023-08-10 16:26:20 +00:00
|
|
|
config_entry = MockConfigEntry(
|
|
|
|
version=2,
|
|
|
|
domain=DOMAIN,
|
|
|
|
title="Test",
|
|
|
|
data={CONF_INSTALLED_APP_ID: str(uuid4())},
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2023-08-10 16:26:20 +00:00
|
|
|
config_entry.add_to_hass(hass)
|
2019-07-31 19:25:30 +00:00
|
|
|
broker = DeviceBroker(
|
|
|
|
hass, config_entry, Mock(), Mock(), devices or [], scenes or []
|
|
|
|
)
|
|
|
|
|
|
|
|
hass.data[DOMAIN] = {DATA_BROKERS: {config_entry.entry_id: broker}}
|
Ensure config entries are not unloaded while their platforms are setting up (#118767)
* Report non-awaited/non-locked config entry platform forwards
Its currently possible for config entries to be reloaded while their platforms
are being forwarded if platform forwards are not awaited or done after the
config entry is setup since the lock will not be held in this case.
In https://developers.home-assistant.io/blog/2022/07/08/config_entry_forwards
we advised to await platform forwards to ensure this does not happen, however
for sleeping devices and late discovered devices, platform forwards may happen
later.
If config platform forwards are happening during setup, they should be awaited
If config entry platform forwards are not happening during setup, instead
async_late_forward_entry_setups should be used which will hold the lock to
prevent the config entry from being unloaded while its platforms are being
setup
* Report non-awaited/non-locked config entry platform forwards
Its currently possible for config entries to be reloaded while their platforms
are being forwarded if platform forwards are not awaited or done after the
config entry is setup since the lock will not be held in this case.
In https://developers.home-assistant.io/blog/2022/07/08/config_entry_forwards
we advised to await platform forwards to ensure this does not happen, however
for sleeping devices and late discovered devices, platform forwards may happen
later.
If config platform forwards are happening during setup, they should be awaited
If config entry platform forwards are not happening during setup, instead
async_late_forward_entry_setups should be used which will hold the lock to
prevent the config entry from being unloaded while its platforms are being
setup
* run with error on to find them
* cert_exp, hold lock
* cert_exp, hold lock
* shelly async_late_forward_entry_setups
* compact
* compact
* found another
* patch up mobileapp
* patch up hue tests
* patch up smartthings
* fix mqtt
* fix esphome
* zwave_js
* mqtt
* rework
* fixes
* fix mocking
* fix mocking
* do not call async_forward_entry_setup directly
* docstrings
* docstrings
* docstrings
* add comments
* doc strings
* fixed all in core, turn off strict
* coverage
* coverage
* missing
* coverage
2024-06-05 01:34:39 +00:00
|
|
|
config_entry.mock_state(hass, ConfigEntryState.LOADED)
|
|
|
|
await hass.config_entries.async_late_forward_entry_setups(config_entry, [platform])
|
2019-02-08 04:51:17 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
return config_entry
|
|
|
|
|
|
|
|
|
2019-01-31 01:31:59 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
2024-06-03 08:20:57 +00:00
|
|
|
async def setup_component(
|
|
|
|
hass: HomeAssistant, config_file: dict[str, str], hass_storage: dict[str, Any]
|
|
|
|
) -> None:
|
2019-01-31 01:31:59 +00:00
|
|
|
"""Load the SmartThing component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
hass_storage[STORAGE_KEY] = {"data": config_file, "version": STORAGE_VERSION}
|
2020-05-08 15:52:32 +00:00
|
|
|
await async_process_ha_core_config(
|
2020-08-27 11:56:20 +00:00
|
|
|
hass,
|
|
|
|
{"external_url": "https://test.local"},
|
2020-05-08 15:52:32 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
await async_setup_component(hass, "smartthings", {})
|
2019-01-31 01:31:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _create_location():
|
2019-07-09 02:39:55 +00:00
|
|
|
loc = Mock(Location)
|
2019-07-31 19:25:30 +00:00
|
|
|
loc.name = "Test Location"
|
2019-07-09 02:39:55 +00:00
|
|
|
loc.location_id = str(uuid4())
|
2019-01-31 01:31:59 +00:00
|
|
|
return loc
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="location")
|
2019-01-31 01:31:59 +00:00
|
|
|
def location_fixture():
|
|
|
|
"""Fixture for a single location."""
|
|
|
|
return _create_location()
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="locations")
|
2019-01-31 01:31:59 +00:00
|
|
|
def locations_fixture(location):
|
|
|
|
"""Fixture for 2 locations."""
|
|
|
|
return [location, _create_location()]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="app")
|
2020-05-08 15:52:32 +00:00
|
|
|
async def app_fixture(hass, config_file):
|
2019-01-31 01:31:59 +00:00
|
|
|
"""Fixture for a single app."""
|
2019-07-09 02:39:55 +00:00
|
|
|
app = Mock(AppEntity)
|
|
|
|
app.app_name = APP_NAME_PREFIX + str(uuid4())
|
|
|
|
app.app_id = str(uuid4())
|
2019-07-31 19:25:30 +00:00
|
|
|
app.app_type = "WEBHOOK_SMART_APP"
|
2019-07-09 02:39:55 +00:00
|
|
|
app.classifications = [CLASSIFICATION_AUTOMATION]
|
2019-07-31 19:25:30 +00:00
|
|
|
app.display_name = "Home Assistant"
|
2020-05-08 15:52:32 +00:00
|
|
|
app.description = f"{hass.config.location_name} at https://test.local"
|
2019-07-09 02:39:55 +00:00
|
|
|
app.single_instance = True
|
|
|
|
app.webhook_target_url = webhook.async_generate_url(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass, hass.data[DOMAIN][CONF_WEBHOOK_ID]
|
|
|
|
)
|
2019-07-09 02:39:55 +00:00
|
|
|
|
|
|
|
settings = Mock(AppSettings)
|
|
|
|
settings.app_id = app.app_id
|
|
|
|
settings.settings = {SETTINGS_INSTANCE_ID: config_file[CONF_INSTANCE_ID]}
|
|
|
|
app.settings.return_value = settings
|
2019-01-31 01:31:59 +00:00
|
|
|
return app
|
|
|
|
|
|
|
|
|
2019-02-22 19:35:12 +00:00
|
|
|
@pytest.fixture(name="app_oauth_client")
|
|
|
|
def app_oauth_client_fixture():
|
|
|
|
"""Fixture for a single app's oauth."""
|
2019-07-09 02:39:55 +00:00
|
|
|
client = Mock(AppOAuthClient)
|
|
|
|
client.client_id = str(uuid4())
|
|
|
|
client.client_secret = str(uuid4())
|
|
|
|
return client
|
2019-02-22 19:35:12 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="app_settings")
|
2019-01-31 01:31:59 +00:00
|
|
|
def app_settings_fixture(app, config_file):
|
|
|
|
"""Fixture for an app settings."""
|
2019-07-09 02:39:55 +00:00
|
|
|
settings = Mock(AppSettings)
|
|
|
|
settings.app_id = app.app_id
|
|
|
|
settings.settings = {SETTINGS_INSTANCE_ID: config_file[CONF_INSTANCE_ID]}
|
2019-01-31 01:31:59 +00:00
|
|
|
return settings
|
|
|
|
|
|
|
|
|
|
|
|
def _create_installed_app(location_id, app_id):
|
2019-07-09 02:39:55 +00:00
|
|
|
item = Mock(InstalledApp)
|
|
|
|
item.installed_app_id = str(uuid4())
|
|
|
|
item.installed_app_status = InstalledAppStatus.AUTHORIZED
|
|
|
|
item.installed_app_type = InstalledAppType.WEBHOOK_SMART_APP
|
|
|
|
item.app_id = app_id
|
|
|
|
item.location_id = location_id
|
2019-01-31 01:31:59 +00:00
|
|
|
return item
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="installed_app")
|
2019-01-31 01:31:59 +00:00
|
|
|
def installed_app_fixture(location, app):
|
|
|
|
"""Fixture for a single installed app."""
|
|
|
|
return _create_installed_app(location.location_id, app.app_id)
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="installed_apps")
|
2019-01-31 01:31:59 +00:00
|
|
|
def installed_apps_fixture(installed_app, locations, app):
|
|
|
|
"""Fixture for 2 installed apps."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return [installed_app, _create_installed_app(locations[1].location_id, app.app_id)]
|
2019-01-31 01:31:59 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="config_file")
|
2024-06-03 08:20:57 +00:00
|
|
|
def config_file_fixture() -> dict[str, str]:
|
2019-01-31 01:31:59 +00:00
|
|
|
"""Fixture representing the local config file contents."""
|
2019-12-12 15:46:33 +00:00
|
|
|
return {CONF_INSTANCE_ID: str(uuid4()), CONF_WEBHOOK_ID: secrets.token_hex()}
|
2019-01-31 01:31:59 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="smartthings_mock")
|
2019-01-31 01:31:59 +00:00
|
|
|
def smartthings_mock_fixture(locations):
|
|
|
|
"""Fixture to mock smartthings API calls."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-07-09 02:39:55 +00:00
|
|
|
async def _location(location_id):
|
2019-07-31 19:25:30 +00:00
|
|
|
return next(
|
|
|
|
location for location in locations if location.location_id == location_id
|
|
|
|
)
|
2019-01-31 01:31:59 +00:00
|
|
|
|
2019-07-01 02:29:21 +00:00
|
|
|
smartthings_mock = Mock(SmartThings)
|
|
|
|
smartthings_mock.location.side_effect = _location
|
|
|
|
mock = Mock(return_value=smartthings_mock)
|
2024-03-25 23:02:16 +00:00
|
|
|
with (
|
|
|
|
patch(COMPONENT_PREFIX + "SmartThings", new=mock),
|
|
|
|
patch(COMPONENT_PREFIX + "config_flow.SmartThings", new=mock),
|
|
|
|
patch(COMPONENT_PREFIX + "smartapp.SmartThings", new=mock),
|
|
|
|
):
|
2019-07-09 02:39:55 +00:00
|
|
|
yield smartthings_mock
|
2019-01-31 01:31:59 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="device")
|
2019-01-31 01:31:59 +00:00
|
|
|
def device_fixture(location):
|
|
|
|
"""Fixture representing devices loaded."""
|
2019-07-09 02:39:55 +00:00
|
|
|
item = Mock(DeviceEntity)
|
|
|
|
item.device_id = "743de49f-036f-4e9c-839a-2f89d57607db"
|
|
|
|
item.name = "GE In-Wall Smart Dimmer"
|
|
|
|
item.label = "Front Porch Lights"
|
|
|
|
item.location_id = location.location_id
|
|
|
|
item.capabilities = [
|
2019-07-31 19:25:30 +00:00
|
|
|
"switch",
|
|
|
|
"switchLevel",
|
|
|
|
"refresh",
|
|
|
|
"indicator",
|
|
|
|
"sensor",
|
|
|
|
"actuator",
|
|
|
|
"healthCheck",
|
|
|
|
"light",
|
2019-07-09 02:39:55 +00:00
|
|
|
]
|
|
|
|
item.components = {"main": item.capabilities}
|
|
|
|
item.status = Mock(DeviceStatus)
|
2019-01-31 01:31:59 +00:00
|
|
|
return item
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@pytest.fixture(name="config_entry")
|
2019-01-31 01:31:59 +00:00
|
|
|
def config_entry_fixture(hass, installed_app, location):
|
|
|
|
"""Fixture representing a config entry."""
|
|
|
|
data = {
|
|
|
|
CONF_ACCESS_TOKEN: str(uuid4()),
|
|
|
|
CONF_INSTALLED_APP_ID: installed_app.installed_app_id,
|
|
|
|
CONF_APP_ID: installed_app.app_id,
|
2019-02-22 19:35:12 +00:00
|
|
|
CONF_LOCATION_ID: location.location_id,
|
|
|
|
CONF_REFRESH_TOKEN: str(uuid4()),
|
2020-05-30 15:27:20 +00:00
|
|
|
CONF_CLIENT_ID: str(uuid4()),
|
|
|
|
CONF_CLIENT_SECRET: str(uuid4()),
|
2019-01-31 01:31:59 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
return MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data=data,
|
|
|
|
title=location.name,
|
|
|
|
version=2,
|
|
|
|
source=SOURCE_USER,
|
|
|
|
)
|
2019-01-31 01:31:59 +00:00
|
|
|
|
|
|
|
|
2019-02-22 19:35:12 +00:00
|
|
|
@pytest.fixture(name="subscription_factory")
|
|
|
|
def subscription_factory_fixture():
|
|
|
|
"""Fixture for creating mock subscriptions."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-02-22 19:35:12 +00:00
|
|
|
def _factory(capability):
|
|
|
|
sub = Subscription()
|
|
|
|
sub.capability = capability
|
|
|
|
return sub
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-02-22 19:35:12 +00:00
|
|
|
return _factory
|
|
|
|
|
|
|
|
|
2019-01-31 01:31:59 +00:00
|
|
|
@pytest.fixture(name="device_factory")
|
|
|
|
def device_factory_fixture():
|
|
|
|
"""Fixture for creating mock devices."""
|
2019-07-09 02:39:55 +00:00
|
|
|
api = Mock(Api)
|
2020-07-22 23:01:57 +00:00
|
|
|
api.post_device_command.return_value = {"results": [{"status": "ACCEPTED"}]}
|
2019-01-31 01:31:59 +00:00
|
|
|
|
2024-04-10 06:55:59 +00:00
|
|
|
def _factory(label, capabilities, status: dict | None = None):
|
2019-01-31 01:31:59 +00:00
|
|
|
device_data = {
|
|
|
|
"deviceId": str(uuid4()),
|
|
|
|
"name": "Device Type Handler Name",
|
|
|
|
"label": label,
|
|
|
|
"deviceManufacturerCode": "9135fc86-0929-4436-bf73-5d75f523d9db",
|
|
|
|
"locationId": "fcd829e9-82f4-45b9-acfd-62fda029af80",
|
|
|
|
"components": [
|
|
|
|
{
|
|
|
|
"id": "main",
|
|
|
|
"capabilities": [
|
2019-07-31 19:25:30 +00:00
|
|
|
{"id": capability, "version": 1} for capability in capabilities
|
|
|
|
],
|
2019-01-31 01:31:59 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"dth": {
|
|
|
|
"deviceTypeId": "b678b29d-2726-4e4f-9c3f-7aa05bd08964",
|
|
|
|
"deviceTypeName": "Switch",
|
2019-07-31 19:25:30 +00:00
|
|
|
"deviceNetworkType": "ZWAVE",
|
2019-01-31 01:31:59 +00:00
|
|
|
},
|
2019-07-31 19:25:30 +00:00
|
|
|
"type": "DTH",
|
2019-01-31 01:31:59 +00:00
|
|
|
}
|
|
|
|
device = DeviceEntity(api, data=device_data)
|
|
|
|
if status:
|
|
|
|
for attribute, value in status.items():
|
2019-07-31 19:25:30 +00:00
|
|
|
device.status.apply_attribute_update("main", "", attribute, value)
|
2019-01-31 01:31:59 +00:00
|
|
|
return device
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-01-31 01:31:59 +00:00
|
|
|
return _factory
|
|
|
|
|
|
|
|
|
2019-02-26 21:12:24 +00:00
|
|
|
@pytest.fixture(name="scene_factory")
|
|
|
|
def scene_factory_fixture(location):
|
|
|
|
"""Fixture for creating mock devices."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-02-26 21:12:24 +00:00
|
|
|
def _factory(name):
|
2019-07-09 02:39:55 +00:00
|
|
|
scene = Mock(SceneEntity)
|
|
|
|
scene.scene_id = str(uuid4())
|
|
|
|
scene.name = name
|
2022-01-07 18:02:32 +00:00
|
|
|
scene.icon = None
|
|
|
|
scene.color = None
|
2019-07-09 02:39:55 +00:00
|
|
|
scene.location_id = location.location_id
|
|
|
|
return scene
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-02-26 21:12:24 +00:00
|
|
|
return _factory
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="scene")
|
|
|
|
def scene_fixture(scene_factory):
|
|
|
|
"""Fixture for an individual scene."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return scene_factory("Test Scene")
|
2019-02-26 21:12:24 +00:00
|
|
|
|
|
|
|
|
2019-01-31 01:31:59 +00:00
|
|
|
@pytest.fixture(name="event_factory")
|
|
|
|
def event_factory_fixture():
|
|
|
|
"""Fixture for creating mock devices."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
|
|
|
def _factory(
|
|
|
|
device_id,
|
|
|
|
event_type="DEVICE_EVENT",
|
|
|
|
capability="",
|
|
|
|
attribute="Updated",
|
|
|
|
value="Value",
|
|
|
|
data=None,
|
|
|
|
):
|
2019-01-31 01:31:59 +00:00
|
|
|
event = Mock()
|
|
|
|
event.event_type = event_type
|
|
|
|
event.device_id = device_id
|
2019-07-31 19:25:30 +00:00
|
|
|
event.component_id = "main"
|
2019-02-03 06:08:37 +00:00
|
|
|
event.capability = capability
|
|
|
|
event.attribute = attribute
|
|
|
|
event.value = value
|
2019-03-09 05:20:07 +00:00
|
|
|
event.data = data
|
2019-02-03 06:08:37 +00:00
|
|
|
event.location_id = str(uuid4())
|
2019-01-31 01:31:59 +00:00
|
|
|
return event
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-01-31 01:31:59 +00:00
|
|
|
return _factory
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="event_request_factory")
|
|
|
|
def event_request_factory_fixture(event_factory):
|
|
|
|
"""Fixture for creating mock smartapp event requests."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-02-03 06:08:37 +00:00
|
|
|
def _factory(device_ids=None, events=None):
|
2019-01-31 01:31:59 +00:00
|
|
|
request = Mock()
|
|
|
|
request.installed_app_id = uuid4()
|
2019-02-03 06:08:37 +00:00
|
|
|
if events is None:
|
|
|
|
events = []
|
|
|
|
if device_ids:
|
2024-04-21 21:25:27 +00:00
|
|
|
events.extend([event_factory(device_id) for device_id in device_ids])
|
2019-02-03 06:08:37 +00:00
|
|
|
events.append(event_factory(uuid4()))
|
|
|
|
events.append(event_factory(device_ids[0], event_type="OTHER"))
|
|
|
|
request.events = events
|
2019-01-31 01:31:59 +00:00
|
|
|
return request
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-01-31 01:31:59 +00:00
|
|
|
return _factory
|