-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diagnostics to LaMetric (#79757)
* Add diagnostics to LaMetric * Add return value typing Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
- Loading branch information
1 parent
5694a4b
commit 633ffad
Showing
2 changed files
with
86 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,29 @@ | ||
"""Diagnostics support for LaMetric.""" | ||
from __future__ import annotations | ||
|
||
import json | ||
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 DOMAIN | ||
from .coordinator import LaMetricDataUpdateCoordinator | ||
|
||
TO_REDACT = { | ||
"device_id", | ||
"name", | ||
"serial_number", | ||
"ssid", | ||
} | ||
|
||
|
||
async def async_get_config_entry_diagnostics( | ||
hass: HomeAssistant, entry: ConfigEntry | ||
) -> dict[str, Any]: | ||
"""Return diagnostics for a config entry.""" | ||
coordinator: LaMetricDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] | ||
# Round-trip via JSON to trigger serialization | ||
data = json.loads(coordinator.data.json()) | ||
return async_redact_data(data, TO_REDACT) |
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,57 @@ | ||
"""Tests for the diagnostics data provided by the LaMetric integration.""" | ||
from aiohttp import ClientSession | ||
|
||
from homeassistant.components.diagnostics import REDACTED | ||
from homeassistant.core import HomeAssistant | ||
|
||
from tests.common import MockConfigEntry | ||
from tests.components.diagnostics import get_diagnostics_for_config_entry | ||
|
||
|
||
async def test_diagnostics( | ||
hass: HomeAssistant, | ||
hass_client: ClientSession, | ||
init_integration: MockConfigEntry, | ||
) -> None: | ||
"""Test diagnostics.""" | ||
assert await get_diagnostics_for_config_entry( | ||
hass, hass_client, init_integration | ||
) == { | ||
"device_id": REDACTED, | ||
"name": REDACTED, | ||
"serial_number": REDACTED, | ||
"os_version": "2.2.2", | ||
"mode": "auto", | ||
"model": "LM 37X8", | ||
"audio": { | ||
"volume": 100, | ||
"volume_range": {"range_min": 0, "range_max": 100}, | ||
"volume_limit": {"range_min": 0, "range_max": 100}, | ||
}, | ||
"bluetooth": { | ||
"available": True, | ||
"name": REDACTED, | ||
"active": False, | ||
"discoverable": True, | ||
"pairable": True, | ||
"address": "AA:BB:CC:DD:EE:FF", | ||
}, | ||
"display": { | ||
"brightness": 100, | ||
"brightness_mode": "auto", | ||
"width": 37, | ||
"height": 8, | ||
"display_type": "mixed", | ||
}, | ||
"wifi": { | ||
"active": True, | ||
"mac": "AA:BB:CC:DD:EE:FF", | ||
"available": True, | ||
"encryption": "WPA", | ||
"ssid": REDACTED, | ||
"ip": "127.0.0.1", | ||
"mode": "dhcp", | ||
"netmask": "255.255.255.0", | ||
"rssi": 21, | ||
}, | ||
} |