Merge pull request #157 from kruemelro/main

Always fetch latest data, added blood pressure service
This commit is contained in:
Ron
2024-12-17 08:46:38 +01:00
committed by GitHub
3 changed files with 66 additions and 2 deletions

View File

@@ -122,7 +122,7 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
_LOGGER.debug(f"Summary data: {summary}")
body = await self.hass.async_add_executor_job(
self._api.get_body_composition, date.today().isoformat()
self._api.get_body_composition, (date.today()-timedelta(days=7)).isoformat(), date.today().isoformat()
)
_LOGGER.debug(f"Body data: {body}")
@@ -199,7 +199,7 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
return {
**summary,
**body["totalAverage"],
**body["dateWeightList"][0],
"nextAlarm": alarms,
"gear": gear,
"gear_stats": gear_stats,
@@ -276,3 +276,19 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
service_data.data.get("visceral_fat_rating", None),
service_data.data.get("bmi", None)
)
async def add_blood_pressure(self, entity, service_data):
"""Record a blood pressure measurement"""
if not await self.async_login():
raise IntegrationError(
"Failed to login to Garmin Connect, unable to update"
)
await self.hass.async_add_executor_job(
self._api.set_blood_pressure,
service_data.data.get('systolic'),
service_data.data.get('diastolic'),
service_data.data.get('pulse'),
service_data.data.get('note', None)
)

View File

@@ -104,6 +104,10 @@ async def async_setup_entry(
"add_body_composition", BODY_COMPOSITION_SERVICE_SCHEMA, coordinator.add_body_composition
)
platform.async_register_entity_service(
"add_blood_pressure", BLOOD_PRESSURE_SERVICE_SCHEMA, coordinator.add_blood_pressure
)
ENTITY_SERVICE_SCHEMA = vol.Schema(
{
vol.Required(ATTR_ENTITY_ID): str,
@@ -131,6 +135,17 @@ BODY_COMPOSITION_SERVICE_SCHEMA = vol.Schema(
}
)
BLOOD_PRESSURE_SERVICE_SCHEMA = vol.Schema(
{
vol.Required(ATTR_ENTITY_ID): str,
vol.Required("systolic"): int,
vol.Required("diastolic"): int,
vol.Required("pulse"): int,
vol.Optional("note"): str
}
)
class GarminConnectSensor(CoordinatorEntity, SensorEntity):
"""Representation of a Garmin Connect Sensor."""

View File

@@ -114,3 +114,36 @@ add_body_composition:
entity:
integration: garmin_connect
device_class: weight
add_blood_pressure:
name: Adds updated blood pressure metrics
description: Adds updated blood pressure metrics.
fields:
entity_id:
name: entity
description: entity
required: true
selector:
entity:
integration: garmin_connect
device_class: weight
systolic:
required: true
name: Systolic
description: Systolic value
example: 120
diastolic:
required: true
name: Diastolic
description: Diastolic value
example: 80
pulse:
required: true
name: Pulse
description: Pulse
example: 60
notes:
required: false
name: Notes
description: Add a note to the measurement
example: 'Measured with Beurer BC54'