mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Add diagnostics to Home Assistant Connect ZBT-1 (#189158)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
eff9e9f160
commit
63fcf3924e
@@ -0,0 +1,61 @@
|
||||
"""Diagnostics support for the Home Assistant SkyConnect integration."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.homeassistant_hardware.helpers import (
|
||||
async_is_firmware_update_in_progress,
|
||||
)
|
||||
from homeassistant.components.homeassistant_hardware.util import (
|
||||
OwningAddon,
|
||||
OwningIntegration,
|
||||
guess_hardware_owners,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import HomeAssistantSkyConnectConfigEntry
|
||||
from .const import DEVICE, FIRMWARE, FIRMWARE_VERSION, MANUFACTURER, PID, PRODUCT, VID
|
||||
|
||||
|
||||
def _owner_as_dict(
|
||||
hass: HomeAssistant, owner: OwningAddon | OwningIntegration
|
||||
) -> dict[str, Any]:
|
||||
"""Describe a firmware owner without exposing identifiers."""
|
||||
if isinstance(owner, OwningAddon):
|
||||
return {"addon": owner.slug}
|
||||
entry = hass.config_entries.async_get_entry(owner.config_entry_id)
|
||||
return {"integration": entry.domain if entry else None}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: HomeAssistantSkyConnectConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
device = entry.data[DEVICE]
|
||||
coordinator = entry.runtime_data.coordinator
|
||||
owners = await guess_hardware_owners(hass, device)
|
||||
|
||||
return {
|
||||
"hardware": {
|
||||
"manufacturer": entry.data[MANUFACTURER],
|
||||
"product": entry.data[PRODUCT],
|
||||
"vid": entry.data[VID],
|
||||
"pid": entry.data[PID],
|
||||
},
|
||||
"firmware": {
|
||||
"type": entry.data[FIRMWARE],
|
||||
"version": entry.data[FIRMWARE_VERSION],
|
||||
"update_in_progress": async_is_firmware_update_in_progress(hass, device),
|
||||
},
|
||||
"firmware_owners": [
|
||||
{
|
||||
"source": info.source,
|
||||
"firmware_type": info.firmware_type,
|
||||
"firmware_version": info.firmware_version,
|
||||
"owners": [_owner_as_dict(hass, owner) for owner in info.owners],
|
||||
}
|
||||
for info in owners
|
||||
],
|
||||
"firmware_update_coordinator": {
|
||||
"last_update_success": coordinator.last_update_success,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics_for_config_entry
|
||||
dict({
|
||||
'firmware': dict({
|
||||
'type': 'ezsp',
|
||||
'update_in_progress': False,
|
||||
'version': '7.4.4.0 build 0',
|
||||
}),
|
||||
'firmware_owners': list([
|
||||
dict({
|
||||
'firmware_type': 'ezsp',
|
||||
'firmware_version': '7.4.4.0 build 0',
|
||||
'owners': list([
|
||||
dict({
|
||||
'integration': 'zha',
|
||||
}),
|
||||
]),
|
||||
'source': 'zha',
|
||||
}),
|
||||
dict({
|
||||
'firmware_type': 'ezsp',
|
||||
'firmware_version': None,
|
||||
'owners': list([
|
||||
dict({
|
||||
'addon': 'core_zigbee2mqtt',
|
||||
}),
|
||||
]),
|
||||
'source': 'zigbee2mqtt (core_zigbee2mqtt)',
|
||||
}),
|
||||
]),
|
||||
'firmware_update_coordinator': dict({
|
||||
'last_update_success': True,
|
||||
}),
|
||||
'hardware': dict({
|
||||
'manufacturer': 'Nabu Casa',
|
||||
'pid': 'EA60',
|
||||
'product': 'Home Assistant Connect ZBT-1',
|
||||
'vid': '10C4',
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,77 @@
|
||||
"""Tests for the Home Assistant SkyConnect diagnostics data."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from pytest_homeassistant.common import MockConfigEntry
|
||||
from pytest_homeassistant.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.homeassistant_hardware.util import (
|
||||
ApplicationType,
|
||||
FirmwareInfo,
|
||||
OwningAddon,
|
||||
OwningIntegration,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import USB_DATA_ZBT1
|
||||
|
||||
|
||||
async def test_diagnostics_for_config_entry(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics for config entry."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
|
||||
zha_config_entry = MockConfigEntry(domain="zha")
|
||||
zha_config_entry.add_to_hass(hass)
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain="homeassistant_sky_connect",
|
||||
unique_id=USB_DATA_ZBT1.serial_number,
|
||||
data={
|
||||
"firmware": "ezsp",
|
||||
"firmware_version": "7.4.4.0 build 0",
|
||||
"device": USB_DATA_ZBT1.device,
|
||||
"manufacturer": USB_DATA_ZBT1.manufacturer,
|
||||
"pid": USB_DATA_ZBT1.pid,
|
||||
"product": USB_DATA_ZBT1.description,
|
||||
"serial_number": USB_DATA_ZBT1.serial_number,
|
||||
"vid": USB_DATA_ZBT1.vid,
|
||||
},
|
||||
version=1,
|
||||
minor_version=5,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.homeassistant_sky_connect.diagnostics.guess_hardware_owners",
|
||||
return_value=[
|
||||
FirmwareInfo(
|
||||
device=USB_DATA_ZBT1.device,
|
||||
firmware_type=ApplicationType.EZSP,
|
||||
firmware_version="7.4.4.0 build 0",
|
||||
source="zha",
|
||||
owners=[OwningIntegration(config_entry_id=zha_config_entry.entry_id)],
|
||||
),
|
||||
FirmwareInfo(
|
||||
device=USB_DATA_ZBT1.device,
|
||||
firmware_type=ApplicationType.EZSP,
|
||||
firmware_version=None,
|
||||
source="zigbee2mqtt (core_zigbee2mqtt)",
|
||||
owners=[OwningAddon(slug="core_zigbee2mqtt")],
|
||||
),
|
||||
],
|
||||
):
|
||||
diagnostics_data = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry
|
||||
)
|
||||
|
||||
assert diagnostics_data == snapshot
|
||||
Reference in New Issue
Block a user