mirror of
https://github.com/cyberjunky/home-assistant-garmin_connect.git
synced 2026-01-08 04:23:56 -05:00
Pull sleepscore from Garmin interface
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user