Pull sleepscore from Garmin interface

This commit is contained in:
Jean-François Paris
2023-06-23 23:34:24 +01:00
parent 17fa2bcc63
commit e9fba7abbe
2 changed files with 17 additions and 1 deletions

View File

@@ -133,6 +133,8 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
gear_defaults = await self.hass.async_add_executor_job(
self._api.get_gear_defaults, summary[GEAR.USERPROFILE_ID]
)
sleep_data = await self.hass.async_add_executor_job(
self._api.get_sleep_data, date.today().isoformat())
except (
GarminConnectAuthenticationError,
@@ -144,6 +146,11 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
raise UpdateFailed(error) from error
return {}
sleep_score = None
try:
sleep_score = sleep_data["dailySleepDTO"]["sleepScores"]["overall"]["value"]
except KeyError:
_LOGGER.debug("sleepScore was absent")
summary['lastActivities'] = activities
return {
@@ -154,6 +161,7 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
"gear_stats": gear_stats,
"activity_types": activity_types,
"gear_defaults": gear_defaults,
"sleepScore": sleep_score,
}
async def set_active_gear(self, entity, service_data):

View File

@@ -401,7 +401,15 @@ GARMIN_ENTITY_LIST = {
"visceralFat": ["Visceral Fat", PERCENTAGE, "mdi:food", None, SensorStateClass.TOTAL, False],
"metabolicAge": ["Metabolic Age", TIME_YEARS, "mdi:calendar-heart", None, SensorStateClass.TOTAL, False],
"nextAlarm": ["Next Alarm Time", None, "mdi:alarm", SensorDeviceClass.TIMESTAMP, None, True],
"lastActivities": ["Last Activities", None, "mdi:numeric", SensorStateClass.TOTAL, None, False]
"lastActivities": ["Last Activities", None, "mdi:numeric", SensorStateClass.TOTAL, None, False],
"sleepScore": [
"Sleeep Score",
None,
"mdi:sleep",
SensorStateClass.TOTAL,
SensorStateClass.MEASUREMENT,
True,
]
}