-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from PeteRager/diagnostics
add support for ha diagnostic report
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Diagnostics support for Nest.""" | ||
# pylint: disable=line-too-long | ||
from __future__ import annotations | ||
from typing import Any | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD | ||
|
||
from . import MANAGER, Manager | ||
from .const import LENNOX_DOMAIN | ||
|
||
|
||
async def async_get_config_entry_diagnostics(hass: HomeAssistant, config_entry: ConfigEntry) -> dict[str, Any]: | ||
"""Return diagnostics for a config entry.""" | ||
manager: Manager = hass.data[LENNOX_DOMAIN][config_entry.unique_id][MANAGER] | ||
data: dict[str, Any] = {} | ||
|
||
data["config"] = {} | ||
for key, val in config_entry.data.items(): | ||
data["config"][key] = val | ||
if CONF_PASSWORD in data["config"]: | ||
data["config"][CONF_PASSWORD] = "**redacted**" | ||
if CONF_EMAIL in data["config"]: | ||
data["config"][CONF_EMAIL] = "**redacted**" | ||
data["system"] = {} | ||
for system in manager.api.system_list: | ||
system_data: dict[str, any] = { | ||
"relayServer": system.relayServerConnected, | ||
"internet": system.internetStatus, | ||
"diagLevel": system.diagLevel, | ||
"cloud_status": system.cloud_status, | ||
"productType": system.productType, | ||
"sibling_identifier": system.sibling_identifier, | ||
"sibling_ip": system.sibling_ipAddress, | ||
"softwareVersion": system.softwareVersion, | ||
"sysUpTime": system.sysUpTime, | ||
} | ||
|
||
system_data["equipment"] = {} | ||
for eq_id, equipment in system.equipment.items(): | ||
element = { | ||
"name": equipment.equipment_name, | ||
"eqType": equipment.equipType, | ||
"eqTypeName": equipment.equipment_type_name, | ||
"model": equipment.unit_model_number, | ||
} | ||
system_data["equipment"][eq_id] = element | ||
data["system"][system.sysId] = system_data | ||
|
||
data["comm_metrics"] = manager.getMetricsList() | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Test the diagnostics""" | ||
# pylint: disable=line-too-long | ||
import pytest | ||
|
||
from custom_components.lennoxs30 import Manager | ||
from custom_components.lennoxs30.const import MANAGER | ||
from custom_components.lennoxs30.diagnostics import async_get_config_entry_diagnostics | ||
from homeassistant import config_entries | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_diagnostics_local( | ||
hass, manager_system_04_furn_ac_zoning_ble: Manager, config_entry_local: config_entries.ConfigEntry | ||
): | ||
"""Test the alert sensor""" | ||
manager = manager_system_04_furn_ac_zoning_ble | ||
entry = manager.config_entry = config_entry_local | ||
hass.data["lennoxs30"] = {} | ||
hass.data["lennoxs30"][entry.unique_id] = {MANAGER: manager} | ||
diags = await async_get_config_entry_diagnostics(hass, entry) | ||
|
||
assert "config" in diags | ||
assert diags["config"]["host"] == "10.0.0.1" | ||
assert "system" in diags | ||
assert "0000000-0000-0000-0000-000000000001" in diags["system"] | ||
system = diags["system"]["0000000-0000-0000-0000-000000000001"] | ||
assert len(system["equipment"]) == 4 | ||
assert "comm_metrics" in diags | ||
assert diags["comm_metrics"]["message_count"] == 6 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_diagnostics_cloud( | ||
hass, manager_system_04_furn_ac_zoning_ble: Manager, config_entry_cloud: config_entries.ConfigEntry | ||
): | ||
"""Test the alert sensor""" | ||
manager = manager_system_04_furn_ac_zoning_ble | ||
entry = manager.config_entry = config_entry_cloud | ||
hass.data["lennoxs30"] = {} | ||
hass.data["lennoxs30"][entry.unique_id] = {MANAGER: manager} | ||
diags = await async_get_config_entry_diagnostics(hass, entry) | ||
|
||
assert "config" in diags | ||
assert diags["config"]["password"] == "**redacted**" | ||
assert diags["config"]["email"] == "**redacted**" | ||
assert "system" in diags | ||
assert "0000000-0000-0000-0000-000000000001" in diags["system"] | ||
system = diags["system"]["0000000-0000-0000-0000-000000000001"] | ||
assert len(system["equipment"]) == 4 | ||
assert "comm_metrics" in diags | ||
assert diags["comm_metrics"]["message_count"] == 6 |