Add diagnostics to SimpliSafe (#65171)
* Add diagnostics to SimpliSafe * Bump * Cleanup
This commit is contained in:
parent
cc94af2872
commit
58f624a3da
10 changed files with 853 additions and 10 deletions
|
@ -1,24 +1,27 @@
|
|||
"""Define test fixtures for SimpliSafe."""
|
||||
import json
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from simplipy.system.v3 import SystemV3
|
||||
|
||||
from homeassistant.components.simplisafe.config_flow import CONF_AUTH_CODE
|
||||
from homeassistant.components.simplisafe.const import CONF_USER_ID, DOMAIN
|
||||
from homeassistant.const import CONF_TOKEN
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
REFRESH_TOKEN = "token123"
|
||||
SYSTEM_ID = "system_123"
|
||||
USER_ID = "12345"
|
||||
|
||||
|
||||
@pytest.fixture(name="api")
|
||||
def api_fixture(websocket):
|
||||
def api_fixture(system_v3, websocket):
|
||||
"""Define a fixture for a simplisafe-python API object."""
|
||||
return Mock(
|
||||
async_get_systems=AsyncMock(),
|
||||
async_get_systems=AsyncMock(return_value={SYSTEM_ID: system_v3}),
|
||||
refresh_token=REFRESH_TOKEN,
|
||||
user_id=USER_ID,
|
||||
websocket=websocket,
|
||||
|
@ -50,19 +53,43 @@ def config_code_fixture(hass):
|
|||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="data_latest_event", scope="session")
|
||||
def data_latest_event_fixture():
|
||||
"""Define latest event data."""
|
||||
return json.loads(load_fixture("latest_event_data.json", "simplisafe"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_sensor", scope="session")
|
||||
def data_sensor_fixture():
|
||||
"""Define sensor data."""
|
||||
return json.loads(load_fixture("sensor_data.json", "simplisafe"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_settings", scope="session")
|
||||
def data_settings_fixture():
|
||||
"""Define settings data."""
|
||||
return json.loads(load_fixture("settings_data.json", "simplisafe"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_subscription", scope="session")
|
||||
def data_subscription_fixture():
|
||||
"""Define subscription data."""
|
||||
return json.loads(load_fixture("subscription_data.json", "simplisafe"))
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_simplisafe")
|
||||
async def setup_simplisafe_fixture(hass, api, config):
|
||||
"""Define a fixture to set up SimpliSafe."""
|
||||
with patch(
|
||||
"homeassistant.components.simplisafe.config_flow.API.async_from_auth",
|
||||
return_value=api,
|
||||
), patch(
|
||||
"homeassistant.components.simplisafe.API.async_from_auth", return_value=api
|
||||
), patch(
|
||||
"homeassistant.components.simplisafe.API.async_from_refresh_token",
|
||||
return_value=api,
|
||||
), patch(
|
||||
"homeassistant.components.simplisafe.SimpliSafe.async_init"
|
||||
), patch(
|
||||
"homeassistant.components.simplisafe.config_flow.API.async_from_auth",
|
||||
return_value=api,
|
||||
"homeassistant.components.simplisafe.SimpliSafe._async_start_websocket_loop"
|
||||
), patch(
|
||||
"homeassistant.components.simplisafe.PLATFORMS", []
|
||||
):
|
||||
|
@ -71,6 +98,17 @@ async def setup_simplisafe_fixture(hass, api, config):
|
|||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="system_v3")
|
||||
def system_v3_fixture(data_latest_event, data_sensor, data_settings, data_subscription):
|
||||
"""Define a fixture for a simplisafe-python V3 System object."""
|
||||
system = SystemV3(Mock(subscription_data=data_subscription), SYSTEM_ID)
|
||||
system.async_get_latest_event = AsyncMock(return_value=data_latest_event)
|
||||
system.sensor_data = data_sensor
|
||||
system.settings_data = data_settings
|
||||
system.generate_device_objects()
|
||||
return system
|
||||
|
||||
|
||||
@pytest.fixture(name="websocket")
|
||||
def websocket_fixture():
|
||||
"""Define a fixture for a simplisafe-python websocket object."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue