Add support for Automatic OAuth2 authentication (#8962)

* Add support for Automatic OAuth2 authentication

* Fix async conversion of configurator

* Rename method for async

* Use hass.components to get configurator component

* Fix typo

* Move session data to hidden directory

* Make configurator callback optional
This commit is contained in:
Adam Mills authored and Paulus Schoutsen committed 2017-08-13 22:37:50 -07:00
1 parent 8fcec03adf
commit 19d1d748d4
25 files changed
+314 -149

No files matched your search

+7 -7
View File
@@ -17,7 +17,6 @@ from homeassistant.components.http import HomeAssistantView
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.helpers.entity import Entity
from homeassistant.loader import get_component
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['fitbit==0.2.3']
@@ -155,7 +154,7 @@ def config_from_file(filename, config=None):
def request_app_setup(hass, config, add_devices, config_path,
discovery_info=None):
"""Assist user with configuring the Fitbit dev application."""
configurator = get_component('configurator')
configurator = hass.components.configurator
# pylint: disable=unused-argument
def fitbit_configuration_callback(callback_data):
@@ -166,7 +165,8 @@ def request_app_setup(hass, config, add_devices, config_path,
if config_file == DEFAULT_CONFIG:
error_msg = ("You didn't correctly modify fitbit.conf",
" please try again")
configurator.notify_errors(_CONFIGURING['fitbit'], error_msg)
configurator.notify_errors(_CONFIGURING['fitbit'],
error_msg)
else:
setup_platform(hass, config, add_devices, discovery_info)
else:
@@ -187,7 +187,7 @@ def request_app_setup(hass, config, add_devices, config_path,
submit = "I have saved my Client ID and Client Secret into fitbit.conf."
_CONFIGURING['fitbit'] = configurator.request_config(
hass, 'Fitbit', fitbit_configuration_callback,
'Fitbit', fitbit_configuration_callback,
description=description, submit_caption=submit,
description_image="/static/images/config_fitbit_app.png"
)
@@ -195,7 +195,7 @@ def request_app_setup(hass, config, add_devices, config_path,
def request_oauth_completion(hass):
"""Request user complete Fitbit OAuth2 flow."""
configurator = get_component('configurator')
configurator = hass.components.configurator
if "fitbit" in _CONFIGURING:
configurator.notify_errors(
_CONFIGURING['fitbit'], "Failed to register, please try again.")
@@ -211,7 +211,7 @@ def request_oauth_completion(hass):
description = "Please authorize Fitbit by visiting {}".format(start_url)
_CONFIGURING['fitbit'] = configurator.request_config(
hass, 'Fitbit', fitbit_configuration_callback,
'Fitbit', fitbit_configuration_callback,
description=description,
submit_caption="I have authorized Fitbit."
)
@@ -233,7 +233,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
return False
if "fitbit" in _CONFIGURING:
get_component('configurator').request_done(_CONFIGURING.pop("fitbit"))
hass.components.configurator.request_done(_CONFIGURING.pop("fitbit"))
import fitbit
+1 -3
View File
@@ -18,7 +18,6 @@ from homeassistant.const import (
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
from homeassistant.loader import get_component
REQUIREMENTS = ['https://github.com/jamespcole/home-assistant-nzb-clients/'
'archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip'
@@ -88,7 +87,7 @@ def setup_sabnzbd(base_url, apikey, name, hass, config, add_devices, sab_api):
def request_configuration(host, name, hass, config, add_devices, sab_api):
"""Request configuration steps from the user."""
configurator = get_component('configurator')
configurator = hass.components.configurator
# We got an error if this method is called while we are configuring
if host in _CONFIGURING:
configurator.notify_errors(_CONFIGURING[host],
@@ -114,7 +113,6 @@ def request_configuration(host, name, hass, config, add_devices, sab_api):
hass.async_add_job(success)
_CONFIGURING[host] = configurator.request_config(
hass,
DEFAULT_NAME,
sabnzbd_configuration_callback,
description=('Enter the API Key'),