Skip to content

Commit

Permalink
Attempt to reintroduce classic Nest login
Browse files Browse the repository at this point in the history
  • Loading branch information
araines committed Oct 18, 2020
1 parent dd07530 commit 382033b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
14 changes: 12 additions & 2 deletions custom_components/badnest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
from homeassistant.helpers import config_validation as cv

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

CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.All(
{
vol.Required(CONF_USER_ID, default=""): cv.string,
vol.Required(CONF_ACCESS_TOKEN, default=""): cv.string,
},
{
vol.Required(CONF_ISSUE_TOKEN, default=""): cv.string,
vol.Required(CONF_COOKIE, default=""): cv.string,
}
},
)
},
extra=vol.ALLOW_EXTRA,
Expand All @@ -21,14 +25,20 @@
def setup(hass, config):
"""Set up the badnest component."""
if config.get(DOMAIN) is not None:
user_id = config[DOMAIN].get(CONF_USER_ID)
access_token = config[DOMAIN].get(CONF_ACCESS_TOKEN)
issue_token = config[DOMAIN].get(CONF_ISSUE_TOKEN)
cookie = config[DOMAIN].get(CONF_COOKIE)
else:
user_id = None
access_token = None
issue_token = None
cookie = None

hass.data[DOMAIN] = {
'api': NestAPI(
user_id,
access_token,
issue_token,
cookie,
),
Expand Down
18 changes: 16 additions & 2 deletions custom_components/badnest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ class AuthorizationRequired(Exception):

class NestAPI():
def __init__(self,
user_id,
access_token,
issue_token,
cookie):
self.device_data = {}
self._wheres = {}
self._user_id = None
self._access_token = None
self._user_id = user_id
self._access_token = access_token
self._retries = Retry(
total=RETRY_NUM,
backoff_factor=RETRY_BACKOFF,
Expand Down Expand Up @@ -137,6 +139,18 @@ def _check_request(self, r):
r.raise_for_status()

def login(self):
if self._user_id and self._access_token:
self._login_dropcam()
else:
self._login_google()

def _login_dropcam(self):
self._session.post(
f"{API_URL}/dropcam/api/login",
data={"access_token": self._access_token}
)

def _login_google(self):
headers = {
'User-Agent': USER_AGENT,
'Sec-Fetch-Mode': 'cors',
Expand Down

0 comments on commit 382033b

Please sign in to comment.