mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add diagnostics to devolo Home Network (#86022)
This commit is contained in:
parent
8e7e210693
commit
cb36905ce5
38
homeassistant/components/devolo_home_network/diagnostics.py
Normal file
38
homeassistant/components/devolo_home_network/diagnostics.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"""Diagnostics support for devolo Home Network."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from devolo_plc_api import Device
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_PASSWORD
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
TO_REDACT = {CONF_PASSWORD}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
device: Device = hass.data[DOMAIN][entry.entry_id]["device"]
|
||||||
|
|
||||||
|
diag_data = {
|
||||||
|
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
||||||
|
"device_info": {
|
||||||
|
"mt_number": device.mt_number,
|
||||||
|
"product": device.product,
|
||||||
|
"firmware": device.firmware_version,
|
||||||
|
"device_api": device.device is not None,
|
||||||
|
"plcnet_api": device.plcnet is not None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if device.device:
|
||||||
|
diag_data["device_info"]["features"] = device.device.features
|
||||||
|
|
||||||
|
return diag_data
|
@ -12,7 +12,7 @@ def configure_integration(hass: HomeAssistant) -> MockConfigEntry:
|
|||||||
"""Configure the integration."""
|
"""Configure the integration."""
|
||||||
config = {
|
config = {
|
||||||
CONF_IP_ADDRESS: IP,
|
CONF_IP_ADDRESS: IP,
|
||||||
CONF_PASSWORD: "",
|
CONF_PASSWORD: "test",
|
||||||
}
|
}
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=config)
|
entry = MockConfigEntry(domain=DOMAIN, data=config)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
@ -32,11 +32,17 @@ class MockDevice(Device):
|
|||||||
super().__init__(ip, zeroconf_instance)
|
super().__init__(ip, zeroconf_instance)
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def firmware_version(self) -> str:
|
||||||
|
"""Mock firmware version currently installed."""
|
||||||
|
return DISCOVERY_INFO.properties["FirmwareVersion"]
|
||||||
|
|
||||||
async def async_connect(
|
async def async_connect(
|
||||||
self, session_instance: httpx.AsyncClient | None = None
|
self, session_instance: httpx.AsyncClient | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Give a mocked device the needed properties."""
|
"""Give a mocked device the needed properties."""
|
||||||
self.mac = DISCOVERY_INFO.properties["PlcMacAddress"]
|
self.mac = DISCOVERY_INFO.properties["PlcMacAddress"]
|
||||||
|
self.mt_number = DISCOVERY_INFO.properties["MT"]
|
||||||
self.product = DISCOVERY_INFO.properties["Product"]
|
self.product = DISCOVERY_INFO.properties["Product"]
|
||||||
self.serial_number = DISCOVERY_INFO.properties["SN"]
|
self.serial_number = DISCOVERY_INFO.properties["SN"]
|
||||||
|
|
||||||
|
45
tests/components/devolo_home_network/test_diagnostics.py
Normal file
45
tests/components/devolo_home_network/test_diagnostics.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
"""Tests for the devolo Home Network diagnostics."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from aiohttp import ClientSession
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.devolo_home_network.diagnostics import TO_REDACT
|
||||||
|
from homeassistant.components.diagnostics import REDACTED
|
||||||
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import configure_integration
|
||||||
|
from .const import DISCOVERY_INFO
|
||||||
|
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_device")
|
||||||
|
async def test_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSession,
|
||||||
|
):
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
entry = configure_integration(hass)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert entry.state == ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
entry_dict = entry.as_dict()
|
||||||
|
for key in TO_REDACT:
|
||||||
|
entry_dict["data"][key] = REDACTED
|
||||||
|
|
||||||
|
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||||
|
assert result == {
|
||||||
|
"entry": entry_dict,
|
||||||
|
"device_info": {
|
||||||
|
"mt_number": DISCOVERY_INFO.properties["MT"],
|
||||||
|
"product": DISCOVERY_INFO.properties["Product"],
|
||||||
|
"firmware": DISCOVERY_INFO.properties["FirmwareVersion"],
|
||||||
|
"device_api": True,
|
||||||
|
"plcnet_api": True,
|
||||||
|
"features": DISCOVERY_INFO.properties["Features"].split(","),
|
||||||
|
},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user