mirror of
https://github.com/cyberjunky/home-assistant-garmin_connect.git
synced 2026-01-08 04:23:56 -05:00
Add a sensor to retreive HRV status when available
This commit is contained in:
@@ -112,6 +112,8 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
activity_types = {}
|
||||
sleep_data = {}
|
||||
sleep_score = None
|
||||
hrv_data = {}
|
||||
hrvStatus = None
|
||||
|
||||
try:
|
||||
summary = await self.hass.async_add_executor_job(
|
||||
@@ -147,6 +149,10 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
sleep_data = await self.hass.async_add_executor_job(
|
||||
self._api.get_sleep_data, date.today().isoformat())
|
||||
_LOGGER.debug(f"Sleep data: {sleep_data}")
|
||||
|
||||
hrv_data = await self.hass.async_add_executor_job(
|
||||
self._api.get_hrv_data, date.today().isoformat())
|
||||
_LOGGER.debug(f"hrv data: {hrv_data}")
|
||||
except (
|
||||
GarminConnectAuthenticationError,
|
||||
GarminConnectTooManyRequestsError,
|
||||
@@ -185,6 +191,12 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
except KeyError:
|
||||
_LOGGER.debug("Sleep score data is not available")
|
||||
|
||||
try:
|
||||
hrvStatus = hrv_data["hrvSummary"]
|
||||
_LOGGER.debug(f"HRV status: {hrvStatus} ")
|
||||
except KeyError:
|
||||
_LOGGER.debug("HRV data is not available")
|
||||
|
||||
return {
|
||||
**summary,
|
||||
**body["totalAverage"],
|
||||
@@ -194,6 +206,7 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
"activity_types": activity_types,
|
||||
"gear_defaults": gear_defaults,
|
||||
"sleepScore": sleep_score,
|
||||
"hrvStatus": hrvStatus,
|
||||
}
|
||||
|
||||
async def set_active_gear(self, entity, service_data):
|
||||
|
||||
@@ -408,8 +408,15 @@ GARMIN_ENTITY_LIST = {
|
||||
SensorStateClass.TOTAL,
|
||||
SensorStateClass.MEASUREMENT,
|
||||
True,
|
||||
]
|
||||
|
||||
],
|
||||
"hrvStatus": [
|
||||
"HRV Status",
|
||||
None,
|
||||
"mdi:heart-pulse",
|
||||
None,
|
||||
None,
|
||||
True,
|
||||
],
|
||||
}
|
||||
|
||||
GEAR_ICONS = {
|
||||
|
||||
@@ -172,6 +172,9 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity):
|
||||
if self._type == "badges":
|
||||
return len(self.coordinator.data[self._type])
|
||||
|
||||
if self._type == "hrvStatus":
|
||||
return self.coordinator.data[self._type]["status"]
|
||||
|
||||
if not self.coordinator.data or not self.coordinator.data[self._type]:
|
||||
return None
|
||||
|
||||
@@ -223,6 +226,10 @@ class GarminConnectSensor(CoordinatorEntity, SensorEntity):
|
||||
self.coordinator.data[self._type]
|
||||
)
|
||||
|
||||
if self._type == "hrvStatus":
|
||||
attributes = {**attributes, **self.coordinator.data[self._type]}
|
||||
del attributes["status"]
|
||||
|
||||
return attributes
|
||||
|
||||
@property
|
||||
@@ -377,4 +384,4 @@ class GarminConnectGearSensor(CoordinatorEntity, SensorEntity):
|
||||
lambda d: d[GEAR.UUID] == self.uuid and d["defaultGear"] is True,
|
||||
self.coordinator.data["gear_defaults"],
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user