mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Add diagnostics to Elexa Guardian (#64599)
This commit is contained in:
parent
fec669f9c8
commit
6bbe38578c
51
homeassistant/components/guardian/diagnostics.py
Normal file
51
homeassistant/components/guardian/diagnostics.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""Diagnostics support for Guardian."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONF_UID, DATA_COORDINATOR, DATA_COORDINATOR_PAIRED_SENSOR, DOMAIN
|
||||
from .util import GuardianDataUpdateCoordinator
|
||||
|
||||
CONF_BSSID = "bssid"
|
||||
CONF_PAIRED_UIDS = "paired_uids"
|
||||
CONF_SSID = "ssid"
|
||||
|
||||
TO_REDACT = {
|
||||
CONF_BSSID,
|
||||
CONF_PAIRED_UIDS,
|
||||
CONF_SSID,
|
||||
CONF_UID,
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
data = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
coordinators: dict[str, GuardianDataUpdateCoordinator] = data[DATA_COORDINATOR]
|
||||
paired_sensor_coordinators: dict[str, GuardianDataUpdateCoordinator] = data[
|
||||
DATA_COORDINATOR_PAIRED_SENSOR
|
||||
]
|
||||
|
||||
return {
|
||||
"entry": {
|
||||
"title": entry.title,
|
||||
"data": async_redact_data(entry.data, TO_REDACT),
|
||||
},
|
||||
"data": {
|
||||
"valve_controller": {
|
||||
api_category: async_redact_data(coordinator.data, TO_REDACT)
|
||||
for api_category, coordinator in coordinators.items()
|
||||
},
|
||||
"paired_sensors": [
|
||||
async_redact_data(coordinator.data, TO_REDACT)
|
||||
for coordinator in paired_sensor_coordinators.values()
|
||||
],
|
||||
},
|
||||
}
|
@ -4,7 +4,7 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.guardian.const import DOMAIN
|
||||
from homeassistant.components.guardian import CONF_UID, DOMAIN
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@ -14,7 +14,11 @@ from tests.common import MockConfigEntry, load_fixture
|
||||
@pytest.fixture(name="config_entry")
|
||||
def config_entry_fixture(hass, config, unique_id):
|
||||
"""Define a config entry fixture."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id=unique_id, data=config)
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=unique_id,
|
||||
data={CONF_UID: "3456", **config},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
return entry
|
||||
|
||||
@ -28,19 +32,97 @@ def config_fixture(hass):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="data_ping", scope="session")
|
||||
def data_ping_fixture():
|
||||
"""Define data from a successful ping response."""
|
||||
return json.loads(load_fixture("ping_data.json", "guardian"))
|
||||
@pytest.fixture(name="data_sensor_pair_dump", scope="session")
|
||||
def data_sensor_pair_dump_fixture():
|
||||
"""Define data from a successful sensor_pair_dump response."""
|
||||
return json.loads(load_fixture("sensor_pair_dump_data.json", "guardian"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_sensor_pair_sensor", scope="session")
|
||||
def data_sensor_pair_sensor_fixture():
|
||||
"""Define data from a successful sensor_pair_sensor response."""
|
||||
return json.loads(load_fixture("sensor_pair_sensor_data.json", "guardian"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_sensor_paired_sensor_status", scope="session")
|
||||
def data_sensor_paired_sensor_status_fixture():
|
||||
"""Define data from a successful sensor_paired_sensor_status response."""
|
||||
return json.loads(load_fixture("sensor_paired_sensor_status_data.json", "guardian"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_system_diagnostics", scope="session")
|
||||
def data_system_diagnostics_fixture():
|
||||
"""Define data from a successful system_diagnostics response."""
|
||||
return json.loads(load_fixture("system_diagnostics_data.json", "guardian"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_system_onboard_sensor_status", scope="session")
|
||||
def data_system_onboard_sensor_status_fixture():
|
||||
"""Define data from a successful system_onboard_sensor_status response."""
|
||||
return json.loads(
|
||||
load_fixture("system_onboard_sensor_status_data.json", "guardian")
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(name="data_system_ping", scope="session")
|
||||
def data_system_ping_fixture():
|
||||
"""Define data from a successful system_ping response."""
|
||||
return json.loads(load_fixture("system_ping_data.json", "guardian"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_valve_status", scope="session")
|
||||
def data_valve_status_fixture():
|
||||
"""Define data from a successful valve_status response."""
|
||||
return json.loads(load_fixture("valve_status_data.json", "guardian"))
|
||||
|
||||
|
||||
@pytest.fixture(name="data_wifi_status", scope="session")
|
||||
def data_wifi_status_fixture():
|
||||
"""Define data from a successful wifi_status response."""
|
||||
return json.loads(load_fixture("wifi_status_data.json", "guardian"))
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_guardian")
|
||||
async def setup_guardian_fixture(hass, config, data_ping):
|
||||
async def setup_guardian_fixture(
|
||||
hass,
|
||||
config,
|
||||
data_sensor_pair_dump,
|
||||
data_sensor_pair_sensor,
|
||||
data_sensor_paired_sensor_status,
|
||||
data_system_diagnostics,
|
||||
data_system_onboard_sensor_status,
|
||||
data_system_ping,
|
||||
data_valve_status,
|
||||
data_wifi_status,
|
||||
):
|
||||
"""Define a fixture to set up Guardian."""
|
||||
with patch("aioguardian.client.Client.connect"), patch(
|
||||
"aioguardian.commands.sensor.SensorCommands.pair_dump",
|
||||
return_value=data_sensor_pair_dump,
|
||||
), patch(
|
||||
"aioguardian.commands.sensor.SensorCommands.pair_sensor",
|
||||
return_value=data_sensor_pair_sensor,
|
||||
), patch(
|
||||
"aioguardian.commands.sensor.SensorCommands.paired_sensor_status",
|
||||
return_value=data_sensor_paired_sensor_status,
|
||||
), patch(
|
||||
"aioguardian.commands.system.SystemCommands.diagnostics",
|
||||
return_value=data_system_diagnostics,
|
||||
), patch(
|
||||
"aioguardian.commands.system.SystemCommands.onboard_sensor_status",
|
||||
return_value=data_system_onboard_sensor_status,
|
||||
), patch(
|
||||
"aioguardian.commands.system.SystemCommands.ping",
|
||||
return_value=data_ping,
|
||||
), patch("aioguardian.client.Client.disconnect"), patch(
|
||||
return_value=data_system_ping,
|
||||
), patch(
|
||||
"aioguardian.commands.valve.ValveCommands.status",
|
||||
return_value=data_valve_status,
|
||||
), patch(
|
||||
"aioguardian.commands.wifi.WiFiCommands.status",
|
||||
return_value=data_wifi_status,
|
||||
), patch(
|
||||
"aioguardian.client.Client.disconnect"
|
||||
), patch(
|
||||
"homeassistant.components.guardian.PLATFORMS", []
|
||||
):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"command": 48,
|
||||
"status": "ok",
|
||||
"data": {
|
||||
"pair_count": 1,
|
||||
"paired_uids": [
|
||||
"6309FB799CDE"
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"command": 49,
|
||||
"status": "ok"
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"command": 51,
|
||||
"status": "ok",
|
||||
"silent": true,
|
||||
"data": {
|
||||
"uid": "AABBCCDDEEFF",
|
||||
"codename": "gld1",
|
||||
"temperature": 68,
|
||||
"wet": false,
|
||||
"moved": true,
|
||||
"battery_percentage": 79
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"command": 1,
|
||||
"status": "ok",
|
||||
"data": {
|
||||
"codename": "gvc1",
|
||||
"uid": "ABCDEF123456",
|
||||
"uptime": 41,
|
||||
"firmware": "0.20.9-beta+official.ef3",
|
||||
"rf_modem_firmware": "4.0.0",
|
||||
"available_heap": 34456
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"command": 80,
|
||||
"status": "ok",
|
||||
"data": {
|
||||
"temperature": 71,
|
||||
"wet": false
|
||||
}
|
||||
}
|
13
tests/components/guardian/fixtures/valve_status_data.json
Normal file
13
tests/components/guardian/fixtures/valve_status_data.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"command": 16,
|
||||
"status": "ok",
|
||||
"data": {
|
||||
"enabled": false,
|
||||
"direction": true,
|
||||
"state": 0,
|
||||
"travel_count": 0,
|
||||
"instantaneous_current": 0,
|
||||
"instantaneous_current_ddt": 0,
|
||||
"average_current": 34
|
||||
}
|
||||
}
|
17
tests/components/guardian/fixtures/wifi_status_data.json
Normal file
17
tests/components/guardian/fixtures/wifi_status_data.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"command": 32,
|
||||
"status": "ok",
|
||||
"data": {
|
||||
"station_connected": true,
|
||||
"ip_assigned": true,
|
||||
"mqtt_connected": true,
|
||||
"rssi": -63,
|
||||
"channel": 1,
|
||||
"lan_ipv4": "192.168.1.100",
|
||||
"lan_ipv6": "AC10:BD0:FFFF:FFFF:AC10:BD0:FFFF:FFFF",
|
||||
"ap_enabled": true,
|
||||
"ap_clients": 0,
|
||||
"bssid": "ABCDEF123456",
|
||||
"ssid": "My_Network"
|
||||
}
|
||||
}
|
76
tests/components/guardian/test_diagnostics.py
Normal file
76
tests/components/guardian/test_diagnostics.py
Normal file
@ -0,0 +1,76 @@
|
||||
"""Test Guardian diagnostics."""
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
from homeassistant.components.guardian import (
|
||||
DATA_PAIRED_SENSOR_MANAGER,
|
||||
DOMAIN,
|
||||
PairedSensorManager,
|
||||
)
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
|
||||
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_guardian):
|
||||
"""Test config entry diagnostics."""
|
||||
paired_sensor_manager: PairedSensorManager = hass.data[DOMAIN][
|
||||
config_entry.entry_id
|
||||
][DATA_PAIRED_SENSOR_MANAGER]
|
||||
|
||||
# Simulate the pairing of a paired sensor:
|
||||
await paired_sensor_manager.async_pair_sensor("AABBCCDDEEFF")
|
||||
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||
"entry": {
|
||||
"title": "Mock Title",
|
||||
"data": {
|
||||
"ip_address": "192.168.1.100",
|
||||
"port": 7777,
|
||||
"uid": REDACTED,
|
||||
},
|
||||
},
|
||||
"data": {
|
||||
"valve_controller": {
|
||||
"sensor_pair_dump": {"pair_count": 1, "paired_uids": REDACTED},
|
||||
"system_diagnostics": {
|
||||
"codename": "gvc1",
|
||||
"uid": REDACTED,
|
||||
"uptime": 41,
|
||||
"firmware": "0.20.9-beta+official.ef3",
|
||||
"rf_modem_firmware": "4.0.0",
|
||||
"available_heap": 34456,
|
||||
},
|
||||
"system_onboard_sensor_status": {"temperature": 71, "wet": False},
|
||||
"valve_status": {
|
||||
"enabled": False,
|
||||
"direction": True,
|
||||
"state": 0,
|
||||
"travel_count": 0,
|
||||
"instantaneous_current": 0,
|
||||
"instantaneous_current_ddt": 0,
|
||||
"average_current": 34,
|
||||
},
|
||||
"wifi_status": {
|
||||
"station_connected": True,
|
||||
"ip_assigned": True,
|
||||
"mqtt_connected": True,
|
||||
"rssi": -63,
|
||||
"channel": 1,
|
||||
"lan_ipv4": "192.168.1.100",
|
||||
"lan_ipv6": "AC10:BD0:FFFF:FFFF:AC10:BD0:FFFF:FFFF",
|
||||
"ap_enabled": True,
|
||||
"ap_clients": 0,
|
||||
"bssid": REDACTED,
|
||||
"ssid": REDACTED,
|
||||
},
|
||||
},
|
||||
"paired_sensors": [
|
||||
{
|
||||
"uid": REDACTED,
|
||||
"codename": "gld1",
|
||||
"temperature": 68,
|
||||
"wet": False,
|
||||
"moved": True,
|
||||
"battery_percentage": 79,
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user