mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 18:20:44 +00:00
Switch from Nest username/password to user_id/access_token
Username and password can no longer be used directly because of reCAPTCHA.
This commit is contained in:
parent
e55159b465
commit
2e9378de06
@ -1,17 +1,16 @@
|
|||||||
"""The example integration."""
|
"""The example integration."""
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
|
||||||
|
|
||||||
from .api import NestAPI
|
from .api import NestAPI
|
||||||
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_REGION
|
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_USER_ID, CONF_ACCESS_TOKEN, CONF_REGION
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.All(
|
DOMAIN: vol.All(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_EMAIL, default=""): cv.string,
|
vol.Required(CONF_USER_ID, default=""): cv.string,
|
||||||
vol.Required(CONF_PASSWORD, default=""): cv.string,
|
vol.Required(CONF_ACCESS_TOKEN, default=""): cv.string,
|
||||||
vol.Optional(CONF_REGION, default="us"): cv.string,
|
vol.Optional(CONF_REGION, default="us"): cv.string,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -28,8 +27,8 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Set up the badnest component."""
|
"""Set up the badnest component."""
|
||||||
if config.get(DOMAIN) is not None:
|
if config.get(DOMAIN) is not None:
|
||||||
email = config[DOMAIN].get(CONF_EMAIL)
|
user_id = config[DOMAIN].get(CONF_USER_ID)
|
||||||
password = config[DOMAIN].get(CONF_PASSWORD)
|
access_token = config[DOMAIN].get(CONF_ACCESS_TOKEN)
|
||||||
issue_token = config[DOMAIN].get(CONF_ISSUE_TOKEN)
|
issue_token = config[DOMAIN].get(CONF_ISSUE_TOKEN)
|
||||||
cookie = config[DOMAIN].get(CONF_COOKIE)
|
cookie = config[DOMAIN].get(CONF_COOKIE)
|
||||||
region = config[DOMAIN].get(CONF_REGION)
|
region = config[DOMAIN].get(CONF_REGION)
|
||||||
@ -42,8 +41,8 @@ def setup(hass, config):
|
|||||||
|
|
||||||
hass.data[DOMAIN] = {
|
hass.data[DOMAIN] = {
|
||||||
'api': NestAPI(
|
'api': NestAPI(
|
||||||
email,
|
user_id,
|
||||||
password,
|
access_token,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
region,
|
region,
|
||||||
|
@ -27,22 +27,20 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class NestAPI():
|
class NestAPI():
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
email,
|
user_id,
|
||||||
password,
|
access_token,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
region):
|
region):
|
||||||
self.device_data = {}
|
self.device_data = {}
|
||||||
self._wheres = {}
|
self._wheres = {}
|
||||||
self._user_id = None
|
self._user_id = user_id
|
||||||
self._access_token = None
|
self._access_token = access_token
|
||||||
self._session = requests.Session()
|
self._session = requests.Session()
|
||||||
self._session.headers.update({
|
self._session.headers.update({
|
||||||
"Referer": "https://home.nest.com/",
|
"Referer": "https://home.nest.com/",
|
||||||
"User-Agent": USER_AGENT,
|
"User-Agent": USER_AGENT,
|
||||||
})
|
})
|
||||||
self._email = email
|
|
||||||
self._password = password
|
|
||||||
self._issue_token = issue_token
|
self._issue_token = issue_token
|
||||||
self._cookie = cookie
|
self._cookie = cookie
|
||||||
self._czfe_url = None
|
self._czfe_url = None
|
||||||
@ -68,19 +66,10 @@ class NestAPI():
|
|||||||
return hasattr(self, name)
|
return hasattr(self, name)
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
if not self._email and not self._password:
|
if self._issue_token and self._cookie:
|
||||||
self._login_google(self._issue_token, self._cookie)
|
self._login_google(self._issue_token, self._cookie)
|
||||||
else:
|
|
||||||
self._login_nest(self._email, self._password)
|
|
||||||
self._login_dropcam()
|
self._login_dropcam()
|
||||||
|
|
||||||
def _login_nest(self, email, password):
|
|
||||||
r = self._session.post(
|
|
||||||
f"{API_URL}/session", json={"email": email, "password": password}
|
|
||||||
)
|
|
||||||
self._user_id = r.json()["userid"]
|
|
||||||
self._access_token = r.json()["access_token"]
|
|
||||||
|
|
||||||
def _login_google(self, issue_token, cookie):
|
def _login_google(self, issue_token, cookie):
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': USER_AGENT,
|
'User-Agent': USER_AGENT,
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
DOMAIN = 'badnest'
|
DOMAIN = 'badnest'
|
||||||
CONF_ISSUE_TOKEN = 'issue_token'
|
CONF_ISSUE_TOKEN = 'issue_token'
|
||||||
CONF_COOKIE = 'cookie'
|
CONF_COOKIE = 'cookie'
|
||||||
|
CONF_USER_ID = 'user_id'
|
||||||
|
CONF_ACCESS_TOKEN = 'access_token'
|
||||||
CONF_REGION = 'region'
|
CONF_REGION = 'region'
|
||||||
|
11
info.md
11
info.md
@ -32,10 +32,17 @@ two-character country code, and it should work.
|
|||||||
|
|
||||||
### Example configuration.yaml - When you're not using the Google Auth Login
|
### Example configuration.yaml - When you're not using the Google Auth Login
|
||||||
|
|
||||||
|
Google recently introduced reCAPTCHA when logging to Nest. That means username
|
||||||
|
and password cannot be used directly any more. Instead, you have to obtain
|
||||||
|
`user_id` and `access_token` for your account by logging in manually. To do that,
|
||||||
|
open developer tools in your browser, switch to the "Network" tab, log in to Nest
|
||||||
|
and look for the request similar to https://home.nest.com/session?_=1578693398448.
|
||||||
|
You will find `user_id` and `access_token` in the response to the request.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
badnest:
|
badnest:
|
||||||
email: email@domain.com
|
user_id: 11111
|
||||||
password: !secret nest_password
|
access_token: !secret nest_access_token
|
||||||
region: us
|
region: us
|
||||||
|
|
||||||
climate:
|
climate:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user