Skip to content

Commit

Permalink
Introduces ability to add blood pressure
Browse files Browse the repository at this point in the history
Provides the ability to set a blood pressure data

Fixes: cyberjunky#167

Signed-off-by: Marcelo Moreira de Mello <[email protected]>
  • Loading branch information
tchellomello committed Oct 17, 2023
1 parent ee04db9 commit 30fc226
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions garminconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def __init__(self, email=None, password=None, is_cn=False):
self.garmin_connect_blood_pressure_endpoint = (
"/bloodpressure-service/bloodpressure/range"
)

self.garmin_connect_set_blood_pressure_endpoint = (
"/bloodpressure-service/bloodpressure"
)

self.garmin_connect_endurance_score_url = (
"/metrics-service/metrics/endurancescore"
)
Expand Down Expand Up @@ -355,6 +360,32 @@ def get_body_battery(

return self.connectapi(url, params=params)

def set_blood_pressure(
self, systolic: int, diastolic: int, pulse:int,
timestamp: str = "", notes: str = ""
):
"""
Add blood pressure measurement
"""

url = f"{self.garmin_connect_set_blood_pressure_endpoint}"
dt = datetime.fromisoformat(timestamp) if timestamp else datetime.now()
# Apply timezone offset to get UTC/GMT time
dtGMT = dt - dt.astimezone().tzinfo.utcoffset(dt)
payload = {
"measurementTimestampLocal": dt.isoformat()[:22] + ".00",
"measurementTimestampGMT": dtGMT.isoformat()[:22] + ".00",
"systolic": systolic,
"diastolic": diastolic,
"pulse": pulse,
"sourceType": "MANUAL",
"notes": notes
}

logger.debug("Adding blood pressure")

return self.garth.post("connectapi", url, json=payload)

def get_blood_pressure(
self, startdate: str, enddate=None
) -> Dict[str, Any]:
Expand Down

0 comments on commit 30fc226

Please sign in to comment.