mirror of
https://github.com/home-assistant/core.git
synced 2025-09-10 23:31:37 +02:00
Fix JSON serialization for ZHA diagnostics download (#150210)
This commit is contained in:
@@ -8,6 +8,7 @@ from typing import Any
|
||||
|
||||
from zha.application.const import ATTR_IEEE
|
||||
from zha.application.gateway import Gateway
|
||||
from zigpy.application import ControllerApplication
|
||||
from zigpy.config import CONF_NWK_EXTENDED_PAN_ID
|
||||
from zigpy.types import Channels
|
||||
|
||||
@@ -63,6 +64,19 @@ def shallow_asdict(obj: Any) -> dict:
|
||||
return obj
|
||||
|
||||
|
||||
def get_application_state_diagnostics(app: ControllerApplication) -> dict:
|
||||
"""Dump the application state as a dictionary."""
|
||||
data = shallow_asdict(app.state)
|
||||
|
||||
# EUI64 objects in zigpy are not subclasses of any JSON-serializable key type and
|
||||
# must be converted to strings.
|
||||
data["network_info"]["nwk_addresses"] = {
|
||||
str(k): v for k, v in data["network_info"]["nwk_addresses"].items()
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
@@ -79,7 +93,7 @@ async def async_get_config_entry_diagnostics(
|
||||
{
|
||||
"config": zha_data.yaml_config,
|
||||
"config_entry": config_entry.as_dict(),
|
||||
"application_state": shallow_asdict(app.state),
|
||||
"application_state": get_application_state_diagnostics(app),
|
||||
"energy_scan": {
|
||||
channel: 100 * energy / 255 for channel, energy in energy_scan.items()
|
||||
},
|
||||
|
@@ -36,6 +36,7 @@
|
||||
}),
|
||||
'network_key': '**REDACTED**',
|
||||
'nwk_addresses': dict({
|
||||
'11:22:33:44:55:66:77:88': 4660,
|
||||
}),
|
||||
'nwk_manager_id': 0,
|
||||
'nwk_update_id': 0,
|
||||
|
@@ -6,6 +6,7 @@ import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
from zigpy.profiles import zha
|
||||
from zigpy.types import EUI64, NWK
|
||||
from zigpy.zcl.clusters import security
|
||||
|
||||
from homeassistant.components.zha.helpers import (
|
||||
@@ -71,6 +72,10 @@ async def test_diagnostics_for_config_entry(
|
||||
|
||||
gateway.application_controller.energy_scan.side_effect = None
|
||||
gateway.application_controller.energy_scan.return_value = scan
|
||||
gateway.application_controller.state.network_info.nwk_addresses = {
|
||||
EUI64.convert("11:22:33:44:55:66:77:88"): NWK(0x1234)
|
||||
}
|
||||
|
||||
diagnostics_data = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry
|
||||
)
|
||||
|
Reference in New Issue
Block a user