Add Nut commands to diagnostics data (#96285)
* Add Nut commands to diagnostics data * Add test for diagnostics
This commit is contained in:
parent
4edec69637
commit
ce3c23cb3a
2 changed files with 50 additions and 2 deletions
|
@ -12,7 +12,7 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from . import PyNUTData
|
||||
from .const import DOMAIN, PYNUT_DATA, PYNUT_UNIQUE_ID
|
||||
from .const import DOMAIN, PYNUT_DATA, PYNUT_UNIQUE_ID, USER_AVAILABLE_COMMANDS
|
||||
|
||||
TO_REDACT = {CONF_PASSWORD, CONF_USERNAME}
|
||||
|
||||
|
@ -26,7 +26,12 @@ async def async_get_config_entry_diagnostics(
|
|||
|
||||
# Get information from Nut library
|
||||
nut_data: PyNUTData = hass_data[PYNUT_DATA]
|
||||
data["nut_data"] = {"ups_list": nut_data.ups_list, "status": nut_data.status}
|
||||
nut_cmd: set[str] = hass_data[USER_AVAILABLE_COMMANDS]
|
||||
data["nut_data"] = {
|
||||
"ups_list": nut_data.ups_list,
|
||||
"status": nut_data.status,
|
||||
"commands": nut_cmd,
|
||||
}
|
||||
|
||||
# Gather information how this Nut device is represented in Home Assistant
|
||||
device_registry = dr.async_get(hass)
|
||||
|
|
43
tests/components/nut/test_diagnostics.py
Normal file
43
tests/components/nut/test_diagnostics.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
"""Tests for the diagnostics data provided by the Nut integration."""
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.components.nut.diagnostics import TO_REDACT
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .util import async_init_integration
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
list_commands: set[str] = ["beeper.enable"]
|
||||
list_commands_return_value = {
|
||||
supported_command: supported_command for supported_command in list_commands
|
||||
}
|
||||
|
||||
mock_config_entry = await async_init_integration(
|
||||
hass,
|
||||
username="someuser",
|
||||
password="somepassword",
|
||||
list_vars={"ups.status": "OL"},
|
||||
list_ups={"ups1": "UPS 1"},
|
||||
list_commands_return_value=list_commands_return_value,
|
||||
)
|
||||
|
||||
entry_dict = async_redact_data(mock_config_entry.as_dict(), TO_REDACT)
|
||||
nut_data_dict = {
|
||||
"ups_list": {"ups1": "UPS 1"},
|
||||
"status": {"ups.status": "OL"},
|
||||
"commands": list_commands,
|
||||
}
|
||||
|
||||
result = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
assert result["entry"] == entry_dict
|
||||
assert result["nut_data"] == nut_data_dict
|
Loading…
Add table
Reference in a new issue