Add Unit System Option For Fitbit (#11817)

* Add Unit System Option For Fitbit

* Update fitbit.py

* Update fitbit.py
pull/11937/merge
Bertbert 2018-02-28 21:18:50 +00:00 committed by Paulus Schoutsen
parent bbd58d7357
commit 44cad7df30
1 changed files with 15 additions and 7 deletions

View File

@ -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"]
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()