From 44cad7df30b7c3b803c21aeb46cd7445cc52adc1 Mon Sep 17 00:00:00 2001 From: Bertbert <7685189+bertbert72@users.noreply.github.com> Date: Wed, 28 Feb 2018 21:18:50 +0000 Subject: [PATCH] Add Unit System Option For Fitbit (#11817) * Add Unit System Option For Fitbit * Update fitbit.py * Update fitbit.py --- homeassistant/components/sensor/fitbit.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/sensor/fitbit.py b/homeassistant/components/sensor/fitbit.py index 6ea18d318b8..8d64a8d8229 100644 --- a/homeassistant/components/sensor/fitbit.py +++ b/homeassistant/components/sensor/fitbit.py @@ -15,6 +15,7 @@ from homeassistant.core import callback from homeassistant.components.http import HomeAssistantView from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ATTR_ATTRIBUTION +from homeassistant.const import CONF_UNIT_SYSTEM from homeassistant.helpers.entity import Entity from homeassistant.helpers.icon import icon_for_battery_level import homeassistant.helpers.config_validation as cv @@ -144,7 +145,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_MONITORED_RESOURCES, default=FITBIT_DEFAULT_RESOURCES): vol.All(cv.ensure_list, [vol.In(FITBIT_RESOURCES_LIST)]), vol.Optional(CONF_CLOCK_FORMAT, default='24H'): - vol.In(['12H', '24H']) + vol.In(['12H', '24H']), + vol.Optional(CONF_UNIT_SYSTEM, default='default'): + vol.In(['en_GB', 'en_US', 'metric', 'default']) }) @@ -248,12 +251,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if int(time.time()) - expires_at > 3600: authd_client.client.refresh_token() - authd_client.system = authd_client.user_profile_get()["user"]["locale"] - if authd_client.system != 'en_GB': - if hass.config.units.is_metric: - authd_client.system = 'metric' - else: - authd_client.system = 'en_US' + unit_system = config.get(CONF_UNIT_SYSTEM) + if unit_system == 'default': + authd_client.system = authd_client. \ + user_profile_get()["user"]["locale"] + if authd_client.system != 'en_GB': + if hass.config.units.is_metric: + authd_client.system = 'metric' + else: + authd_client.system = 'en_US' + else: + authd_client.system = unit_system dev = [] registered_devs = authd_client.get_devices()