generated from ludeeus/integration_blueprint
-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
446cd20
commit 5c9156d
Showing
1 changed file
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,48 @@ | ||
"""Diagnostic helpers.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import CONF_DEVICE_ID | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import ( | ||
device_registry as dr, | ||
) | ||
from homeassistant.helpers import ( | ||
entity_registry as er, | ||
) | ||
|
||
from .common import get_device_model_id | ||
from .const import CONF_SOURCE_ENTITY_ID | ||
|
||
|
||
async def async_get_config_entry_diagnostics( | ||
entry: ConfigEntry, | ||
) -> dict: | ||
hass: HomeAssistant, config_entry: ConfigEntry | ||
) -> dict[str, Any]: | ||
"""Return diagnostics for a config entry.""" | ||
return { | ||
"entry": entry.as_dict(), | ||
} | ||
|
||
device_id = config_entry.data.get(CONF_DEVICE_ID, None) | ||
source_entity_id = config_entry.data.get(CONF_SOURCE_ENTITY_ID, None) | ||
|
||
device_registry = dr.async_get(hass) | ||
entity_registry = er.async_get(hass) | ||
|
||
if source_entity_id: | ||
entity = entity_registry.async_get(source_entity_id) | ||
device_id = entity.device_id | ||
|
||
device_entry = device_registry.async_get(device_id) | ||
|
||
diagnostics = {"entry": config_entry.as_dict()} | ||
if device_entry: | ||
device_info = { | ||
"manufacturer": device_entry.manufacturer, | ||
"model": device_entry.model, | ||
"model_id": get_device_model_id(device_entry), | ||
"hw_version": device_entry.hw_version, | ||
} | ||
diagnostics.update({"device": device_info}) | ||
|
||
return diagnostics |