Extend Overkiz diagnostics and implement device diagnostics (#68859)

pull/68814/head^2
Mick Vleeshouwer 2022-03-30 01:07:34 -07:00 committed by GitHub
parent 2be8b07af9
commit 7613784367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 6 deletions

View File

@ -1,21 +1,59 @@
"""Provides diagnostics for Overkiz."""
from __future__ import annotations
from typing import Any, cast
from typing import Any
from pyoverkiz.obfuscate import obfuscate_id
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntry
from . import HomeAssistantOverkizData
from .const import DOMAIN
from .const import CONF_HUB, DOMAIN
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
client = data.coordinator.client
setup = await client.get_diagnostic_data()
entry_data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
client = entry_data.coordinator.client
return cast(dict, setup)
data = {
"setup": await client.get_diagnostic_data(),
"server": entry.data[CONF_HUB],
"execution_history": [
repr(execution) for execution in await client.get_execution_history()
],
}
return data
async def async_get_device_diagnostics(
hass: HomeAssistant, entry: ConfigEntry, device: DeviceEntry
) -> dict[str, Any]:
"""Return diagnostics for a device entry."""
entry_data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
client = entry_data.coordinator.client
device_url = min(device.identifiers)[1]
data = {
"device": {
"controllable_name": device.hw_version,
"firmware": device.sw_version,
"device_url": obfuscate_id(device_url),
"model": device.model,
},
"setup": await client.get_diagnostic_data(),
"server": entry.data[CONF_HUB],
"execution_history": [
repr(execution)
for execution in await client.get_execution_history()
if any(command.device_url == device_url for command in execution.commands)
],
}
return data