helto4real / custom_component_myfitnesspal

Custom component in Home Assistant for getting fitness datat from MyFitnessPal
MIT License
13 stars 13 forks source link

Weight returns 0 #14

Closed dkvdm closed 2 years ago

dkvdm commented 2 years ago

Hey there,

I was about to implement my own custom component when I came across yours! Great work Question: weight is currently returning 0, do you know why this would be the case? See screenshot. Thank you!

Screen Shot 2022-01-31 at 4 13 48 PM

dkvdm commented 2 years ago

Fixed it with the following change in __init__.py around line 135:

latest_record = weights.popitem(last=False) # grab first item
latest_weight = latest_record[1] # grab weight from record

additionally, I've added the following extra attributes, which you might find handy:

result["cal_remaining"] = goal_calories - total_calories # calories remaining for the day
result["cal_remaining_ex_workout"] = goal_calories - total_calories - cardio_calories_burned # calories remaining without exercise added for padding
result["cal_goal"] = goal_calories - cardio_calories_burned # calorie goal without exercise added

As an overall status, I want to graph my weight over time, so I've adjusted the sensor to output my weight instead of the % towards calorie goal for the day, which I found less useful as it resets every day:

sensor.py around line 64

return self.coordinator.data.get("weight") # return weight instead of pct

Anyway, I hope these suggestions help, thank you for the hard work you put into this component!

helto4real commented 2 years ago

Thanks for the tip. Will fix this within a few days.

dkvdm commented 2 years ago

No problem, glad to help! Thank you for your swift response.

I want to make it clear that I'm not telling you what to do, as this is your custom component and I can keep a fork if needed; it would be helpful to move the main sensor output of calorie goal % to an attribute instead, and use the sensor output for weight instead, so this can be graphed over time :)

dkvdm commented 2 years ago

To make it more convenient for you, I've created a PR here: https://github.com/helto4real/custom_component_myfitnesspal/pull/15

dkvdm commented 2 years ago

Just unforked and switched back to master and updated without any issues, thank you for accepting this PR!