From 6330d9cde6286251e63e132a82f47e14c8aacd1d Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Thu, 13 Oct 2016 12:22:05 -0400 Subject: [PATCH] Fixed Fitbit resting heart rate attribute (#3835) * Fixed Fitbit restingHeartRate field to grab the correct field from dictionary In [31]: r['activities-heart'][-1].get('value') Out[31]: {'customHeartRateZones': [], 'heartRateZones': [{'caloriesOut': 126.18348, 'max': 94, 'min': 30, 'minutes': 67, 'name': 'Out of Range'}, {'caloriesOut': 27.21339, 'max': 131, 'min': 94, 'minutes': 5, 'name': 'Fat Burn'}, {'caloriesOut': 0, 'max': 159, 'min': 131, 'minutes': 0, 'name': 'Cardio'}, {'caloriesOut': 0, 'max': 220, 'min': 159, 'minutes': 0, 'name': 'Peak'}], 'restingHeartRate': 69} In [32]: r['activities-heart'][-1].get('value').get('restingHeartRate') Out[32]: 69 * Renamed sensor to Resting Heart Rate to match it * Fixed lint style --- homeassistant/components/sensor/fitbit.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/fitbit.py b/homeassistant/components/sensor/fitbit.py index cf11c9bb393..11288bae63a 100644 --- a/homeassistant/components/sensor/fitbit.py +++ b/homeassistant/components/sensor/fitbit.py @@ -359,6 +359,8 @@ class FitbitSensor(Entity): pretty_resource = pretty_resource.title() if pretty_resource == 'Body Bmi': pretty_resource = 'BMI' + elif pretty_resource == 'Heart': + pretty_resource = 'Resting Heart Rate' self._name = pretty_resource unit_type = FITBIT_RESOURCES_LIST[self.resource_type] if unit_type == "": @@ -403,7 +405,8 @@ class FitbitSensor(Entity): response = self.client.time_series(self.resource_type, period='7d') self._state = response[container][-1].get('value') if self.resource_type == 'activities/heart': - self._state = response[container][-1].get('restingHeartRate') + self._state = response[container][-1]. \ + get('value').get('restingHeartRate') config_contents = { ATTR_ACCESS_TOKEN: self.client.client.token['access_token'], ATTR_REFRESH_TOKEN: self.client.client.token['refresh_token'],