Skip to content

Commit

Permalink
Fix nest cam access
Browse files Browse the repository at this point in the history
  • Loading branch information
araines committed Oct 18, 2020
1 parent 18a309e commit 02933ab
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions custom_components/badnest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,29 @@ def login(self):
self._login_google()

def _login_dropcam(self):
self._session.post(
f"{API_URL}/dropcam/api/login",
data={"access_token": self._access_token}
)
try:
r = self._session.post(
f"{API_URL}/dropcam/api/login",
data={"access_token": self._access_token}
)
r.raise_for_status()
except (HTTPError, RetryError) as e:
_LOGGER.error(f"Upstream error: {e}")
except RequestException as e:
_LOGGER.error(e)

try:
session = r.json()[0]['session_token']
except KeyError:
_LOGGER.error(f"{r.json()}")
_LOGGER.error("Invalid access_token. Please see:")
_LOGGER.error("https://github.com/mattsch/badnest#configuration")
raise

self._session.headers.update({
"Authorization": f"Basic {self._access_token}",
"cookie": f"user_token={self._access_token}; website_2={session}",
})

def _login_google(self):
headers = {
Expand Down Expand Up @@ -199,7 +218,7 @@ def _login_google(self):

self._session.headers.update({
"Authorization": f"Basic {self._access_token}",
"cookie": f'user_token={self._access_token}',
"cookie": f"user_token={self._access_token}",
})

@Decorators.refresh_login
Expand Down

0 comments on commit 02933ab

Please sign in to comment.