From bd567dc0b2fb1832ecec0e67706f8a2f66a590d1 Mon Sep 17 00:00:00 2001 From: Lukas Hermans Date: Tue, 7 Jan 2025 19:52:13 +0100 Subject: [PATCH] Add total sleep duration --- README.md | 1 + custom_components/garmin_connect/__init__.py | 8 ++++++++ custom_components/garmin_connect/const.py | 1 + 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index e6ba6b7..f14a879 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Sedentary Time Sleeping Time Awake Duration Sleep Duration +Total Sleep Duration Floors Ascended Floors Descended Floors Ascended Goal diff --git a/custom_components/garmin_connect/__init__.py b/custom_components/garmin_connect/__init__.py index abea225..c9ed314 100644 --- a/custom_components/garmin_connect/__init__.py +++ b/custom_components/garmin_connect/__init__.py @@ -111,6 +111,7 @@ async def _async_update_data(self) -> dict: activity_types = {} sleep_data = {} sleep_score = None + sleep_time_seconds = None hrv_data = {} hrvStatus = {"status": "UNKNOWN"} @@ -190,6 +191,12 @@ async def _async_update_data(self) -> dict: except KeyError: _LOGGER.debug("Sleep score data is not available") + try: + sleep_time_seconds = sleep_data["dailySleepDTO"]["sleepTimeSeconds"] + _LOGGER.debug(f"Sleep time seconds data: {sleep_time_seconds}") + except KeyError: + _LOGGER.debug("Sleep time seconds data is not available") + try: if hrv_data and "hrvSummary" in hrv_data: hrvStatus = hrv_data["hrvSummary"] @@ -206,6 +213,7 @@ async def _async_update_data(self) -> dict: "activity_types": activity_types, "gear_defaults": gear_defaults, "sleepScore": sleep_score, + "sleepTimeSeconds": sleep_time_seconds, "hrvStatus": hrvStatus, } diff --git a/custom_components/garmin_connect/const.py b/custom_components/garmin_connect/const.py index db90940..7f01b97 100644 --- a/custom_components/garmin_connect/const.py +++ b/custom_components/garmin_connect/const.py @@ -409,6 +409,7 @@ SensorStateClass.MEASUREMENT, True, ], + "sleepTimeSeconds": ["Total Sleep Duration", UnitOfTime.MINUTES, "mdi:sleep", None, SensorStateClass.TOTAL, True], "hrvStatus": [ "HRV Status", None,