mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-09-07 03:01:52 +01:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cc7ec56d2a | ||
|
385e97a62a | ||
|
fe6f04e645 | ||
|
799d7a55dc | ||
|
0c87f7561a | ||
|
c9693df3a2 | ||
|
2927881c33 | ||
|
334ce8579f | ||
|
98490b08f5 | ||
|
7cef7c65a4 | ||
|
c7ac77ca85 | ||
|
dadf80f745 | ||
|
fa1a632d2b | ||
|
b1447a4e6e | ||
|
3d49b85c50 | ||
|
4a6c88a6ef | ||
|
51efa759e8 | ||
|
77bd36b4bd | ||
|
1228304609 | ||
|
68e71850be | ||
|
5f4b14514c | ||
|
6f097c58a8 | ||
|
98daabc5d7 | ||
|
c4f702b859 | ||
|
977c553a8d | ||
|
f1abecefce | ||
|
c7c011720c | ||
|
b4debfcf9c | ||
|
10bd645c0f | ||
|
de8312b722 | ||
|
ed105b74c1 | ||
|
52d381f471 | ||
|
074a2fdf44 | ||
|
87c65ab23e | ||
|
7ac7989bf4 | ||
|
f2643d4427 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -12,6 +12,6 @@ jobs:
|
|||||||
run: zip -r badnest.zip hacs.json info.md custom_components
|
run: zip -r badnest.zip hacs.json info.md custom_components
|
||||||
- uses: JasonEtco/upload-to-release@master
|
- uses: JasonEtco/upload-to-release@master
|
||||||
with:
|
with:
|
||||||
args: badnest.zip
|
args: badnest.zip application/zip
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
8
.gitignore
vendored
8
.gitignore
vendored
@@ -91,3 +91,11 @@ ENV/
|
|||||||
|
|
||||||
.vscode/
|
.vscode/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
__init__.py
|
||||||
|
api.py
|
||||||
|
camera.py
|
||||||
|
climate.py
|
||||||
|
const.py
|
||||||
|
manifest.json
|
||||||
|
sensor.py
|
||||||
|
@@ -3,7 +3,8 @@ 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 .api import NestAPI
|
||||||
|
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_REGION
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
@@ -11,11 +12,12 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
{
|
{
|
||||||
vol.Required(CONF_EMAIL, default=""): cv.string,
|
vol.Required(CONF_EMAIL, default=""): cv.string,
|
||||||
vol.Required(CONF_PASSWORD, default=""): cv.string,
|
vol.Required(CONF_PASSWORD, default=""): cv.string,
|
||||||
|
vol.Optional(CONF_REGION, default="us"): cv.string,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
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
|
vol.Optional(CONF_REGION, default="us"): cv.string,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -30,20 +32,22 @@ 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)
|
region = config[DOMAIN].get(CONF_REGION)
|
||||||
else:
|
else:
|
||||||
email = None
|
email = None
|
||||||
password = None
|
password = None
|
||||||
issue_token = None
|
issue_token = None
|
||||||
cookie = None
|
cookie = None
|
||||||
api_key = None
|
region = None
|
||||||
|
|
||||||
hass.data[DOMAIN] = {
|
hass.data[DOMAIN] = {
|
||||||
CONF_EMAIL: email,
|
'api': NestAPI(
|
||||||
CONF_PASSWORD: password,
|
email,
|
||||||
CONF_ISSUE_TOKEN: issue_token,
|
password,
|
||||||
CONF_COOKIE: cookie,
|
issue_token,
|
||||||
CONF_APIKEY: api_key
|
cookie,
|
||||||
|
region,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@@ -1,25 +1,78 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
API_URL = "https://home.nest.com"
|
API_URL = "https://home.nest.com"
|
||||||
CAMERA_WEBAPI_BASE = "https://webapi.camera.home.nest.com"
|
CAMERA_WEBAPI_BASE = "https://webapi.camera.home.nest.com"
|
||||||
CAMERA_URL = "https://nexusapi-us1.camera.home.nest.com"
|
|
||||||
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) " \
|
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) " \
|
||||||
"AppleWebKit/537.36 (KHTML, like Gecko) " \
|
"AppleWebKit/537.36 (KHTML, like Gecko) " \
|
||||||
"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"
|
||||||
|
|
||||||
class NestAPI:
|
KNOWN_BUCKET_TYPES = [
|
||||||
def __init__(self, email, password, issue_token, cookie, api_key):
|
# Thermostats
|
||||||
|
"device",
|
||||||
|
"shared",
|
||||||
|
# Protect
|
||||||
|
"topaz",
|
||||||
|
# Temperature sensors
|
||||||
|
"kryptonite",
|
||||||
|
]
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class NestAPI():
|
||||||
|
def __init__(self,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
issue_token,
|
||||||
|
cookie,
|
||||||
|
region):
|
||||||
|
self.device_data = {}
|
||||||
|
self._wheres = {}
|
||||||
self._user_id = None
|
self._user_id = None
|
||||||
self._access_token = None
|
self._access_token = None
|
||||||
self._session = requests.Session()
|
self._session = requests.Session()
|
||||||
self._session.headers.update({"Referer": "https://home.nest.com/"})
|
self._session.headers.update({
|
||||||
self._device_id = None
|
"Referer": "https://home.nest.com/",
|
||||||
if not email and not password:
|
"User-Agent": USER_AGENT,
|
||||||
self._login_google(issue_token, cookie, api_key)
|
})
|
||||||
|
self._email = email
|
||||||
|
self._password = password
|
||||||
|
self._issue_token = issue_token
|
||||||
|
self._cookie = cookie
|
||||||
|
self._czfe_url = None
|
||||||
|
self._camera_url = f'https://nexusapi-{region}1.camera.home.nest.com'
|
||||||
|
self.cameras = []
|
||||||
|
self.thermostats = []
|
||||||
|
self.temperature_sensors = []
|
||||||
|
self.protects = []
|
||||||
|
self.login()
|
||||||
|
self._get_devices()
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def __getitem__(self, name):
|
||||||
|
return getattr(self, name)
|
||||||
|
|
||||||
|
def __setitem__(self, name, value):
|
||||||
|
return setattr(self, name, value)
|
||||||
|
|
||||||
|
def __delitem__(self, name):
|
||||||
|
return delattr(self, name)
|
||||||
|
|
||||||
|
def __contains__(self, name):
|
||||||
|
return hasattr(self, name)
|
||||||
|
|
||||||
|
def login(self):
|
||||||
|
if not self._email and not self._password:
|
||||||
|
self._login_google(self._issue_token, self._cookie)
|
||||||
else:
|
else:
|
||||||
self._login_nest(email, password)
|
self._login_nest(self._email, self._password)
|
||||||
|
self._login_dropcam()
|
||||||
|
|
||||||
def _login_nest(self, email, password):
|
def _login_nest(self, email, password):
|
||||||
r = self._session.post(
|
r = self._session.post(
|
||||||
@@ -28,21 +81,21 @@ 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',
|
|
||||||
'User-Agent': USER_AGENT,
|
'User-Agent': USER_AGENT,
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
'X-Requested-With': 'XmlHttpRequest',
|
'X-Requested-With': 'XmlHttpRequest',
|
||||||
'Referer': 'https://accounts.google.com/o/oauth2/iframe',
|
'Referer': 'https://accounts.google.com/o/oauth2/iframe',
|
||||||
'cookie': cookie
|
'cookie': cookie
|
||||||
}
|
}
|
||||||
r = requests.get(url=issue_token, headers=headers)
|
r = self._session.get(url=issue_token, headers=headers)
|
||||||
access_token = r.json()['access_token']
|
access_token = r.json()['access_token']
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': 'Bearer ' + access_token,
|
|
||||||
'User-Agent': USER_AGENT,
|
'User-Agent': USER_AGENT,
|
||||||
'x-goog-api-key': api_key,
|
'Authorization': 'Bearer ' + access_token,
|
||||||
|
'x-goog-api-key': NEST_API_KEY,
|
||||||
'Referer': 'https://home.nest.com'
|
'Referer': 'https://home.nest.com'
|
||||||
}
|
}
|
||||||
params = {
|
params = {
|
||||||
@@ -51,244 +104,395 @@ class NestAPI:
|
|||||||
"google_oauth_access_token": access_token,
|
"google_oauth_access_token": access_token,
|
||||||
"policy_id": 'authproxy-oauth-policy'
|
"policy_id": 'authproxy-oauth-policy'
|
||||||
}
|
}
|
||||||
r = requests.post(url=URL_JWT, headers=headers, params=params)
|
r = self._session.post(url=URL_JWT, headers=headers, params=params)
|
||||||
self._user_id = r.json()['claims']['subject']['nestId']['id']
|
self._user_id = r.json()['claims']['subject']['nestId']['id']
|
||||||
self._access_token = r.json()['jwt']
|
self._access_token = r.json()['jwt']
|
||||||
|
|
||||||
|
def _login_dropcam(self):
|
||||||
class NestThermostatAPI(NestAPI):
|
|
||||||
def __init__(self, email, password, issue_token, cookie, api_key):
|
|
||||||
super(NestThermostatAPI, self).__init__(
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
issue_token,
|
|
||||||
cookie,
|
|
||||||
api_key)
|
|
||||||
self._shared_id = None
|
|
||||||
self._czfe_url = None
|
|
||||||
self._compressor_lockout_enabled = None
|
|
||||||
self._compressor_lockout_time = None
|
|
||||||
self._hvac_ac_state = None
|
|
||||||
self._hvac_heater_state = None
|
|
||||||
self.mode = None
|
|
||||||
self._time_to_target = None
|
|
||||||
self._fan_timer_timeout = None
|
|
||||||
self.can_heat = None
|
|
||||||
self.can_cool = None
|
|
||||||
self.has_fan = None
|
|
||||||
self.fan = None
|
|
||||||
self.away = None
|
|
||||||
self.current_temperature = None
|
|
||||||
self.target_temperature = None
|
|
||||||
self.target_temperature_high = None
|
|
||||||
self.target_temperature_low = None
|
|
||||||
self.current_humidity = None
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def get_action(self):
|
|
||||||
if self._hvac_ac_state:
|
|
||||||
return "cooling"
|
|
||||||
elif self._hvac_heater_state:
|
|
||||||
return "heating"
|
|
||||||
else:
|
|
||||||
return "off"
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
r = self._session.post(
|
|
||||||
f"{API_URL}/api/0.1/user/{self._user_id}/app_launch",
|
|
||||||
json={
|
|
||||||
"known_bucket_types": ["shared", "device"],
|
|
||||||
"known_bucket_versions": [],
|
|
||||||
},
|
|
||||||
headers={"Authorization": f"Basic {self._access_token}"},
|
|
||||||
)
|
|
||||||
|
|
||||||
self._czfe_url = r.json()["service_urls"]["urls"]["czfe_url"]
|
|
||||||
|
|
||||||
for bucket in r.json()["updated_buckets"]:
|
|
||||||
if bucket["object_key"].startswith("shared."):
|
|
||||||
self._shared_id = bucket["object_key"]
|
|
||||||
thermostat_data = bucket["value"]
|
|
||||||
self.current_temperature = \
|
|
||||||
thermostat_data["current_temperature"]
|
|
||||||
self.target_temperature = thermostat_data["target_temperature"]
|
|
||||||
self._compressor_lockout_enabled = thermostat_data[
|
|
||||||
"compressor_lockout_enabled"
|
|
||||||
]
|
|
||||||
self._compressor_lockout_time = thermostat_data[
|
|
||||||
"compressor_lockout_timeout"
|
|
||||||
]
|
|
||||||
self._hvac_ac_state = thermostat_data["hvac_ac_state"]
|
|
||||||
self._hvac_heater_state = thermostat_data["hvac_heater_state"]
|
|
||||||
self.mode = thermostat_data["target_temperature_type"]
|
|
||||||
self.target_temperature_high = thermostat_data[
|
|
||||||
"target_temperature_high"
|
|
||||||
]
|
|
||||||
self.target_temperature_low = \
|
|
||||||
thermostat_data["target_temperature_low"]
|
|
||||||
self.can_heat = thermostat_data["can_heat"]
|
|
||||||
self.can_cool = thermostat_data["can_cool"]
|
|
||||||
elif bucket["object_key"].startswith("device."):
|
|
||||||
self._device_id = bucket["object_key"]
|
|
||||||
thermostat_data = bucket["value"]
|
|
||||||
self._time_to_target = thermostat_data["time_to_target"]
|
|
||||||
self._fan_timer_timeout = thermostat_data["fan_timer_timeout"]
|
|
||||||
self.has_fan = thermostat_data["has_fan"]
|
|
||||||
self.fan = thermostat_data["fan_timer_timeout"] > 0
|
|
||||||
self.current_humidity = thermostat_data["current_humidity"]
|
|
||||||
self.away = thermostat_data["home_away_input"]
|
|
||||||
|
|
||||||
def set_temp(self, temp, temp_high=None):
|
|
||||||
if temp_high is None:
|
|
||||||
self._session.post(
|
|
||||||
f"{self._czfe_url}/v5/put",
|
|
||||||
json={
|
|
||||||
"objects": [
|
|
||||||
{
|
|
||||||
"object_key": self._shared_id,
|
|
||||||
"op": "MERGE",
|
|
||||||
"value": {"target_temperature": temp},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
headers={"Authorization": f"Basic {self._access_token}"},
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self._session.post(
|
|
||||||
f"{self._czfe_url}/v5/put",
|
|
||||||
json={
|
|
||||||
"objects": [
|
|
||||||
{
|
|
||||||
"object_key": self._shared_id,
|
|
||||||
"op": "MERGE",
|
|
||||||
"value": {
|
|
||||||
"target_temperature_low": temp,
|
|
||||||
"target_temperature_high": temp_high,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
headers={"Authorization": f"Basic {self._access_token}"},
|
|
||||||
)
|
|
||||||
|
|
||||||
def set_mode(self, mode):
|
|
||||||
self._session.post(
|
|
||||||
f"{self._czfe_url}/v5/put",
|
|
||||||
json={
|
|
||||||
"objects": [
|
|
||||||
{
|
|
||||||
"object_key": self._shared_id,
|
|
||||||
"op": "MERGE",
|
|
||||||
"value": {"target_temperature_type": mode},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
headers={"Authorization": f"Basic {self._access_token}"},
|
|
||||||
)
|
|
||||||
|
|
||||||
def set_fan(self, date):
|
|
||||||
self._session.post(
|
|
||||||
f"{self._czfe_url}/v5/put",
|
|
||||||
json={
|
|
||||||
"objects": [
|
|
||||||
{
|
|
||||||
"object_key": self._device_id,
|
|
||||||
"op": "MERGE",
|
|
||||||
"value": {"fan_timer_timeout": date},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
headers={"Authorization": f"Basic {self._access_token}"},
|
|
||||||
)
|
|
||||||
|
|
||||||
def set_eco_mode(self):
|
|
||||||
self._session.post(
|
|
||||||
f"{self._czfe_url}/v5/put",
|
|
||||||
json={
|
|
||||||
"objects": [
|
|
||||||
{
|
|
||||||
"object_key": self._device_id,
|
|
||||||
"op": "MERGE",
|
|
||||||
"value": {"eco": {"mode": "manual-eco"}},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
headers={"Authorization": f"Basic {self._access_token}"},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class NestCameraAPI(NestAPI):
|
|
||||||
def __init__(self, email, password, issue_token, cookie, api_key):
|
|
||||||
super(NestCameraAPI, self).__init__(
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
issue_token,
|
|
||||||
cookie,
|
|
||||||
api_key)
|
|
||||||
# log into dropcam
|
|
||||||
self._session.post(
|
self._session.post(
|
||||||
f"{API_URL}/dropcam/api/login",
|
f"{API_URL}/dropcam/api/login",
|
||||||
data={"access_token": self._access_token}
|
data={"access_token": self._access_token}
|
||||||
)
|
)
|
||||||
self.location = None
|
|
||||||
self.name = "Nest Camera"
|
|
||||||
self.online = None
|
|
||||||
self.is_streaming = None
|
|
||||||
self.battery_voltage = None
|
|
||||||
self.ac_voltge = None
|
|
||||||
self.data_tier = None
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def set_device(self, uuid):
|
def _get_cameras(self):
|
||||||
self._device_id = uuid
|
cameras = []
|
||||||
self.update()
|
|
||||||
|
try:
|
||||||
|
r = self._session.get(
|
||||||
|
f"{CAMERA_WEBAPI_BASE}/api/cameras."
|
||||||
|
+ "get_owned_and_member_of_with_properties"
|
||||||
|
)
|
||||||
|
|
||||||
|
for camera in r.json()["items"]:
|
||||||
|
cameras.append(camera['uuid'])
|
||||||
|
self.device_data[camera['uuid']] = {}
|
||||||
|
|
||||||
|
return cameras
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to get cameras, trying again')
|
||||||
|
return self._get_cameras()
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to get cameras, trying to log in again')
|
||||||
|
self.login()
|
||||||
|
return self._get_cameras()
|
||||||
|
|
||||||
|
def _get_devices(self):
|
||||||
|
try:
|
||||||
|
r = self._session.post(
|
||||||
|
f"{API_URL}/api/0.1/user/{self._user_id}/app_launch",
|
||||||
|
json={
|
||||||
|
"known_bucket_types": ["buckets"],
|
||||||
|
"known_bucket_versions": [],
|
||||||
|
},
|
||||||
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
|
)
|
||||||
|
|
||||||
|
self._czfe_url = r.json()["service_urls"]["urls"]["czfe_url"]
|
||||||
|
|
||||||
|
buckets = r.json()['updated_buckets'][0]['value']['buckets']
|
||||||
|
for bucket in buckets:
|
||||||
|
if bucket.startswith('topaz.'):
|
||||||
|
sn = bucket.replace('topaz.', '')
|
||||||
|
self.protects.append(sn)
|
||||||
|
self.device_data[sn] = {}
|
||||||
|
elif bucket.startswith('kryptonite.'):
|
||||||
|
sn = bucket.replace('kryptonite.', '')
|
||||||
|
self.temperature_sensors.append(sn)
|
||||||
|
self.device_data[sn] = {}
|
||||||
|
elif bucket.startswith('device.'):
|
||||||
|
sn = bucket.replace('device.', '')
|
||||||
|
self.thermostats.append(sn)
|
||||||
|
self.device_data[sn] = {}
|
||||||
|
|
||||||
|
self.cameras = self._get_cameras()
|
||||||
|
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to get devices, trying again')
|
||||||
|
return self.get_devices()
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to get devices, trying to log in again')
|
||||||
|
self.login()
|
||||||
|
return self.get_devices()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self._device_id:
|
try:
|
||||||
props = self.get_properties()
|
# To get friendly names
|
||||||
self._location = None
|
r = self._session.post(
|
||||||
self.name = props["name"]
|
f"{API_URL}/api/0.1/user/{self._user_id}/app_launch",
|
||||||
self.online = props["is_online"]
|
json={
|
||||||
self.is_streaming = props["is_streaming"]
|
"known_bucket_types": ["where"],
|
||||||
self.battery_voltage = props["rq_battery_battery_volt"]
|
"known_bucket_versions": [],
|
||||||
self.ac_voltge = props["rq_battery_vbridge_volt"]
|
},
|
||||||
self.location = props["location"]
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
self.data_tier = props["properties"]["streaming.data-usage-tier"]
|
)
|
||||||
|
|
||||||
def _set_properties(self, property, value):
|
for bucket in r.json()["updated_buckets"]:
|
||||||
r = self._session.post(
|
sensor_data = bucket["value"]
|
||||||
f"{CAMERA_WEBAPI_BASE}/api/dropcams.set_properties",
|
sn = bucket["object_key"].split('.')[1]
|
||||||
data={property: value, "uuid": self._device_id},
|
if bucket["object_key"].startswith(
|
||||||
)
|
f"where.{sn}"):
|
||||||
|
wheres = sensor_data['wheres']
|
||||||
|
for where in wheres:
|
||||||
|
self._wheres[where['where_id']] = where['name']
|
||||||
|
|
||||||
return r.json()["items"]
|
r = self._session.post(
|
||||||
|
f"{API_URL}/api/0.1/user/{self._user_id}/app_launch",
|
||||||
|
json={
|
||||||
|
"known_bucket_types": KNOWN_BUCKET_TYPES,
|
||||||
|
"known_bucket_versions": [],
|
||||||
|
},
|
||||||
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
|
)
|
||||||
|
|
||||||
def get_properties(self):
|
for bucket in r.json()["updated_buckets"]:
|
||||||
r = self._session.get(
|
sensor_data = bucket["value"]
|
||||||
f"{API_URL}/dropcam/api/cameras/{self._device_id}"
|
sn = bucket["object_key"].split('.')[1]
|
||||||
)
|
# Thermostats
|
||||||
return r.json()[0]
|
if bucket["object_key"].startswith(
|
||||||
|
f"shared.{sn}"):
|
||||||
|
self.device_data[sn]['current_temperature'] = \
|
||||||
|
sensor_data["current_temperature"]
|
||||||
|
self.device_data[sn]['target_temperature'] = \
|
||||||
|
sensor_data["target_temperature"]
|
||||||
|
self.device_data[sn]['hvac_ac_state'] = \
|
||||||
|
sensor_data["hvac_ac_state"]
|
||||||
|
self.device_data[sn]['hvac_heater_state'] = \
|
||||||
|
sensor_data["hvac_heater_state"]
|
||||||
|
self.device_data[sn]['target_temperature_high'] = \
|
||||||
|
sensor_data["target_temperature_high"]
|
||||||
|
self.device_data[sn]['target_temperature_low'] = \
|
||||||
|
sensor_data["target_temperature_low"]
|
||||||
|
self.device_data[sn]['can_heat'] = \
|
||||||
|
sensor_data["can_heat"]
|
||||||
|
self.device_data[sn]['can_cool'] = \
|
||||||
|
sensor_data["can_cool"]
|
||||||
|
self.device_data[sn]['mode'] = \
|
||||||
|
sensor_data["target_temperature_type"]
|
||||||
|
if self.device_data[sn]['hvac_ac_state']:
|
||||||
|
self.device_data[sn]['action'] = "cooling"
|
||||||
|
elif self.device_data[sn]['hvac_heater_state']:
|
||||||
|
self.device_data[sn]['action'] = "heating"
|
||||||
|
else:
|
||||||
|
self.device_data[sn]['action'] = "off"
|
||||||
|
# Thermostats, pt 2
|
||||||
|
elif bucket["object_key"].startswith(
|
||||||
|
f"device.{sn}"):
|
||||||
|
self.device_data[sn]['name'] = self._wheres[
|
||||||
|
sensor_data['where_id']
|
||||||
|
]
|
||||||
|
if sensor_data.get('description', None):
|
||||||
|
self.device_data[sn]['name'] += \
|
||||||
|
f' ({sensor_data["description"]})'
|
||||||
|
self.device_data[sn]['name'] += ' Thermostat'
|
||||||
|
self.device_data[sn]['has_fan'] = \
|
||||||
|
sensor_data["has_fan"]
|
||||||
|
self.device_data[sn]['fan'] = \
|
||||||
|
sensor_data["fan_timer_timeout"]
|
||||||
|
self.device_data[sn]['current_humidity'] = \
|
||||||
|
sensor_data["current_humidity"]
|
||||||
|
if sensor_data["eco"]["mode"] == 'manual-eco' or \
|
||||||
|
sensor_data["eco"]["mode"] == 'auto-eco':
|
||||||
|
self.device_data[sn]['eco'] = True
|
||||||
|
else:
|
||||||
|
self.device_data[sn]['eco'] = False
|
||||||
|
# Protect
|
||||||
|
elif bucket["object_key"].startswith(
|
||||||
|
f"topaz.{sn}"):
|
||||||
|
self.device_data[sn]['name'] = self._wheres[
|
||||||
|
sensor_data['where_id']
|
||||||
|
]
|
||||||
|
if sensor_data.get('description', None):
|
||||||
|
self.device_data[sn]['name'] += \
|
||||||
|
f' ({sensor_data["description"]})'
|
||||||
|
self.device_data[sn]['name'] += ' Protect'
|
||||||
|
self.device_data[sn]['co_status'] = \
|
||||||
|
sensor_data['co_status']
|
||||||
|
self.device_data[sn]['smoke_status'] = \
|
||||||
|
sensor_data['smoke_status']
|
||||||
|
self.device_data[sn]['battery_health_state'] = \
|
||||||
|
sensor_data['battery_health_state']
|
||||||
|
# Temperature sensors
|
||||||
|
elif bucket["object_key"].startswith(
|
||||||
|
f"kryptonite.{sn}"):
|
||||||
|
self.device_data[sn]['name'] = self._wheres[
|
||||||
|
sensor_data['where_id']
|
||||||
|
]
|
||||||
|
if sensor_data.get('description', None):
|
||||||
|
self.device_data[sn]['name'] += \
|
||||||
|
f' ({sensor_data["description"]})'
|
||||||
|
self.device_data[sn]['name'] += ' Temperature'
|
||||||
|
self.device_data[sn]['temperature'] = \
|
||||||
|
sensor_data['current_temperature']
|
||||||
|
self.device_data[sn]['battery_level'] = \
|
||||||
|
sensor_data['battery_level']
|
||||||
|
|
||||||
def get_cameras(self):
|
# Cameras
|
||||||
r = self._session.get(
|
for camera in self.cameras:
|
||||||
f"{CAMERA_WEBAPI_BASE}/api/cameras."
|
r = self._session.get(
|
||||||
+ "get_owned_and_member_of_with_properties"
|
f"{API_URL}/dropcam/api/cameras/{camera}"
|
||||||
)
|
)
|
||||||
return r.json()["items"]
|
sensor_data = r.json()[0]
|
||||||
|
self.device_data[camera]['name'] = \
|
||||||
|
sensor_data["name"]
|
||||||
|
self.device_data[camera]['is_online'] = \
|
||||||
|
sensor_data["is_online"]
|
||||||
|
self.device_data[camera]['is_streaming'] = \
|
||||||
|
sensor_data["is_streaming"]
|
||||||
|
self.device_data[camera]['battery_voltage'] = \
|
||||||
|
sensor_data["rq_battery_battery_volt"]
|
||||||
|
self.device_data[camera]['ac_voltage'] = \
|
||||||
|
sensor_data["rq_battery_vbridge_volt"]
|
||||||
|
self.device_data[camera]['location'] = \
|
||||||
|
sensor_data["location"]
|
||||||
|
self.device_data[camera]['data_tier'] = \
|
||||||
|
sensor_data["properties"]["streaming.data-usage-tier"]
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to update, trying again')
|
||||||
|
self.update()
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to update, trying to log in again')
|
||||||
|
self.login()
|
||||||
|
self.update()
|
||||||
|
|
||||||
# def set_upload_quality(self, quality):
|
def thermostat_set_temperature(self, device_id, temp, temp_high=None):
|
||||||
# quality = str(quality)
|
if device_id not in self.thermostats:
|
||||||
# return self._set_properties("streaming.data-usage-tier", quality)
|
return
|
||||||
|
|
||||||
def turn_off(self):
|
try:
|
||||||
return self._set_properties("streaming.enabled", "false")
|
if temp_high is None:
|
||||||
|
self._session.post(
|
||||||
|
f"{self._czfe_url}/v5/put",
|
||||||
|
json={
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"object_key": f'shared.{device_id}',
|
||||||
|
"op": "MERGE",
|
||||||
|
"value": {"target_temperature": temp},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._session.post(
|
||||||
|
f"{self._czfe_url}/v5/put",
|
||||||
|
json={
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"object_key": f'shared.{device_id}',
|
||||||
|
"op": "MERGE",
|
||||||
|
"value": {
|
||||||
|
"target_temperature_low": temp,
|
||||||
|
"target_temperature_high": temp_high,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
|
)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to set temperature, trying again')
|
||||||
|
self.thermostat_set_temperature(device_id, temp, temp_high)
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to set temperature, trying to log in again')
|
||||||
|
self.login()
|
||||||
|
self.thermostat_set_temperature(device_id, temp, temp_high)
|
||||||
|
|
||||||
def turn_on(self):
|
def thermostat_set_mode(self, device_id, mode):
|
||||||
return self._set_properties("streaming.enabled", "true")
|
if device_id not in self.thermostats:
|
||||||
|
return
|
||||||
|
|
||||||
def get_image(self, now):
|
try:
|
||||||
r = self._session.get(
|
self._session.post(
|
||||||
f"{CAMERA_URL}/get_image?uuid={self._device_id}&cachebuster={now}"
|
f"{self._czfe_url}/v5/put",
|
||||||
)
|
json={
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"object_key": f'shared.{device_id}',
|
||||||
|
"op": "MERGE",
|
||||||
|
"value": {"target_temperature_type": mode},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
|
)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to set mode, trying again')
|
||||||
|
self.thermostat_set_mode(device_id, mode)
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to set mode, trying to log in again')
|
||||||
|
self.login()
|
||||||
|
self.thermostat_set_mode(device_id, mode)
|
||||||
|
|
||||||
return r.content
|
def thermostat_set_fan(self, device_id, date):
|
||||||
|
if device_id not in self.thermostats:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._session.post(
|
||||||
|
f"{self._czfe_url}/v5/put",
|
||||||
|
json={
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"object_key": f'device.{device_id}',
|
||||||
|
"op": "MERGE",
|
||||||
|
"value": {"fan_timer_timeout": date},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
|
)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to set fan, trying again')
|
||||||
|
self.thermostat_set_fan(device_id, date)
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to set fan, trying to log in again')
|
||||||
|
self.login()
|
||||||
|
self.thermostat_set_fan(device_id, date)
|
||||||
|
|
||||||
|
def thermostat_set_eco_mode(self, device_id, state):
|
||||||
|
if device_id not in self.thermostats:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
mode = 'manual-eco' if state else 'schedule'
|
||||||
|
self._session.post(
|
||||||
|
f"{self._czfe_url}/v5/put",
|
||||||
|
json={
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"object_key": f'device.{device_id}',
|
||||||
|
"op": "MERGE",
|
||||||
|
"value": {"eco": {"mode": mode}},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
|
)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to set eco, trying again')
|
||||||
|
self.thermostat_set_eco_mode(device_id, state)
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to set eco, trying to log in again')
|
||||||
|
self.login()
|
||||||
|
self.thermostat_set_eco_mode(device_id, state)
|
||||||
|
|
||||||
|
def _camera_set_properties(self, device_id, property, value):
|
||||||
|
if device_id not in self.cameras:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
r = self._session.post(
|
||||||
|
f"{CAMERA_WEBAPI_BASE}/api/dropcams.set_properties",
|
||||||
|
data={property: value, "uuid": device_id},
|
||||||
|
)
|
||||||
|
|
||||||
|
return r.json()["items"]
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to set camera property, trying again')
|
||||||
|
return self._camera_set_properties(device_id, property, value)
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to set camera property, ' +
|
||||||
|
'trying to log in again')
|
||||||
|
self.login()
|
||||||
|
return self._camera_set_properties(device_id, property, value)
|
||||||
|
|
||||||
|
def camera_turn_off(self, device_id):
|
||||||
|
if device_id not in self.cameras:
|
||||||
|
return
|
||||||
|
|
||||||
|
return self._set_properties(device_id, "streaming.enabled", "false")
|
||||||
|
|
||||||
|
def camera_turn_on(self, device_id):
|
||||||
|
if device_id not in self.cameras:
|
||||||
|
return
|
||||||
|
|
||||||
|
return self._set_properties(device_id, "streaming.enabled", "true")
|
||||||
|
|
||||||
|
def camera_get_image(self, device_id, now):
|
||||||
|
if device_id not in self.cameras:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
r = self._session.get(
|
||||||
|
f'{self._camera_url}/get_image?uuid={device_id}' +
|
||||||
|
f'&cachebuster={now}'
|
||||||
|
)
|
||||||
|
|
||||||
|
return r.content
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
_LOGGER.error(e)
|
||||||
|
_LOGGER.error('Failed to get camera image, trying again')
|
||||||
|
return self.camera_get_image(device_id, now)
|
||||||
|
except KeyError:
|
||||||
|
_LOGGER.debug('Failed to get camera image, trying to log in again')
|
||||||
|
self.login()
|
||||||
|
return self.camera_get_image(device_id, now)
|
||||||
|
@@ -1,44 +1,32 @@
|
|||||||
"""This component provides basic support for Foscam IP cameras."""
|
"""This component provides basic support for Foscam IP cameras."""
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from homeassistant.components.camera import (
|
||||||
|
Camera,
|
||||||
|
SUPPORT_ON_OFF,
|
||||||
|
)
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from homeassistant.components.camera import Camera, SUPPORT_ON_OFF
|
from .const import (
|
||||||
|
DOMAIN
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
)
|
||||||
from .api import NestCameraAPI
|
|
||||||
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_APIKEY
|
|
||||||
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_NAME = "Nest Camera"
|
|
||||||
DATA_KEY = "camera.badnest"
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass,
|
async def async_setup_platform(hass,
|
||||||
config,
|
config,
|
||||||
async_add_entities,
|
async_add_entities,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up a Nest Camera."""
|
"""Set up a Nest Camera."""
|
||||||
hass.data[DATA_KEY] = dict()
|
api = hass.data[DOMAIN]['api']
|
||||||
|
|
||||||
api = NestCameraAPI(
|
|
||||||
hass.data[DOMAIN][CONF_EMAIL],
|
|
||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
|
||||||
hass.data[DOMAIN][CONF_APIKEY]
|
|
||||||
)
|
|
||||||
|
|
||||||
# cameras = await hass.async_add_executor_job(nest.get_cameras())
|
|
||||||
cameras = []
|
cameras = []
|
||||||
_LOGGER.info("Adding cameras")
|
_LOGGER.info("Adding temperature sensors")
|
||||||
for camera in api.get_cameras():
|
for camera in api['cameras']:
|
||||||
_LOGGER.info("Adding nest cam uuid: %s", camera["uuid"])
|
_LOGGER.info(f"Adding nest camera uuid: {camera}")
|
||||||
device = NestCamera(camera["uuid"], api)
|
cameras.append(NestCamera(camera, api))
|
||||||
cameras.append(device)
|
|
||||||
hass.data[DATA_KEY][camera["uuid"]] = device
|
|
||||||
|
|
||||||
async_add_entities(cameras)
|
async_add_entities(cameras)
|
||||||
|
|
||||||
@@ -50,7 +38,6 @@ class NestCamera(Camera):
|
|||||||
"""Initialize a Nest camera."""
|
"""Initialize a Nest camera."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._uuid = uuid
|
self._uuid = uuid
|
||||||
api.set_device(self._uuid)
|
|
||||||
self._device = api
|
self._device = api
|
||||||
self._time_between_snapshots = timedelta(seconds=30)
|
self._time_between_snapshots = timedelta(seconds=30)
|
||||||
self._last_image = None
|
self._last_image = None
|
||||||
@@ -61,7 +48,7 @@ class NestCamera(Camera):
|
|||||||
"""Return information about the device."""
|
"""Return information about the device."""
|
||||||
return {
|
return {
|
||||||
"identifiers": {(DOMAIN, self._uuid)},
|
"identifiers": {(DOMAIN, self._uuid)},
|
||||||
"name": self.name,
|
"name": self._device.device_data[self._uuid]['name'],
|
||||||
"manufacturer": "Nest Labs",
|
"manufacturer": "Nest Labs",
|
||||||
"model": "Camera",
|
"model": "Camera",
|
||||||
}
|
}
|
||||||
@@ -78,20 +65,20 @@ class NestCamera(Camera):
|
|||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if on."""
|
"""Return true if on."""
|
||||||
return self._device.online
|
return self._device.device_data[self._uuid]['online']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_recording(self):
|
def is_recording(self):
|
||||||
return True
|
return True
|
||||||
"""Return true if the device is recording."""
|
"""Return true if the device is recording."""
|
||||||
return self._device.is_streaming
|
return self._device.device_data[self._uuid]['is_streaming']
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
self._device.turn_off()
|
self._device.camera_turn_off(self._uuid)
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
self._device.turn_on()
|
self._device.camera_turn_on(self._uuid)
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -106,7 +93,7 @@ class NestCamera(Camera):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of this camera."""
|
"""Return the name of this camera."""
|
||||||
return self._device.name
|
return self._device.device_data[self._uuid]['name']
|
||||||
|
|
||||||
def _ready_for_snapshot(self, now):
|
def _ready_for_snapshot(self, now):
|
||||||
return self._next_snapshot_at is None or now > self._next_snapshot_at
|
return self._next_snapshot_at is None or now > self._next_snapshot_at
|
||||||
@@ -115,8 +102,7 @@ class NestCamera(Camera):
|
|||||||
"""Return a still image response from the camera."""
|
"""Return a still image response from the camera."""
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
if self._ready_for_snapshot(now) or True:
|
if self._ready_for_snapshot(now) or True:
|
||||||
image = self._device.get_image(now)
|
image = self._device.camera_get_image(self._uuid, now)
|
||||||
# _LOGGER.info(image)
|
|
||||||
|
|
||||||
self._next_snapshot_at = now + self._time_between_snapshots
|
self._next_snapshot_at = now + self._time_between_snapshots
|
||||||
self._last_image = image
|
self._last_image = image
|
||||||
|
@@ -13,9 +13,9 @@ from homeassistant.components.climate.const import (
|
|||||||
HVAC_MODE_HEAT,
|
HVAC_MODE_HEAT,
|
||||||
HVAC_MODE_OFF,
|
HVAC_MODE_OFF,
|
||||||
SUPPORT_FAN_MODE,
|
SUPPORT_FAN_MODE,
|
||||||
|
SUPPORT_PRESET_MODE,
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||||
PRESET_AWAY,
|
|
||||||
PRESET_ECO,
|
PRESET_ECO,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
CURRENT_HVAC_HEAT,
|
CURRENT_HVAC_HEAT,
|
||||||
@@ -25,12 +25,11 @@ from homeassistant.components.climate.const import (
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
CONF_EMAIL,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .api import NestThermostatAPI
|
from .const import (
|
||||||
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_APIKEY
|
DOMAIN,
|
||||||
|
)
|
||||||
|
|
||||||
NEST_MODE_HEAT_COOL = "range"
|
NEST_MODE_HEAT_COOL = "range"
|
||||||
NEST_MODE_ECO = "eco"
|
NEST_MODE_ECO = "eco"
|
||||||
@@ -53,9 +52,7 @@ ACTION_NEST_TO_HASS = {
|
|||||||
|
|
||||||
MODE_NEST_TO_HASS = {v: k for k, v in MODE_HASS_TO_NEST.items()}
|
MODE_NEST_TO_HASS = {v: k for k, v in MODE_HASS_TO_NEST.items()}
|
||||||
|
|
||||||
PRESET_AWAY_AND_ECO = "Away and Eco"
|
PRESET_MODES = [PRESET_NONE, PRESET_ECO]
|
||||||
|
|
||||||
PRESET_MODES = [PRESET_NONE, PRESET_AWAY, PRESET_ECO, PRESET_AWAY_AND_ECO]
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -65,52 +62,63 @@ async def async_setup_platform(hass,
|
|||||||
async_add_entities,
|
async_add_entities,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up the Nest climate device."""
|
"""Set up the Nest climate device."""
|
||||||
nest = NestThermostatAPI(
|
api = hass.data[DOMAIN]['api']
|
||||||
hass.data[DOMAIN][CONF_EMAIL],
|
|
||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
|
||||||
hass.data[DOMAIN][CONF_APIKEY]
|
|
||||||
)
|
|
||||||
|
|
||||||
async_add_entities([NestClimate(nest)])
|
thermostats = []
|
||||||
|
_LOGGER.info("Adding thermostats")
|
||||||
|
for thermostat in api['thermostats']:
|
||||||
|
_LOGGER.info(f"Adding nest thermostat uuid: {thermostat}")
|
||||||
|
thermostats.append(NestClimate(thermostat, api))
|
||||||
|
|
||||||
|
async_add_entities(thermostats)
|
||||||
|
|
||||||
|
|
||||||
class NestClimate(ClimateDevice):
|
class NestClimate(ClimateDevice):
|
||||||
"""Representation of a Nest climate device."""
|
"""Representation of a Nest climate device."""
|
||||||
|
|
||||||
def __init__(self, api):
|
def __init__(self, device_id, api):
|
||||||
"""Initialize the thermostat."""
|
"""Initialize the thermostat."""
|
||||||
self._name = "Nest Thermostat"
|
self._name = "Nest Thermostat"
|
||||||
self._unit_of_measurement = TEMP_CELSIUS
|
self._unit_of_measurement = TEMP_CELSIUS
|
||||||
self._fan_modes = [FAN_ON, FAN_AUTO]
|
self._fan_modes = [FAN_ON, FAN_AUTO]
|
||||||
|
self.device_id = device_id
|
||||||
|
|
||||||
# Set the default supported features
|
# Set the default supported features
|
||||||
self._support_flags = SUPPORT_TARGET_TEMPERATURE
|
self._support_flags = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
|
||||||
# | SUPPORT_PRESET_MODE
|
|
||||||
|
|
||||||
# Not all nest devices support cooling and heating remove unused
|
# Not all nest devices support cooling and heating remove unused
|
||||||
self._operation_list = []
|
self._operation_list = []
|
||||||
|
|
||||||
self.device = api
|
self.device = api
|
||||||
|
|
||||||
if self.device.can_heat and self.device.can_cool:
|
if self.device.device_data[device_id]['can_heat'] \
|
||||||
|
and self.device.device_data[device_id]['can_cool']:
|
||||||
self._operation_list.append(HVAC_MODE_AUTO)
|
self._operation_list.append(HVAC_MODE_AUTO)
|
||||||
self._support_flags |= SUPPORT_TARGET_TEMPERATURE_RANGE
|
self._support_flags |= SUPPORT_TARGET_TEMPERATURE_RANGE
|
||||||
|
|
||||||
# Add supported nest thermostat features
|
# Add supported nest thermostat features
|
||||||
if self.device.can_heat:
|
if self.device.device_data[device_id]['can_heat']:
|
||||||
self._operation_list.append(HVAC_MODE_HEAT)
|
self._operation_list.append(HVAC_MODE_HEAT)
|
||||||
|
|
||||||
if self.device.can_cool:
|
if self.device.device_data[device_id]['can_cool']:
|
||||||
self._operation_list.append(HVAC_MODE_COOL)
|
self._operation_list.append(HVAC_MODE_COOL)
|
||||||
|
|
||||||
self._operation_list.append(HVAC_MODE_OFF)
|
self._operation_list.append(HVAC_MODE_OFF)
|
||||||
|
|
||||||
# feature of device
|
# feature of device
|
||||||
if self.device.has_fan:
|
if self.device.device_data[device_id]['has_fan']:
|
||||||
self._support_flags = self._support_flags | SUPPORT_FAN_MODE
|
self._support_flags = self._support_flags | SUPPORT_FAN_MODE
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return an unique ID."""
|
||||||
|
return self.device_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return an friendly name."""
|
||||||
|
return self.device.device_data[self.device_id]['name']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Return the list of supported features."""
|
"""Return the list of supported features."""
|
||||||
@@ -121,11 +129,6 @@ class NestClimate(ClimateDevice):
|
|||||||
"""Return the polling state."""
|
"""Return the polling state."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the climate device."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self):
|
def temperature_unit(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
@@ -134,48 +137,63 @@ class NestClimate(ClimateDevice):
|
|||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
return self.device.current_temperature
|
return self.device.device_data[self.device_id]['current_temperature']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_humidity(self):
|
||||||
|
"""Return the current humidity."""
|
||||||
|
return self.device.device_data[self.device_id]['current_humidity']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self):
|
||||||
"""Return the temperature we try to reach."""
|
"""Return the temperature we try to reach."""
|
||||||
if self.device.mode not in (NEST_MODE_HEAT_COOL, NEST_MODE_ECO):
|
if self.device.device_data[self.device_id]['mode'] \
|
||||||
return self.device.target_temperature
|
!= NEST_MODE_HEAT_COOL \
|
||||||
|
and not self.device.device_data[self.device_id]['eco']:
|
||||||
|
return \
|
||||||
|
self.device.device_data[self.device_id]['target_temperature']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_high(self):
|
def target_temperature_high(self):
|
||||||
"""Return the highbound target temperature we try to reach."""
|
"""Return the highbound target temperature we try to reach."""
|
||||||
if self.device.mode == NEST_MODE_ECO:
|
if self.device.device_data[self.device_id]['mode'] \
|
||||||
# TODO: Grab properly
|
== NEST_MODE_HEAT_COOL \
|
||||||
return None
|
and not self.device.device_data[self.device_id]['eco']:
|
||||||
if self.device.mode == NEST_MODE_HEAT_COOL:
|
return \
|
||||||
return self.device.target_temperature_high
|
self.device. \
|
||||||
|
device_data[self.device_id]['target_temperature_high']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_low(self):
|
def target_temperature_low(self):
|
||||||
"""Return the lowbound target temperature we try to reach."""
|
"""Return the lowbound target temperature we try to reach."""
|
||||||
if self.device.mode == NEST_MODE_ECO:
|
if self.device.device_data[self.device_id]['mode'] \
|
||||||
# TODO: Grab properly
|
== NEST_MODE_HEAT_COOL \
|
||||||
return None
|
and not self.device.device_data[self.device_id]['eco']:
|
||||||
if self.device.mode == NEST_MODE_HEAT_COOL:
|
return \
|
||||||
return self.device.target_temperature_low
|
self.device. \
|
||||||
|
device_data[self.device_id]['target_temperature_low']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self):
|
def hvac_action(self):
|
||||||
"""Return current operation ie. heat, cool, idle."""
|
"""Return current operation ie. heat, cool, idle."""
|
||||||
return ACTION_NEST_TO_HASS[self.device.get_action()]
|
return ACTION_NEST_TO_HASS[
|
||||||
|
self.device.device_data[self.device_id]['action']
|
||||||
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self):
|
||||||
"""Return hvac target hvac state."""
|
"""Return hvac target hvac state."""
|
||||||
if self.device.mode is None or self.device.mode == NEST_MODE_ECO:
|
if self.device.device_data[self.device_id]['mode'] is None \
|
||||||
|
or self.device.device_data[self.device_id]['eco']:
|
||||||
# We assume the first operation in operation list is the main one
|
# We assume the first operation in operation list is the main one
|
||||||
return self._operation_list[0]
|
return self._operation_list[0]
|
||||||
|
|
||||||
return MODE_NEST_TO_HASS[self.device.mode]
|
return MODE_NEST_TO_HASS[
|
||||||
|
self.device.device_data[self.device_id]['mode']
|
||||||
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_modes(self):
|
def hvac_modes(self):
|
||||||
@@ -185,16 +203,10 @@ class NestClimate(ClimateDevice):
|
|||||||
@property
|
@property
|
||||||
def preset_mode(self):
|
def preset_mode(self):
|
||||||
"""Return current preset mode."""
|
"""Return current preset mode."""
|
||||||
if self.device.away and self.device.mode == NEST_MODE_ECO:
|
if self.device.device_data[self.device_id]['eco']:
|
||||||
return PRESET_AWAY_AND_ECO
|
|
||||||
|
|
||||||
if self.device.away:
|
|
||||||
return PRESET_AWAY
|
|
||||||
|
|
||||||
if self.device.mode == NEST_MODE_ECO:
|
|
||||||
return PRESET_ECO
|
return PRESET_ECO
|
||||||
|
|
||||||
return None
|
return PRESET_NONE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preset_modes(self):
|
def preset_modes(self):
|
||||||
@@ -204,16 +216,19 @@ class NestClimate(ClimateDevice):
|
|||||||
@property
|
@property
|
||||||
def fan_mode(self):
|
def fan_mode(self):
|
||||||
"""Return whether the fan is on."""
|
"""Return whether the fan is on."""
|
||||||
if self.device.has_fan:
|
if self.device.device_data[self.device_id]['has_fan']:
|
||||||
# Return whether the fan is on
|
# Return whether the fan is on
|
||||||
return FAN_ON if self.device.fan else FAN_AUTO
|
if self.device.device_data[self.device_id]['fan']:
|
||||||
|
return FAN_ON
|
||||||
|
else:
|
||||||
|
return FAN_AUTO
|
||||||
# No Fan available so disable slider
|
# No Fan available so disable slider
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_modes(self):
|
def fan_modes(self):
|
||||||
"""Return the list of available fan modes."""
|
"""Return the list of available fan modes."""
|
||||||
if self.device.has_fan:
|
if self.device.device_data[self.device_id]['has_fan']:
|
||||||
return self._fan_modes
|
return self._fan_modes
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -222,42 +237,52 @@ class NestClimate(ClimateDevice):
|
|||||||
temp = None
|
temp = None
|
||||||
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||||
target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
if self.device.mode == NEST_MODE_HEAT_COOL:
|
if self.device.device_data[self.device_id]['mode'] == \
|
||||||
|
NEST_MODE_HEAT_COOL:
|
||||||
if target_temp_low is not None and target_temp_high is not None:
|
if target_temp_low is not None and target_temp_high is not None:
|
||||||
self.device.set_temp(target_temp_low, target_temp_high)
|
self.device.thermostat_set_temperature(
|
||||||
|
self.device_id,
|
||||||
|
target_temp_low,
|
||||||
|
target_temp_high,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
temp = kwargs.get(ATTR_TEMPERATURE)
|
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||||
if temp is not None:
|
if temp is not None:
|
||||||
self.device.set_temp(temp)
|
self.device.thermostat_set_temperature(
|
||||||
|
self.device_id,
|
||||||
|
temp,
|
||||||
|
)
|
||||||
|
|
||||||
def set_hvac_mode(self, hvac_mode):
|
def set_hvac_mode(self, hvac_mode):
|
||||||
"""Set operation mode."""
|
"""Set operation mode."""
|
||||||
self.device.set_mode(MODE_HASS_TO_NEST[hvac_mode])
|
self.device.thermostat_set_mode(
|
||||||
|
self.device_id,
|
||||||
|
MODE_HASS_TO_NEST[hvac_mode],
|
||||||
|
)
|
||||||
|
|
||||||
def set_fan_mode(self, fan_mode):
|
def set_fan_mode(self, fan_mode):
|
||||||
"""Turn fan on/off."""
|
"""Turn fan on/off."""
|
||||||
if self.device.has_fan:
|
if self.device.device_data[self.device_id]['has_fan']:
|
||||||
if fan_mode == "on":
|
if fan_mode == "on":
|
||||||
self.device.set_fan(int(datetime.now().timestamp() + 60 * 30))
|
self.device.thermostat_set_fan(
|
||||||
|
self.device_id,
|
||||||
|
int(datetime.now().timestamp() + 60 * 30),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.device.set_fan(0)
|
self.device.thermostat_set_fan(
|
||||||
|
self.device_id,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
def set_preset_mode(self, preset_mode):
|
def set_preset_mode(self, preset_mode):
|
||||||
"""Set preset mode."""
|
"""Set preset mode."""
|
||||||
need_away = preset_mode in (PRESET_AWAY, PRESET_AWAY_AND_ECO)
|
need_eco = preset_mode == PRESET_ECO
|
||||||
need_eco = preset_mode in (PRESET_ECO, PRESET_AWAY_AND_ECO)
|
|
||||||
is_away = self.device.away
|
|
||||||
is_eco = self.device.mode == NEST_MODE_ECO
|
|
||||||
|
|
||||||
if is_away != need_away:
|
if need_eco != self.device.device_data[self.device_id]['eco']:
|
||||||
pass
|
self.device.thermostat_set_eco_mode(
|
||||||
# self.device.set_away()
|
self.device_id,
|
||||||
|
need_eco,
|
||||||
if is_eco != need_eco:
|
)
|
||||||
if need_eco:
|
|
||||||
self.device.set_eco_mode()
|
|
||||||
else:
|
|
||||||
self.device.mode = MODE_HASS_TO_NEST[self._operation_list[0]]
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Updates data"""
|
"""Updates data"""
|
||||||
|
@@ -1,4 +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'
|
||||||
|
123
custom_components/badnest/sensor.py
Normal file
123
custom_components/badnest/sensor.py
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
from homeassistant.const import (
|
||||||
|
ATTR_BATTERY_LEVEL,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
TEMP_CELSIUS
|
||||||
|
)
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
PROTECT_SENSOR_TYPES = [
|
||||||
|
"co_status",
|
||||||
|
"smoke_status",
|
||||||
|
"battery_health_state"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_platform(hass,
|
||||||
|
config,
|
||||||
|
async_add_entities,
|
||||||
|
discovery_info=None):
|
||||||
|
"""Set up the Nest climate device."""
|
||||||
|
api = hass.data[DOMAIN]['api']
|
||||||
|
|
||||||
|
temperature_sensors = []
|
||||||
|
_LOGGER.info("Adding temperature sensors")
|
||||||
|
for sensor in api['temperature_sensors']:
|
||||||
|
_LOGGER.info(f"Adding nest temp sensor uuid: {sensor}")
|
||||||
|
temperature_sensors.append(NestTemperatureSensor(sensor, api))
|
||||||
|
|
||||||
|
async_add_entities(temperature_sensors)
|
||||||
|
|
||||||
|
protect_sensors = []
|
||||||
|
_LOGGER.info("Adding protect sensors")
|
||||||
|
for sensor in api['protects']:
|
||||||
|
_LOGGER.info(f"Adding nest protect sensor uuid: {sensor}")
|
||||||
|
for sensor_type in PROTECT_SENSOR_TYPES:
|
||||||
|
protect_sensors.append(NestProtectSensor(sensor, sensor_type, api))
|
||||||
|
|
||||||
|
async_add_entities(protect_sensors)
|
||||||
|
|
||||||
|
|
||||||
|
class NestTemperatureSensor(Entity):
|
||||||
|
"""Implementation of the Nest Temperature Sensor."""
|
||||||
|
|
||||||
|
def __init__(self, device_id, api):
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
self._name = "Nest Temperature Sensor"
|
||||||
|
self._unit_of_measurement = TEMP_CELSIUS
|
||||||
|
self.device_id = device_id
|
||||||
|
self.device = api
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return an unique ID."""
|
||||||
|
return self.device_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the sensor."""
|
||||||
|
return self.device.device_data[self.device_id]['name']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
"""Return the state of the sensor."""
|
||||||
|
return self.device.device_data[self.device_id]['temperature']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class of this entity."""
|
||||||
|
return DEVICE_CLASS_TEMPERATURE
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unit_of_measurement(self):
|
||||||
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
|
return self._unit_of_measurement
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Get the latest data from the DHT and updates the states."""
|
||||||
|
self.device.update()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the state attributes."""
|
||||||
|
return {
|
||||||
|
ATTR_BATTERY_LEVEL:
|
||||||
|
self.device.device_data[self.device_id]['battery_level']
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class NestProtectSensor(Entity):
|
||||||
|
"""Implementation of the Nest Protect sensor."""
|
||||||
|
|
||||||
|
def __init__(self, device_id, sensor_type, api):
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
self._name = "Nest Protect Sensor"
|
||||||
|
self.device_id = device_id
|
||||||
|
self._sensor_type = sensor_type
|
||||||
|
self.device = api
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return an unique ID."""
|
||||||
|
return self.device_id + '_' + self._sensor_type
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the sensor."""
|
||||||
|
return self.device.device_data[self.device_id]['name'] + \
|
||||||
|
f' {self._sensor_type}'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
"""Return the state of the sensor."""
|
||||||
|
return self.device.device_data[self.device_id][self._sensor_type]
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Get the latest data from the Protect and updates the states."""
|
||||||
|
self.device.update()
|
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"name": "Bad Nest Thermostat",
|
"name": "Bad Nest",
|
||||||
"domains": ["climate", "camera"]
|
"domains": ["climate", "camera", "sensor"]
|
||||||
}
|
}
|
||||||
|
39
info.md
39
info.md
@@ -4,23 +4,39 @@ A bad Nest thermostat and camera integration that uses the web api to work after
|
|||||||
|
|
||||||
## Why is it bad?
|
## Why is it bad?
|
||||||
|
|
||||||
This isn't an advertised or public API, it's still better than web scraping, but will never be as good as the original API
|
This isn't an advertised or public API, it's still better than web scraping, but will never be as reliable as the original API
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Doesn't use the now defunct Works with Nest API
|
||||||
|
- Works with migrated/new accounts via Google auth
|
||||||
|
- Works with old via Nest auth
|
||||||
|
- Nest Protect support
|
||||||
|
- Nest Thermostat support
|
||||||
|
- Nest Thermostat Sensor support
|
||||||
|
- Nest Camera support
|
||||||
|
|
||||||
## Drawbacks
|
## Drawbacks
|
||||||
|
|
||||||
- No proper error handling
|
|
||||||
- Won't work with 2FA enabled accounts (Works with 2fa Google Accounts)
|
- Won't work with 2FA enabled accounts (Works with 2fa Google Accounts)
|
||||||
- Tested with a single thermostat, I have no other devices to test with
|
- Tested with a single thermostat, I have no other devices to test with
|
||||||
- Camera integration is untested by me
|
- Camera integration is untested by me
|
||||||
|
- Nest Protect integration is untested by me
|
||||||
- Nest could change their webapp api at any time, making this defunct
|
- Nest could change their webapp api at any time, making this defunct
|
||||||
- Thermostat presets don't work (Eco, Away)
|
|
||||||
|
|
||||||
## Example configuration.yaml - When you're not using the Google Auth Login
|
## Configuration
|
||||||
|
|
||||||
|
The camera's region is one of `us` or `eu` depending on your region.
|
||||||
|
If you're not in the US or EU, you should be able to add your
|
||||||
|
two-character country code, and it should work.
|
||||||
|
|
||||||
|
### Example configuration.yaml - When you're not using the Google Auth Login
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
badnest:
|
badnest:
|
||||||
email: email@domain.com
|
email: email@domain.com
|
||||||
password: !secret nest_password
|
password: !secret nest_password
|
||||||
|
region: us
|
||||||
|
|
||||||
climate:
|
climate:
|
||||||
- platform: badnest
|
- platform: badnest
|
||||||
@@ -28,15 +44,18 @@ climate:
|
|||||||
|
|
||||||
camera:
|
camera:
|
||||||
- platform: badnest
|
- platform: badnest
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: badnest
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example configuration.yaml - When you are using the Google Auth Login
|
### Example configuration.yaml - When you are using the Google Auth Login
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
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#"
|
region: us
|
||||||
|
|
||||||
climate:
|
climate:
|
||||||
- platform: badnest
|
- platform: badnest
|
||||||
@@ -44,11 +63,14 @@ climate:
|
|||||||
|
|
||||||
camera:
|
camera:
|
||||||
- platform: badnest
|
- platform: badnest
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: badnest
|
||||||
```
|
```
|
||||||
|
|
||||||
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).
|
||||||
@@ -60,6 +82,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`.
|
|
||||||
|
Reference in New Issue
Block a user