Skip to content

Commit

Permalink
Add redacted subscription data to SimpliSafe diagnostics (#65751)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Feb 5, 2022
1 parent b9b53be commit 3387e83
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
1 change: 1 addition & 0 deletions homeassistant/components/simplisafe/__init__.py
Expand Up @@ -449,6 +449,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, api: API) -> None:
self._websocket_reconnect_task: asyncio.Task | None = None
self.entry = entry
self.initial_event_to_use: dict[int, dict[str, Any]] = {}
self.subscription_data: dict[int, Any] = api.subscription_data
self.systems: dict[int, SystemType] = {}

# This will get filled in by async_init:
Expand Down
15 changes: 15 additions & 0 deletions homeassistant/components/simplisafe/diagnostics.py
Expand Up @@ -11,14 +11,28 @@
from . import SimpliSafe
from .const import DOMAIN

CONF_CREDIT_CARD = "creditCard"
CONF_EXPIRES = "expires"
CONF_LOCATION = "location"
CONF_LOCATION_NAME = "locationName"
CONF_PAYMENT_PROFILE_ID = "paymentProfileId"
CONF_SERIAL = "serial"
CONF_SID = "sid"
CONF_SYSTEM_ID = "system_id"
CONF_UID = "uid"
CONF_WIFI_SSID = "wifi_ssid"

TO_REDACT = {
CONF_ADDRESS,
CONF_CREDIT_CARD,
CONF_EXPIRES,
CONF_LOCATION,
CONF_LOCATION_NAME,
CONF_PAYMENT_PROFILE_ID,
CONF_SERIAL,
CONF_SID,
CONF_SYSTEM_ID,
CONF_UID,
CONF_WIFI_SSID,
}

Expand All @@ -34,6 +48,7 @@ async def async_get_config_entry_diagnostics(
"entry": {
"options": dict(entry.options),
},
"subscription_data": simplisafe.subscription_data,
"systems": [system.as_dict() for system in simplisafe.systems.values()],
},
TO_REDACT,
Expand Down
3 changes: 2 additions & 1 deletion tests/components/simplisafe/conftest.py
Expand Up @@ -18,11 +18,12 @@


@pytest.fixture(name="api")
def api_fixture(system_v3, websocket):
def api_fixture(data_subscription, system_v3, websocket):
"""Define a fixture for a simplisafe-python API object."""
return Mock(
async_get_systems=AsyncMock(return_value={SYSTEM_ID: system_v3}),
refresh_token=REFRESH_TOKEN,
subscription_data=data_subscription,
user_id=USER_ID,
websocket=websocket,
)
Expand Down
93 changes: 91 additions & 2 deletions tests/components/simplisafe/test_diagnostics.py
Expand Up @@ -7,7 +7,96 @@
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_simplisafe):
"""Test config entry diagnostics."""
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"entry": {"options": {}},
"entry": {
"options": {},
},
"subscription_data": {
"system_123": {
"uid": REDACTED,
"sid": REDACTED,
"sStatus": 20,
"activated": 1445034752,
"planSku": "SSEDSM2",
"planName": "Interactive Monitoring",
"price": 24.99,
"currency": "USD",
"country": "US",
"expires": REDACTED,
"canceled": 0,
"extraTime": 0,
"creditCard": REDACTED,
"time": 2628000,
"paymentProfileId": REDACTED,
"features": {
"monitoring": True,
"alerts": True,
"online": True,
"hazard": True,
"video": True,
"cameras": 10,
"dispatch": True,
"proInstall": False,
"discount": 0,
"vipCS": False,
"medical": True,
"careVisit": False,
"storageDays": 30,
},
"status": {
"hasBaseStation": True,
"isActive": True,
"monitoring": "Active",
},
"subscriptionFeatures": {
"monitoredSensorsTypes": [
"Entry",
"Motion",
"GlassBreak",
"Smoke",
"CO",
"Freeze",
"Water",
],
"monitoredPanicConditions": ["Fire", "Medical", "Duress"],
"dispatchTypes": ["Police", "Fire", "Medical", "Guard"],
"remoteControl": [
"ArmDisarm",
"LockUnlock",
"ViewSettings",
"ConfigureSettings",
],
"cameraFeatures": {
"liveView": True,
"maxRecordingCameras": 10,
"recordingStorageDays": 30,
"videoVerification": True,
},
"support": {
"level": "Basic",
"annualVisit": False,
"professionalInstall": False,
},
"cellCommunicationBackup": True,
"alertChannels": ["Push", "SMS", "Email"],
"alertTypes": ["Alarm", "Error", "Activity", "Camera"],
"alarmModes": ["Alarm", "SecretAlert", "Disabled"],
"supportedIntegrations": [
"GoogleAssistant",
"AmazonAlexa",
"AugustLock",
],
"timeline": {},
},
"dispatcher": "cops",
"dcid": 0,
"location": REDACTED,
"pinUnlocked": True,
"billDate": 1602887552,
"billInterval": 2628000,
"pinUnlockedBy": "pin",
"autoActivation": None,
}
},
"systems": [
{
"address": REDACTED,
Expand Down Expand Up @@ -183,7 +272,7 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_simplisa
"shutter_open_when_off": False,
"status": "online",
"subscription_enabled": True,
},
}
],
"chime_volume": 2,
"entry_delay_away": 30,
Expand Down

0 comments on commit 3387e83

Please sign in to comment.