Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10 from mattsch/bugfix/login
Browse files Browse the repository at this point in the history
Make the error message a little clearer when login is needed
  • Loading branch information
mattsch authored Jun 7, 2020
2 parents 018df94 + fec2ed1 commit 5dd0a91
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions custom_components/badnest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from homeassistant.helpers import config_validation as cv

from .api import NestAPI
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_USER_ID, \
CONF_ACCESS_TOKEN
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE

CONFIG_SCHEMA = vol.Schema(
{
Expand Down
9 changes: 8 additions & 1 deletion custom_components/badnest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self,
self.thermostats = set()
self.temperature_sensors = set()
self.protects = set()

self.login()
self._get_devices()
self.update()
Expand Down Expand Up @@ -151,7 +152,13 @@ def login(self):
except RequestException as e:
_LOGGER.error(e)

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

headers = {
'User-Agent': USER_AGENT,
Expand Down
2 changes: 0 additions & 2 deletions custom_components/badnest/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
DOMAIN = 'badnest'
CONF_ISSUE_TOKEN = 'issue_token'
CONF_COOKIE = 'cookie'
CONF_USER_ID = 'user_id'
CONF_ACCESS_TOKEN = 'access_token'
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ will never be as reliable as the original API
```yaml
badnest:
issue_token: "https://accounts.google.com/o/oauth2/iframerpc....."
cookie: "OCAK=......"
cookie: "......"

climate:
- platform: badnest
Expand Down

0 comments on commit 5dd0a91

Please sign in to comment.