From 1602fdfc30173ab0df435c5915fbeb624e4b2d99 Mon Sep 17 00:00:00 2001 From: Rene Lange Date: Fri, 29 Nov 2024 10:13:46 +0100 Subject: [PATCH] correct handling of attributes dictionary --- .../homeassistant_edupage.py | 2 +- .../homeassistantedupage/sensor.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/custom_components/homeassistantedupage/homeassistant_edupage.py b/custom_components/homeassistantedupage/homeassistant_edupage.py index dfb7766..e90bafa 100644 --- a/custom_components/homeassistantedupage/homeassistant_edupage.py +++ b/custom_components/homeassistantedupage/homeassistant_edupage.py @@ -73,7 +73,7 @@ async def get_notifications(self): try: all_notifications = await self.hass.async_add_executor_job(self.api.get_notifications) - _LOGGER.info(f"EDUPAGE Notifications found %s", all_notifications) + _LOGGER.debug(f"EDUPAGE Notifications found %s", all_notifications) return all_notifications except Exception as e: raise UpdateFailed(F"EDUPAGE error updating get_notifications() data from API: {e}") diff --git a/custom_components/homeassistantedupage/sensor.py b/custom_components/homeassistantedupage/sensor.py index a377438..5bab9ec 100644 --- a/custom_components/homeassistantedupage/sensor.py +++ b/custom_components/homeassistantedupage/sensor.py @@ -88,8 +88,13 @@ def extra_state_attributes(self): if not self._grades: return {"info": "no grades yet"} - attributes = {"student": self._student_name} - attributes = {"unique_id": self._unique_id} + attributes = {} + + attributes = { + "student": self.coordinator.data.get("student", {}), + "unique_id": self._unique_id + } + for i, grade in enumerate(self._grades): attributes[f"grade_{i+1}_title"] = grade.title attributes[f"grade_{i+1}_grade_n"] = grade.grade_n @@ -132,8 +137,12 @@ def state(self): def extra_state_attributes(self): """Return additional attributes.""" - attributes = {"student": self._student_name} - attributes = {"unique_id": self._unique_id} + attributes = {} + + attributes = { + "student": self.coordinator.data.get("student", {}), + "unique_id": self._unique_id + } for i, event in enumerate(self._notifications): if event.event_type == EventType.HOMEWORK: