Skip to content

Commit

Permalink
Merge pull request #18 from helto4real/fix-error
Browse files Browse the repository at this point in the history
Fix check for missing weight
  • Loading branch information
helto4real authored Mar 4, 2022
2 parents d3b3065 + 6e5de3f commit 1027d41
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions custom_components/my_fitnesspal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,14 @@ def update_data_sync(self) -> Dict[str, str]:
"""Get the actual data from the API"""

today = date.today()
latest_weight = 0

info = self.client.get_date(today.year, today.month, today.day)

weights = self.client.get_measurements("Weight")
latest_record = weights.popitem(last=False)
if len(latest_record) > 1:
latest_weight = latest_record[1]
else:
latest_weight = 0
if len(weights) > 0:
latest_record = weights.popitem(last=False)
if len(latest_record) > 1:
latest_weight = latest_record[1]

goal_calories = info.goals.get("calories", 0)
goal_carbohydrates = info.goals.get("carbohydrates", 0)
Expand Down

0 comments on commit 1027d41

Please sign in to comment.