From 94e1416e5d62cfc72892ab776014413708a8232d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Franc=CC=A7ois=20Paris?= Date: Wed, 14 May 2025 23:51:57 +0100 Subject: [PATCH] Added the endurance score as an optional entity --- custom_components/garmin_connect/__init__.py | 9 +++++++++ custom_components/garmin_connect/const.py | 8 ++++++++ custom_components/garmin_connect/sensor.py | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/custom_components/garmin_connect/__init__.py b/custom_components/garmin_connect/__init__.py index fd9f034..da0a261 100644 --- a/custom_components/garmin_connect/__init__.py +++ b/custom_components/garmin_connect/__init__.py @@ -114,6 +114,7 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator): sleep_time_seconds = None hrv_data = {} hrv_status = {"status": "unknown"} + endurance_data = {} next_alarms = [] today = datetime.now(ZoneInfo(self.time_zone)).date() @@ -181,6 +182,13 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator): self.api.get_hrv_data, today.isoformat() ) _LOGGER.debug("HRV data fetched: %s", hrv_data) + + # Endurance data + endurance_data = await self.hass.async_add_executor_job( + self.api.get_endurance_score, today.isoformat() + ) + _LOGGER.debug("Endurance data fetched: %s", endurance_data) + except ( GarminConnectAuthenticationError, GarminConnectTooManyRequestsError, @@ -254,6 +262,7 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator): "sleepScore": sleep_score, "sleepTimeSeconds": sleep_time_seconds, "hrvStatus": hrv_status, + "enduranceScore": endurance_data, } diff --git a/custom_components/garmin_connect/const.py b/custom_components/garmin_connect/const.py index 36efc82..b4c6458 100644 --- a/custom_components/garmin_connect/const.py +++ b/custom_components/garmin_connect/const.py @@ -657,6 +657,14 @@ GARMIN_ENTITY_LIST = { None, True, ], + "enduranceScore": [ + "Endurance Score", + None, + "mdi:run", + None, + SensorStateClass.MEASUREMENT, + False, + ], } GEAR_ICONS = { diff --git a/custom_components/garmin_connect/sensor.py b/custom_components/garmin_connect/sensor.py index 203b1ba..05e2af7 100644 --- a/custom_components/garmin_connect/sensor.py +++ b/custom_components/garmin_connect/sensor.py @@ -204,6 +204,9 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity): elif self._type == "hrvStatus": value = self.coordinator.data[self._type]["status"].capitalize() + elif self._type == "enduranceScore": + value = self.coordinator.data[self._type]["overallScore"] + elif "Duration" in self._type or "Seconds" in self._type: value = round(value // 60, 2) @@ -261,6 +264,10 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity): attributes = {**attributes, **self.coordinator.data[self._type]} del attributes["status"] + if self._type == "enduranceScore": + attributes = {**attributes, **self.coordinator.data[self._type]} + del attributes["overallScore"] + return attributes @property