mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Add velbus diagnostics (#65426)
This commit is contained in:
parent
2bc2f85b1b
commit
2bcc21ecbb
@ -1339,6 +1339,7 @@ omit =
|
|||||||
homeassistant/components/velbus/climate.py
|
homeassistant/components/velbus/climate.py
|
||||||
homeassistant/components/velbus/const.py
|
homeassistant/components/velbus/const.py
|
||||||
homeassistant/components/velbus/cover.py
|
homeassistant/components/velbus/cover.py
|
||||||
|
homeassistant/components/velbus/diagnostics.py
|
||||||
homeassistant/components/velbus/light.py
|
homeassistant/components/velbus/light.py
|
||||||
homeassistant/components/velbus/sensor.py
|
homeassistant/components/velbus/sensor.py
|
||||||
homeassistant/components/velbus/switch.py
|
homeassistant/components/velbus/switch.py
|
||||||
|
57
homeassistant/components/velbus/diagnostics.py
Normal file
57
homeassistant/components/velbus/diagnostics.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
"""Diagnostics support for Velbus."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from velbusaio.channels import Channel as VelbusChannel
|
||||||
|
from velbusaio.module import Module as VelbusModule
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
controller = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
||||||
|
data: dict[str, Any] = {"entry": entry.as_dict(), "modules": []}
|
||||||
|
for module in controller.get_modules().values():
|
||||||
|
data["modules"].append(_build_module_diagnostics_info(module))
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_device_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry, device: DeviceEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a device entry."""
|
||||||
|
controller = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
||||||
|
channel = list(next(iter(device.identifiers)))[1]
|
||||||
|
modules = controller.get_modules()
|
||||||
|
return _build_module_diagnostics_info(modules[int(channel)])
|
||||||
|
|
||||||
|
|
||||||
|
def _build_module_diagnostics_info(module: VelbusModule) -> dict[str, Any]:
|
||||||
|
"""Build per module diagnostics info."""
|
||||||
|
data: dict[str, Any] = {
|
||||||
|
"type": module.get_type_name(),
|
||||||
|
"address": module.get_addresses(),
|
||||||
|
"name": module.get_name(),
|
||||||
|
"sw_version": module.get_sw_version(),
|
||||||
|
"is_loaded": module.is_loaded(),
|
||||||
|
"channels": _build_channels_diagnostics_info(module.get_channels()),
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def _build_channels_diagnostics_info(
|
||||||
|
channels: dict[str, VelbusChannel]
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Build diagnostics info for all channels."""
|
||||||
|
data: dict[str, Any] = {}
|
||||||
|
for channel in channels.values():
|
||||||
|
data[str(channel.get_channel_number())] = channel.get_channel_info()
|
||||||
|
return data
|
Loading…
x
Reference in New Issue
Block a user