diff --git a/custom_components/alexa_media/__init__.py b/custom_components/alexa_media/__init__.py index 624e6193..6fc92dbd 100644 --- a/custom_components/alexa_media/__init__.py +++ b/custom_components/alexa_media/__init__.py @@ -49,6 +49,7 @@ CONF_DEBUG, CONF_EXCLUDE_DEVICES, CONF_INCLUDE_DEVICES, + CONF_OAUTH, CONF_OTPSECRET, CONF_QUEUE_DELAY, DATA_ALEXAMEDIA, @@ -135,6 +136,7 @@ async def async_setup(hass, config, discovery_info=None): CONF_SCAN_INTERVAL: account[ CONF_SCAN_INTERVAL ].total_seconds(), + CONF_OAUTH: account.get("CONF_OAUTH", {}), CONF_OTPSECRET: account.get(CONF_OTPSECRET, ""), }, ) @@ -154,6 +156,7 @@ async def async_setup(hass, config, discovery_info=None): CONF_INCLUDE_DEVICES: account[CONF_INCLUDE_DEVICES], CONF_EXCLUDE_DEVICES: account[CONF_EXCLUDE_DEVICES], CONF_SCAN_INTERVAL: account[CONF_SCAN_INTERVAL].total_seconds(), + CONF_OAUTH: account.get("CONF_OAUTH", {}), CONF_OTPSECRET: account.get(CONF_OTPSECRET, ""), }, ) @@ -182,12 +185,13 @@ async def relogin(event=None) -> None: ].get("login_obj") if login_obj is None: login_obj = AlexaLogin( - url, - email, - password, - hass.config.path, - account.get(CONF_DEBUG), - account.get(CONF_OTPSECRET, ""), + url=url, + email=email, + password=password, + outputpath=hass.config.path, + debug=account.get(CONF_DEBUG), + otp_secret=account.get(CONF_OTPSECRET, ""), + oauth=account.get(CONF_OAUTH, {}), ) hass.data[DATA_ALEXAMEDIA]["accounts"][email][ "login_obj" @@ -248,12 +252,13 @@ async def login_success(event=None) -> None: login: AlexaLogin = hass.data[DATA_ALEXAMEDIA]["accounts"][email].get( "login_obj", AlexaLogin( - url, - email, - password, - hass.config.path, - account.get(CONF_DEBUG), - account.get(CONF_OTPSECRET, ""), + url=url, + email=email, + password=password, + outputpath=hass.config.path, + debug=account.get(CONF_DEBUG), + otp_secret=account.get(CONF_OTPSECRET, ""), + oauth=account.get(CONF_OAUTH, {}), ), ) hass.data[DATA_ALEXAMEDIA]["accounts"][email]["login_obj"] = login @@ -475,6 +480,18 @@ async def async_update_data(): hass.data[DATA_ALEXAMEDIA]["accounts"][email]["new_devices"] = False await login_obj.save_cookiefile() + if login_obj.access_token: + hass.config_entries.async_update_entry( + config_entry, + data={ + **config_entry.data, + CONF_OAUTH: { + "access_token": login_obj.access_token, + "refresh_token": login_obj.refresh_token, + "expires_in": login_obj.expires_in, + }, + }, + ) @_catch_login_errors async def process_notifications(login_obj, raw_notifications=None): diff --git a/custom_components/alexa_media/config_flow.py b/custom_components/alexa_media/config_flow.py index 3163ffe1..1ace2a6f 100644 --- a/custom_components/alexa_media/config_flow.py +++ b/custom_components/alexa_media/config_flow.py @@ -43,6 +43,7 @@ CONF_INCLUDE_DEVICES, CONF_QUEUE_DELAY, CONF_SECURITYCODE, + CONF_OAUTH, CONF_OTPSECRET, CONF_TOTP_REGISTER, DATA_ALEXAMEDIA, @@ -359,6 +360,11 @@ async def _test_login(self): self.config.pop("reauth") if self.config.get(CONF_SECURITYCODE): self.config.pop(CONF_SECURITYCODE) + self.config[CONF_OAUTH] = { + "access_token": login.access_token, + "refresh_token": login.refresh_token, + "expires_in": login.expires_in, + } if existing_entry: self.hass.config_entries.async_update_entry( existing_entry, data=self.config diff --git a/custom_components/alexa_media/const.py b/custom_components/alexa_media/const.py index 7625ebf9..7f56c1b8 100644 --- a/custom_components/alexa_media/const.py +++ b/custom_components/alexa_media/const.py @@ -36,6 +36,7 @@ CONF_SECURITYCODE = "securitycode" CONF_OTPSECRET = "otp_secret" CONF_TOTP_REGISTER = "registered" +CONF_OAUTH = "oauth" DATA_LISTENER = "listener" EXCEPTION_TEMPLATE = "An exception of type {0} occurred. Arguments:\n{1!r}" diff --git a/custom_components/alexa_media/manifest.json b/custom_components/alexa_media/manifest.json index cae94ed4..30d50bf0 100644 --- a/custom_components/alexa_media/manifest.json +++ b/custom_components/alexa_media/manifest.json @@ -6,5 +6,5 @@ "issue_tracker": "https://github.com/custom-components/alexa_media_player/issues", "dependencies": ["persistent_notification"], "codeowners": ["@keatontaylor", "@alandtse"], - "requirements": ["alexapy==1.17.2", "packaging~=20.3", "wrapt~=1.12.1"] + "requirements": ["alexapy==1.18.0", "packaging~=20.3", "wrapt~=1.12.1"] }