mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 18:30:43 +00:00
Merge pull request #30 from USA-RedDragon/remove_api_key
Remove API Key from the config.
This commit is contained in:
commit
98490b08f5
@ -3,7 +3,7 @@ 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 homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
|
|
||||||
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_APIKEY
|
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
@ -15,7 +15,6 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
{
|
{
|
||||||
vol.Required(CONF_ISSUE_TOKEN, default=""): cv.string,
|
vol.Required(CONF_ISSUE_TOKEN, default=""): cv.string,
|
||||||
vol.Required(CONF_COOKIE, default=""): cv.string,
|
vol.Required(CONF_COOKIE, default=""): cv.string,
|
||||||
vol.Required(CONF_APIKEY, default=""): cv.string
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -30,20 +29,17 @@ def setup(hass, config):
|
|||||||
password = config[DOMAIN].get(CONF_PASSWORD)
|
password = config[DOMAIN].get(CONF_PASSWORD)
|
||||||
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)
|
||||||
api_key = config[DOMAIN].get(CONF_APIKEY)
|
|
||||||
else:
|
else:
|
||||||
email = None
|
email = None
|
||||||
password = None
|
password = None
|
||||||
issue_token = None
|
issue_token = None
|
||||||
cookie = None
|
cookie = None
|
||||||
api_key = None
|
|
||||||
|
|
||||||
hass.data[DOMAIN] = {
|
hass.data[DOMAIN] = {
|
||||||
CONF_EMAIL: email,
|
CONF_EMAIL: email,
|
||||||
CONF_PASSWORD: password,
|
CONF_PASSWORD: password,
|
||||||
CONF_ISSUE_TOKEN: issue_token,
|
CONF_ISSUE_TOKEN: issue_token,
|
||||||
CONF_COOKIE: cookie,
|
CONF_COOKIE: cookie,
|
||||||
CONF_APIKEY: api_key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -10,6 +10,9 @@ USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) " \
|
|||||||
"Chrome/75.0.3770.100 Safari/537.36"
|
"Chrome/75.0.3770.100 Safari/537.36"
|
||||||
URL_JWT = "https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt"
|
URL_JWT = "https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt"
|
||||||
|
|
||||||
|
# Nest website's (public) API key
|
||||||
|
NEST_API_KEY = "AIzaSyAdkSIMNc51XGNEAYWasX9UOWkS5P6sZE4"
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +22,6 @@ class NestAPI:
|
|||||||
password,
|
password,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key,
|
|
||||||
device_id=None):
|
device_id=None):
|
||||||
self._user_id = None
|
self._user_id = None
|
||||||
self._access_token = None
|
self._access_token = None
|
||||||
@ -30,12 +32,11 @@ class NestAPI:
|
|||||||
self._password = password
|
self._password = password
|
||||||
self._issue_token = issue_token
|
self._issue_token = issue_token
|
||||||
self._cookie = cookie
|
self._cookie = cookie
|
||||||
self._api_key = api_key
|
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
if not self._email and not self._password:
|
if not self._email and not self._password:
|
||||||
self._login_google(self._issue_token, self._cookie, self._api_key)
|
self._login_google(self._issue_token, self._cookie)
|
||||||
else:
|
else:
|
||||||
self._login_nest(self._email, self._password)
|
self._login_nest(self._email, self._password)
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ class NestAPI:
|
|||||||
self._user_id = r.json()["userid"]
|
self._user_id = r.json()["userid"]
|
||||||
self._access_token = r.json()["access_token"]
|
self._access_token = r.json()["access_token"]
|
||||||
|
|
||||||
def _login_google(self, issue_token, cookie, api_key):
|
def _login_google(self, issue_token, cookie):
|
||||||
headers = {
|
headers = {
|
||||||
'Sec-Fetch-Mode': 'cors',
|
'Sec-Fetch-Mode': 'cors',
|
||||||
'User-Agent': USER_AGENT,
|
'User-Agent': USER_AGENT,
|
||||||
@ -60,7 +61,7 @@ class NestAPI:
|
|||||||
headers = {
|
headers = {
|
||||||
'Authorization': 'Bearer ' + access_token,
|
'Authorization': 'Bearer ' + access_token,
|
||||||
'User-Agent': USER_AGENT,
|
'User-Agent': USER_AGENT,
|
||||||
'x-goog-api-key': api_key,
|
'x-goog-api-key': NEST_API_KEY,
|
||||||
'Referer': 'https://home.nest.com'
|
'Referer': 'https://home.nest.com'
|
||||||
}
|
}
|
||||||
params = {
|
params = {
|
||||||
@ -80,14 +81,12 @@ class NestThermostatAPI(NestAPI):
|
|||||||
password,
|
password,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key,
|
|
||||||
device_id=None):
|
device_id=None):
|
||||||
super(NestThermostatAPI, self).__init__(
|
super(NestThermostatAPI, self).__init__(
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key,
|
|
||||||
device_id)
|
device_id)
|
||||||
self._czfe_url = None
|
self._czfe_url = None
|
||||||
self._compressor_lockout_enabled = None
|
self._compressor_lockout_enabled = None
|
||||||
@ -290,14 +289,12 @@ class NestTemperatureSensorAPI(NestAPI):
|
|||||||
password,
|
password,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key,
|
|
||||||
device_id=None):
|
device_id=None):
|
||||||
super(NestTemperatureSensorAPI, self).__init__(
|
super(NestTemperatureSensorAPI, self).__init__(
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key,
|
|
||||||
device_id)
|
device_id)
|
||||||
self.temperature = None
|
self.temperature = None
|
||||||
self._device_id = device_id
|
self._device_id = device_id
|
||||||
@ -362,7 +359,6 @@ class NestCameraAPI(NestAPI):
|
|||||||
password,
|
password,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key,
|
|
||||||
region,
|
region,
|
||||||
device_id=None):
|
device_id=None):
|
||||||
super(NestCameraAPI, self).__init__(
|
super(NestCameraAPI, self).__init__(
|
||||||
@ -370,7 +366,6 @@ class NestCameraAPI(NestAPI):
|
|||||||
password,
|
password,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key,
|
|
||||||
device_id)
|
device_id)
|
||||||
# log into dropcam
|
# log into dropcam
|
||||||
self._session.post(
|
self._session.post(
|
||||||
|
@ -15,7 +15,6 @@ from homeassistant.util.dt import utcnow
|
|||||||
|
|
||||||
from .api import NestCameraAPI
|
from .api import NestCameraAPI
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_APIKEY,
|
|
||||||
CONF_COOKIE,
|
CONF_COOKIE,
|
||||||
CONF_ISSUE_TOKEN,
|
CONF_ISSUE_TOKEN,
|
||||||
CONF_REGION,
|
CONF_REGION,
|
||||||
@ -41,7 +40,6 @@ async def async_setup_platform(hass,
|
|||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
hass.data[DOMAIN][CONF_PASSWORD],
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
hass.data[DOMAIN][CONF_COOKIE],
|
||||||
hass.data[DOMAIN][CONF_APIKEY],
|
|
||||||
config.get(CONF_REGION)
|
config.get(CONF_REGION)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,7 +53,6 @@ async def async_setup_platform(hass,
|
|||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
hass.data[DOMAIN][CONF_PASSWORD],
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
hass.data[DOMAIN][CONF_COOKIE],
|
||||||
hass.data[DOMAIN][CONF_APIKEY],
|
|
||||||
config.get(CONF_REGION),
|
config.get(CONF_REGION),
|
||||||
camera["uuid"]
|
camera["uuid"]
|
||||||
))
|
))
|
||||||
|
@ -30,7 +30,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .api import NestThermostatAPI
|
from .api import NestThermostatAPI
|
||||||
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_APIKEY
|
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE
|
||||||
|
|
||||||
NEST_MODE_HEAT_COOL = "range"
|
NEST_MODE_HEAT_COOL = "range"
|
||||||
NEST_MODE_ECO = "eco"
|
NEST_MODE_ECO = "eco"
|
||||||
@ -68,7 +68,6 @@ async def async_setup_platform(hass,
|
|||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
hass.data[DOMAIN][CONF_PASSWORD],
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
hass.data[DOMAIN][CONF_COOKIE],
|
||||||
hass.data[DOMAIN][CONF_APIKEY]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
thermostats = []
|
thermostats = []
|
||||||
@ -80,7 +79,6 @@ async def async_setup_platform(hass,
|
|||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
hass.data[DOMAIN][CONF_PASSWORD],
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
hass.data[DOMAIN][CONF_COOKIE],
|
||||||
hass.data[DOMAIN][CONF_APIKEY],
|
|
||||||
thermostat
|
thermostat
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
DOMAIN = 'badnest'
|
DOMAIN = 'badnest'
|
||||||
CONF_ISSUE_TOKEN = 'issue_token'
|
CONF_ISSUE_TOKEN = 'issue_token'
|
||||||
CONF_COOKIE = 'cookie'
|
CONF_COOKIE = 'cookie'
|
||||||
CONF_APIKEY = 'api_key'
|
|
||||||
CONF_REGION = 'region'
|
CONF_REGION = 'region'
|
||||||
|
@ -3,7 +3,7 @@ import logging
|
|||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from .api import NestTemperatureSensorAPI
|
from .api import NestTemperatureSensorAPI
|
||||||
from .const import DOMAIN, CONF_APIKEY, CONF_COOKIE, CONF_ISSUE_TOKEN
|
from .const import DOMAIN, CONF_COOKIE, CONF_ISSUE_TOKEN
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_BATTERY_LEVEL,
|
ATTR_BATTERY_LEVEL,
|
||||||
@ -26,7 +26,6 @@ async def async_setup_platform(hass,
|
|||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
hass.data[DOMAIN][CONF_PASSWORD],
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
hass.data[DOMAIN][CONF_COOKIE],
|
||||||
hass.data[DOMAIN][CONF_APIKEY]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
@ -41,7 +40,6 @@ async def async_setup_platform(hass,
|
|||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
hass.data[DOMAIN][CONF_PASSWORD],
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
hass.data[DOMAIN][CONF_COOKIE],
|
||||||
hass.data[DOMAIN][CONF_APIKEY],
|
|
||||||
sensor
|
sensor
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
6
info.md
6
info.md
@ -45,7 +45,6 @@ sensor:
|
|||||||
badnest:
|
badnest:
|
||||||
issue_token: "https://accounts.google.com/o/oauth2/iframerpc....."
|
issue_token: "https://accounts.google.com/o/oauth2/iframerpc....."
|
||||||
cookie: "OCAK=......"
|
cookie: "OCAK=......"
|
||||||
api_key : "#YOURAPIKEYHERE#"
|
|
||||||
|
|
||||||
climate:
|
climate:
|
||||||
- platform: badnest
|
- platform: badnest
|
||||||
@ -61,7 +60,7 @@ sensor:
|
|||||||
|
|
||||||
Google Login support added with many thanks to: chrisjshull from <https://github.com/chrisjshull/homebridge-nest/>
|
Google Login support added with many thanks to: chrisjshull from <https://github.com/chrisjshull/homebridge-nest/>
|
||||||
|
|
||||||
The values of `"issue_token"`, `"cookie"` and `"api_key"` are specific to your Google Account. To get them, follow these steps (only needs to be done once, as long as you stay logged into your Google Account).
|
The values of `"issue_token"` and `"cookie"` are specific to your Google Account. To get them, follow these steps (only needs to be done once, as long as you stay logged into your Google Account).
|
||||||
|
|
||||||
1. Open a Chrome browser tab in Incognito Mode (or clear your cache).
|
1. Open a Chrome browser tab in Incognito Mode (or clear your cache).
|
||||||
2. Open Developer Tools (View/Developer/Developer Tools).
|
2. Open Developer Tools (View/Developer/Developer Tools).
|
||||||
@ -73,6 +72,3 @@ The values of `"issue_token"`, `"cookie"` and `"api_key"` are specific to your G
|
|||||||
8. In the 'Filter' box, enter `oauth2/iframe`
|
8. In the 'Filter' box, enter `oauth2/iframe`
|
||||||
9. Several network calls will appear in the Dev Tools window. Click on the last `iframe` call.
|
9. Several network calls will appear in the Dev Tools window. Click on the last `iframe` call.
|
||||||
10. In the Headers tab, under Request Headers, copy the entire `cookie` (beginning `OCAK=...` - **include the whole string which is several lines long and has many field/value pairs** - do not include the `cookie:` name). This is your `"cookie"` in `configuration.yaml`.
|
10. In the Headers tab, under Request Headers, copy the entire `cookie` (beginning `OCAK=...` - **include the whole string which is several lines long and has many field/value pairs** - do not include the `cookie:` name). This is your `"cookie"` in `configuration.yaml`.
|
||||||
11. In the 'Filter' box, enter `issue_jwt`
|
|
||||||
12. Click on the last `issue_jwt` call.
|
|
||||||
13. In the Headers tab, under Request Headers, copy the entire `x-goog-api-key` (do not include the `x-goog-api-key:` name). This is your `"api_key"` in `configuration.yaml`.
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user