From c00af14ee2c63b9d9c545568f9312aaf7be0827b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 11 Jan 2020 18:22:08 -0800 Subject: [PATCH] Ring OTP improvement (#30688) * Fix otp flow * Update Ring to 0.5 Co-authored-by: steve-gombos <3118886+steve-gombos@users.noreply.github.com> --- homeassistant/components/ring/config_flow.py | 12 ++++-------- homeassistant/components/ring/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/ring/config_flow.py b/homeassistant/components/ring/config_flow.py index 98555277baf2..6d177a4db495 100644 --- a/homeassistant/components/ring/config_flow.py +++ b/homeassistant/components/ring/config_flow.py @@ -1,7 +1,7 @@ """Config flow for Ring integration.""" import logging -from oauthlib.oauth2 import AccessDeniedError +from oauthlib.oauth2 import AccessDeniedError, MissingTokenError from ring_doorbell import Auth import voluptuous as vol @@ -15,18 +15,14 @@ _LOGGER = logging.getLogger(__name__) async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect.""" - def otp_callback(): - if "2fa" in data: - return data["2fa"] - - raise Require2FA - auth = Auth() try: token = await hass.async_add_executor_job( - auth.fetch_token, data["username"], data["password"], otp_callback, + auth.fetch_token, data["username"], data["password"], data.get("2fa"), ) + except MissingTokenError: + raise Require2FA except AccessDeniedError: raise InvalidAuth diff --git a/homeassistant/components/ring/manifest.json b/homeassistant/components/ring/manifest.json index d6570fad5cbc..fccbf9a5319e 100644 --- a/homeassistant/components/ring/manifest.json +++ b/homeassistant/components/ring/manifest.json @@ -2,7 +2,7 @@ "domain": "ring", "name": "Ring", "documentation": "https://www.home-assistant.io/integrations/ring", - "requirements": ["ring_doorbell==0.4.0"], + "requirements": ["ring_doorbell==0.5.0"], "dependencies": ["ffmpeg"], "codeowners": [], "config_flow": true diff --git a/requirements_all.txt b/requirements_all.txt index 253014c211a9..35dceaf2a9cc 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1753,7 +1753,7 @@ rfk101py==0.0.1 rflink==0.0.50 # homeassistant.components.ring -ring_doorbell==0.4.0 +ring_doorbell==0.5.0 # homeassistant.components.fleetgo ritassist==0.9.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 13a73e4c1b35..eb48440be141 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -567,7 +567,7 @@ restrictedpython==5.0 rflink==0.0.50 # homeassistant.components.ring -ring_doorbell==0.4.0 +ring_doorbell==0.5.0 # homeassistant.components.yamaha rxv==0.6.0