Revert "Fix connection issues with withings API by switching to a maintained codebase (#27310)" (#27385)

This reverts commit 071476343c.
This commit is contained in:
Martin Hjelmare 2019-10-10 14:21:42 +02:00 committed by Bram Kragten
parent d337b71725
commit c188ecf79b
9 changed files with 117 additions and 130 deletions

View file

@ -4,7 +4,7 @@ import logging
import re
import time
import withings_api as withings
import nokia
from oauthlib.oauth2.rfc6749.errors import MissingTokenError
from requests_oauthlib import TokenUpdated
@ -68,9 +68,7 @@ class WithingsDataManager:
service_available = None
def __init__(
self, hass: HomeAssistantType, profile: str, api: withings.WithingsApi
):
def __init__(self, hass: HomeAssistantType, profile: str, api: nokia.NokiaApi):
"""Constructor."""
self._hass = hass
self._api = api
@ -255,7 +253,7 @@ def create_withings_data_manager(
"""Set up the sensor config entry."""
entry_creds = entry.data.get(const.CREDENTIALS) or {}
profile = entry.data[const.PROFILE]
credentials = withings.WithingsCredentials(
credentials = nokia.NokiaCredentials(
entry_creds.get("access_token"),
entry_creds.get("token_expiry"),
entry_creds.get("token_type"),
@ -268,7 +266,7 @@ def create_withings_data_manager(
def credentials_saver(credentials_param):
_LOGGER.debug("Saving updated credentials of type %s", type(credentials_param))
# Sanitizing the data as sometimes a WithingsCredentials object
# Sanitizing the data as sometimes a NokiaCredentials object
# is passed through from the API.
cred_data = credentials_param
if not isinstance(credentials_param, dict):
@ -277,8 +275,8 @@ def create_withings_data_manager(
entry.data[const.CREDENTIALS] = cred_data
hass.config_entries.async_update_entry(entry, data={**entry.data})
_LOGGER.debug("Creating withings api instance")
api = withings.WithingsApi(
_LOGGER.debug("Creating nokia api instance")
api = nokia.NokiaApi(
credentials, refresh_cb=(lambda token: credentials_saver(api.credentials))
)