Perform an energy scan when downloading ZHA diagnostics (#90605)
parent
f56ccf90d9
commit
590db0fa74
|
@ -7,6 +7,7 @@ from typing import Any
|
|||
|
||||
from zigpy.config import CONF_NWK_EXTENDED_PAN_ID
|
||||
from zigpy.profiles import PROFILES
|
||||
from zigpy.types import Channels
|
||||
from zigpy.zcl import Cluster
|
||||
|
||||
from homeassistant.components.diagnostics.util import async_redact_data
|
||||
|
@ -67,11 +68,19 @@ async def async_get_config_entry_diagnostics(
|
|||
"""Return diagnostics for a config entry."""
|
||||
config: dict = hass.data[DATA_ZHA].get(DATA_ZHA_CONFIG, {})
|
||||
gateway: ZHAGateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY]
|
||||
|
||||
energy_scan = await gateway.application_controller.energy_scan(
|
||||
channels=Channels.ALL_CHANNELS, duration_exp=4, count=1
|
||||
)
|
||||
|
||||
return async_redact_data(
|
||||
{
|
||||
"config": config,
|
||||
"config_entry": config_entry.as_dict(),
|
||||
"application_state": shallow_asdict(gateway.application_controller.state),
|
||||
"energy_scan": {
|
||||
channel: 100 * energy / 255 for channel, energy in energy_scan.items()
|
||||
},
|
||||
"versions": {
|
||||
"bellows": version("bellows"),
|
||||
"zigpy": version("zigpy"),
|
||||
|
|
|
@ -6,6 +6,7 @@ import zigpy.profiles.zha as zha
|
|||
import zigpy.zcl.clusters.security as security
|
||||
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
from homeassistant.components.zha.core.const import DATA_ZHA, DATA_ZHA_GATEWAY
|
||||
from homeassistant.components.zha.core.device import ZHADevice
|
||||
from homeassistant.components.zha.diagnostics import KEYS_TO_REDACT
|
||||
from homeassistant.const import Platform
|
||||
|
@ -62,14 +63,25 @@ async def test_diagnostics_for_config_entry(
|
|||
) -> None:
|
||||
"""Test diagnostics for config entry."""
|
||||
await zha_device_joined(zigpy_device)
|
||||
diagnostics_data = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry
|
||||
)
|
||||
assert diagnostics_data
|
||||
|
||||
gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY]
|
||||
scan = {c: c for c in range(11, 26 + 1)}
|
||||
|
||||
with patch.object(gateway.application_controller, "energy_scan", return_value=scan):
|
||||
diagnostics_data = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry
|
||||
)
|
||||
|
||||
for key in CONFIG_ENTRY_DIAGNOSTICS_KEYS:
|
||||
assert key in diagnostics_data
|
||||
assert diagnostics_data[key] is not None
|
||||
|
||||
# Energy scan results are presented as a percentage. JSON object keys also must be
|
||||
# strings, not integers.
|
||||
assert diagnostics_data["energy_scan"] == {
|
||||
str(k): 100 * v / 255 for k, v in scan.items()
|
||||
}
|
||||
|
||||
|
||||
async def test_diagnostics_for_device(
|
||||
hass: HomeAssistant,
|
||||
|
|
Loading…
Reference in New Issue