Skip to content

Commit

Permalink
Merge branch 'master' into feat/upload-body-composition
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunky authored Oct 28, 2023
2 parents 3b401d5 + 20b862b commit d6d688d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
10 changes: 8 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"J": "Get race predictions",
"K": f"Get all day stress data for '{today.isoformat()}'",
"L": f"Add body composition for '{today.isoformat()}'",
"M": "Set blood pressure '120,80,80,notes='Testing with example.py'",
"Z": "Remove stored login tokens (logout)",
"q": "Exit",
}
Expand Down Expand Up @@ -632,7 +633,7 @@ def switch(api, i):
api.get_all_day_stress(today.isoformat())
)
elif i == "L":
# Get all day stress data for date
# Add body composition
weight = 70.0
percent_fat = 15.4
percent_hydration = 54.8
Expand Down Expand Up @@ -661,7 +662,12 @@ def switch(api, i):
metabolic_age=metabolic_age,
visceral_fat_rating=visceral_fat_rating,
bmi=bmi,
),
)
elif i == "M":
# Set blood pressure values
display_json(
f"api.set_blood_pressure(120,80,80,notes=`Testing with example.py`)",
api.set_blood_pressure(120,80,80,notes="Testing with example.py")
)
elif i == "Z":
# Remove stored login tokens for Garmin Connect portal
Expand Down
38 changes: 36 additions & 2 deletions garminconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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 @@ -400,6 +405,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 Expand Up @@ -889,8 +920,11 @@ def set_gear_default(self, activityType, gearUUID, defaultGear=True):
f"{self.garmin_connect_gear_baseurl}{gearUUID}/"
f"activityType/{activityType}{defaultGearString}"
)
return self.garth.post(
"connectapi", url, {"x-http-method-override": method_override}
return self.garth.request(
method_override,
"connectapi",
url,
api=True
)

class ActivityDownloadFormat(Enum):
Expand Down
2 changes: 1 addition & 1 deletion garminconnect/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.8"
__version__ = "0.2.9"

0 comments on commit d6d688d

Please sign in to comment.