Move imports in fitbit component (#27820)

This commit is contained in:
Quentame 2019-10-18 02:14:53 +02:00 committed by Paulus Schoutsen
parent fe036ed094
commit 0965e358ea

View file

@ -4,6 +4,9 @@ import logging
import datetime import datetime
import time import time
from fitbit import Fitbit
from fitbit.api import FitbitOauth2Client
from oauthlib.oauth2.rfc6749.errors import MismatchingStateError, MissingTokenError
import voluptuous as vol import voluptuous as vol
from homeassistant.core import callback from homeassistant.core import callback
@ -234,13 +237,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if "fitbit" in _CONFIGURING: if "fitbit" in _CONFIGURING:
hass.components.configurator.request_done(_CONFIGURING.pop("fitbit")) hass.components.configurator.request_done(_CONFIGURING.pop("fitbit"))
import fitbit
access_token = config_file.get(ATTR_ACCESS_TOKEN) access_token = config_file.get(ATTR_ACCESS_TOKEN)
refresh_token = config_file.get(ATTR_REFRESH_TOKEN) refresh_token = config_file.get(ATTR_REFRESH_TOKEN)
expires_at = config_file.get(ATTR_LAST_SAVED_AT) expires_at = config_file.get(ATTR_LAST_SAVED_AT)
if None not in (access_token, refresh_token): if None not in (access_token, refresh_token):
authd_client = fitbit.Fitbit( authd_client = Fitbit(
config_file.get(ATTR_CLIENT_ID), config_file.get(ATTR_CLIENT_ID),
config_file.get(ATTR_CLIENT_SECRET), config_file.get(ATTR_CLIENT_SECRET),
access_token=access_token, access_token=access_token,
@ -294,7 +295,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(dev, True) add_entities(dev, True)
else: else:
oauth = fitbit.api.FitbitOauth2Client( oauth = FitbitOauth2Client(
config_file.get(ATTR_CLIENT_ID), config_file.get(ATTR_CLIENT_SECRET) config_file.get(ATTR_CLIENT_ID), config_file.get(ATTR_CLIENT_SECRET)
) )
@ -337,9 +338,6 @@ class FitbitAuthCallbackView(HomeAssistantView):
@callback @callback
def get(self, request): def get(self, request):
"""Finish OAuth callback request.""" """Finish OAuth callback request."""
from oauthlib.oauth2.rfc6749.errors import MismatchingStateError
from oauthlib.oauth2.rfc6749.errors import MissingTokenError
hass = request.app["hass"] hass = request.app["hass"]
data = request.query data = request.query