Skip to content

Commit

Permalink
Merge pull request #6 from helto4real/ludeeus_fix
Browse files Browse the repository at this point in the history
Ludeeus fix
  • Loading branch information
helto4real authored Aug 14, 2020
2 parents 4ad0005 + 46770d4 commit 6b0c173
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
19 changes: 12 additions & 7 deletions custom_components/my_fitnesspal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
password = config_entry.data.get(CONF_PASSWORD)
display_name = config_entry.data.get(CONF_NAME)

# Lib does I/O in the init...
def wrap_client():
"""Wrap the fitnesspal client."""
return ext_myfitnesspal.Client(username, password)

client = await hass.async_add_executor_job(wrap_client)

coordinator = MyFitnessPalDataUpdateCoordinator(
hass, username=username, password=password, display_name=display_name
hass, client=client, display_name=display_name
)
await coordinator.async_refresh()

Expand Down Expand Up @@ -93,18 +100,16 @@ class MyFitnessPalDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching data from the API."""

def __init__(
self, hass: HomeAssistant, username: str, password: str, display_name: str
self, hass: HomeAssistant, client: ext_myfitnesspal.Client, display_name: str
):
"""Initialize."""

self._username = username
self._password = password
self.client = client
self.display_name = display_name

if len(self.display_name) == 0:
self.display_name = self._username

self._client = ext_myfitnesspal.Client(self._username, self._password)
self.platforms = []

super().__init__(
Expand All @@ -124,9 +129,9 @@ def update_data_sync(self) -> Dict[str, str]:

today = date.today()

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

weights = self._client.get_measurements("Weight")
weights = self.client.get_measurements("Weight")

goal_calories = info.goals.get("calories", 0)
goal_carbohydrates = info.goals.get("carbohydrates", 0)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/my_fitnesspal/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title": "Enter Name and credentials",
"data": {
"name": "Name",
"user_name": "User name",
"username": "User name",
"password": "Password"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title": "Enter Name and credentials",
"data": {
"name": "Name",
"user_name": "User name",
"username": "User name",
"password": "Password"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title": "Skriv namn och kontouppgifter",
"data": {
"name": "Namn",
"user_name": "Användarnamn",
"username": "Användarnamn",
"password": "Lösenord"
}
}
Expand Down

0 comments on commit 6b0c173

Please sign in to comment.