From d0a9d0ccb8604d8ef0b0db784ea53cd90de19667 Mon Sep 17 00:00:00 2001 From: David Radcliffe Date: Wed, 12 Jun 2024 21:34:36 -0400 Subject: [PATCH] add diagnostics --- .../intellicenter/diagnostics.py | 32 +++++++++++++++++++ .../intellicenter/pyintellicenter/model.py | 5 +++ 2 files changed, 37 insertions(+) create mode 100644 custom_components/intellicenter/diagnostics.py diff --git a/custom_components/intellicenter/diagnostics.py b/custom_components/intellicenter/diagnostics.py new file mode 100644 index 0000000..ee01070 --- /dev/null +++ b/custom_components/intellicenter/diagnostics.py @@ -0,0 +1,32 @@ +"""Diagnostics support for Intellicenter.""" + +from __future__ import annotations + +from typing import Any + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from .const import DOMAIN +from .pyintellicenter import ModelController + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + controller: ModelController = hass.data[DOMAIN][entry.entry_id].controller + + objects = [ + { + "objnam": obj.objnam, + "objtype": obj.objtype, + "subtype": obj.subtype, + "properties": obj.properties, + } + for obj in controller.model.objectList + ] + + return { + "objects": objects + } diff --git a/custom_components/intellicenter/pyintellicenter/model.py b/custom_components/intellicenter/pyintellicenter/model.py index 950d49b..daa0ffa 100644 --- a/custom_components/intellicenter/pyintellicenter/model.py +++ b/custom_components/intellicenter/pyintellicenter/model.py @@ -115,6 +115,11 @@ def attributes(self) -> list: """Return the list of attributes for this object.""" return list(self._properties.keys()) + @property + def properties(self) -> dict: + """Return the properties of the object.""" + return self._properties + def update(self, updates): """Update the object from a set of key/value pairs, return the changed attributes."""