mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-09-07 00:11:52 +01:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ed105b74c1 | ||
|
52d381f471 | ||
|
074a2fdf44 | ||
|
87c65ab23e | ||
|
7ac7989bf4 | ||
|
f2643d4427 | ||
|
474fb1adc6 | ||
|
9fb3e12061 | ||
|
9de843188f | ||
|
12d2866676 | ||
|
33baabdd24 | ||
|
87dbe0bcf7 | ||
|
6357504e96 | ||
|
21d7c00e50 | ||
|
25b07f40e4 | ||
|
543973b7f9 | ||
|
4602092449 | ||
|
52ce92df7e |
27
.github/workflows/release.yml
vendored
27
.github/workflows/release.yml
vendored
@@ -1,20 +1,17 @@
|
||||
name: Releases
|
||||
name: Release uploader
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
on: release
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
upload_release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Package up a release
|
||||
run: zip -r ../badnest.zip hacs.json info.md custom_components
|
||||
- uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifact: ../badnest.zip
|
||||
artifactContentType: application/zip
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Pull source
|
||||
uses: actions/checkout@v1
|
||||
- name: Package up a release
|
||||
run: zip -r badnest.zip hacs.json info.md custom_components
|
||||
- uses: JasonEtco/upload-to-release@master
|
||||
with:
|
||||
args: badnest.zip
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import requests
|
||||
import logging
|
||||
|
||||
API_URL = "https://home.nest.com"
|
||||
CAMERA_WEBAPI_BASE = "https://webapi.camera.home.nest.com"
|
||||
@@ -8,19 +9,26 @@ USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) " \
|
||||
"Chrome/75.0.3770.100 Safari/537.36"
|
||||
URL_JWT = "https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt"
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NestAPI:
|
||||
def __init__(self, email, password, issue_token, cookie, api_key):
|
||||
def __init__(self,
|
||||
email,
|
||||
password,
|
||||
issue_token,
|
||||
cookie,
|
||||
api_key,
|
||||
device_id=None):
|
||||
self._user_id = None
|
||||
self._access_token = None
|
||||
self._session = requests.Session()
|
||||
self._session.headers.update({"Referer": "https://home.nest.com/"})
|
||||
self._device_id = None
|
||||
self._device_id = device_id
|
||||
if not email and not password:
|
||||
self._login_google(issue_token, cookie, api_key)
|
||||
else:
|
||||
self._login_nest(email, password)
|
||||
self.update()
|
||||
|
||||
def _login_nest(self, email, password):
|
||||
r = self._session.post(
|
||||
@@ -56,19 +64,22 @@ class NestAPI:
|
||||
self._user_id = r.json()['claims']['subject']['nestId']['id']
|
||||
self._access_token = r.json()['jwt']
|
||||
|
||||
def update(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class NestThermostatAPI(NestAPI):
|
||||
def __init__(self, email, password, issue_token, cookie, api_key):
|
||||
def __init__(self,
|
||||
email,
|
||||
password,
|
||||
issue_token,
|
||||
cookie,
|
||||
api_key,
|
||||
device_id=None):
|
||||
super(NestThermostatAPI, self).__init__(
|
||||
email,
|
||||
password,
|
||||
issue_token,
|
||||
cookie,
|
||||
api_key)
|
||||
self._shared_id = None
|
||||
api_key,
|
||||
device_id)
|
||||
self._czfe_url = None
|
||||
self._compressor_lockout_enabled = None
|
||||
self._compressor_lockout_time = None
|
||||
@@ -87,6 +98,24 @@ class NestThermostatAPI(NestAPI):
|
||||
self.target_temperature_high = None
|
||||
self.target_temperature_low = None
|
||||
self.current_humidity = None
|
||||
self.update()
|
||||
|
||||
def get_devices(self):
|
||||
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}"},
|
||||
)
|
||||
devices = []
|
||||
buckets = r.json()['updated_buckets'][0]['value']['buckets']
|
||||
for bucket in buckets:
|
||||
if bucket.startswith('device.'):
|
||||
devices.append(bucket.replace('device.', ''))
|
||||
|
||||
return devices
|
||||
|
||||
def get_action(self):
|
||||
if self._hvac_ac_state:
|
||||
@@ -109,8 +138,7 @@ class NestThermostatAPI(NestAPI):
|
||||
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"]
|
||||
if bucket["object_key"].startswith(f"shared.{self._device_id}"):
|
||||
thermostat_data = bucket["value"]
|
||||
self.current_temperature = \
|
||||
thermostat_data["current_temperature"]
|
||||
@@ -131,8 +159,7 @@ class NestThermostatAPI(NestAPI):
|
||||
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"]
|
||||
elif bucket["object_key"].startswith(f"device.{self._device_id}"):
|
||||
thermostat_data = bucket["value"]
|
||||
self._time_to_target = thermostat_data["time_to_target"]
|
||||
self._fan_timer_timeout = thermostat_data["fan_timer_timeout"]
|
||||
@@ -148,7 +175,7 @@ class NestThermostatAPI(NestAPI):
|
||||
json={
|
||||
"objects": [
|
||||
{
|
||||
"object_key": self._shared_id,
|
||||
"object_key": f'shared.{self._device_id}',
|
||||
"op": "MERGE",
|
||||
"value": {"target_temperature": temp},
|
||||
}
|
||||
@@ -162,7 +189,7 @@ class NestThermostatAPI(NestAPI):
|
||||
json={
|
||||
"objects": [
|
||||
{
|
||||
"object_key": self._shared_id,
|
||||
"object_key": f'shared.{self._device_id}',
|
||||
"op": "MERGE",
|
||||
"value": {
|
||||
"target_temperature_low": temp,
|
||||
@@ -180,7 +207,7 @@ class NestThermostatAPI(NestAPI):
|
||||
json={
|
||||
"objects": [
|
||||
{
|
||||
"object_key": self._shared_id,
|
||||
"object_key": f'shared.{self._device_id}',
|
||||
"op": "MERGE",
|
||||
"value": {"target_temperature_type": mode},
|
||||
}
|
||||
@@ -195,7 +222,7 @@ class NestThermostatAPI(NestAPI):
|
||||
json={
|
||||
"objects": [
|
||||
{
|
||||
"object_key": self._device_id,
|
||||
"object_key": f'device.{self._device_id}',
|
||||
"op": "MERGE",
|
||||
"value": {"fan_timer_timeout": date},
|
||||
}
|
||||
@@ -210,7 +237,7 @@ class NestThermostatAPI(NestAPI):
|
||||
json={
|
||||
"objects": [
|
||||
{
|
||||
"object_key": self._device_id,
|
||||
"object_key": f'device.{self._device_id}',
|
||||
"op": "MERGE",
|
||||
"value": {"eco": {"mode": "manual-eco"}},
|
||||
}
|
||||
@@ -220,6 +247,60 @@ class NestThermostatAPI(NestAPI):
|
||||
)
|
||||
|
||||
|
||||
class NestTemperatureSensorAPI(NestAPI):
|
||||
def __init__(self,
|
||||
email,
|
||||
password,
|
||||
issue_token,
|
||||
cookie,
|
||||
api_key,
|
||||
device_id=None):
|
||||
super(NestTemperatureSensorAPI, self).__init__(
|
||||
email,
|
||||
password,
|
||||
issue_token,
|
||||
cookie,
|
||||
api_key,
|
||||
device_id)
|
||||
self.temperature = None
|
||||
self._device_id = device_id
|
||||
self.update()
|
||||
|
||||
def get_devices(self):
|
||||
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}"},
|
||||
)
|
||||
devices = []
|
||||
buckets = r.json()['updated_buckets'][0]['value']['buckets']
|
||||
for bucket in buckets:
|
||||
if bucket.startswith('kryptonite.'):
|
||||
devices.append(bucket.replace('kryptonite.', ''))
|
||||
|
||||
return devices
|
||||
|
||||
def update(self):
|
||||
r = self._session.post(
|
||||
f"{API_URL}/api/0.1/user/{self._user_id}/app_launch",
|
||||
json={
|
||||
"known_bucket_types": ["kryptonite"],
|
||||
"known_bucket_versions": [],
|
||||
},
|
||||
headers={"Authorization": f"Basic {self._access_token}"},
|
||||
)
|
||||
|
||||
for bucket in r.json()["updated_buckets"]:
|
||||
if bucket["object_key"].startswith(
|
||||
f"kryptonite.{self._device_id}"):
|
||||
sensor_data = bucket["value"]
|
||||
self.temperature = sensor_data["current_temperature"]
|
||||
self.battery_level = sensor_data["battery_level"]
|
||||
|
||||
|
||||
class NestCameraAPI(NestAPI):
|
||||
def __init__(self, email, password, issue_token, cookie, api_key):
|
||||
super(NestCameraAPI, self).__init__(
|
||||
@@ -240,6 +321,7 @@ class NestCameraAPI(NestAPI):
|
||||
self.battery_voltage = None
|
||||
self.ac_voltge = None
|
||||
self.data_tier = None
|
||||
self.update()
|
||||
|
||||
def set_device(self, uuid):
|
||||
self._device_id = uuid
|
||||
|
@@ -1,5 +1,6 @@
|
||||
"""Demo platform that offers a fake climate device."""
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
from homeassistant.components.climate import ClimateDevice
|
||||
from homeassistant.components.climate.const import (
|
||||
@@ -56,13 +57,15 @@ PRESET_AWAY_AND_ECO = "Away and Eco"
|
||||
|
||||
PRESET_MODES = [PRESET_NONE, PRESET_AWAY, PRESET_ECO, PRESET_AWAY_AND_ECO]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(hass,
|
||||
config,
|
||||
async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Nest climate device."""
|
||||
nest = NestThermostatAPI(
|
||||
api = NestThermostatAPI(
|
||||
hass.data[DOMAIN][CONF_EMAIL],
|
||||
hass.data[DOMAIN][CONF_PASSWORD],
|
||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||
@@ -70,17 +73,31 @@ async def async_setup_platform(hass,
|
||||
hass.data[DOMAIN][CONF_APIKEY]
|
||||
)
|
||||
|
||||
async_add_entities([NestClimate(nest)])
|
||||
thermostats = []
|
||||
_LOGGER.info("Adding thermostats")
|
||||
for thermostat in api.get_devices():
|
||||
_LOGGER.info(f"Adding nest thermostat uuid: {thermostat}")
|
||||
thermostats.append(NestClimate(thermostat, NestThermostatAPI(
|
||||
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],
|
||||
thermostat
|
||||
)))
|
||||
|
||||
async_add_entities(thermostats)
|
||||
|
||||
|
||||
class NestClimate(ClimateDevice):
|
||||
"""Representation of a Nest climate device."""
|
||||
|
||||
def __init__(self, api):
|
||||
def __init__(self, device_id, api):
|
||||
"""Initialize the thermostat."""
|
||||
self._name = "Nest Thermostat"
|
||||
self._unit_of_measurement = TEMP_CELSIUS
|
||||
self._fan_modes = [FAN_ON, FAN_AUTO]
|
||||
self.device_id = device_id
|
||||
|
||||
# Set the default supported features
|
||||
self._support_flags = SUPPORT_TARGET_TEMPERATURE
|
||||
@@ -108,6 +125,11 @@ class NestClimate(ClimateDevice):
|
||||
if self.device.has_fan:
|
||||
self._support_flags = self._support_flags | SUPPORT_FAN_MODE
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return an unique ID."""
|
||||
return self.device_id
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
@@ -121,7 +143,7 @@ class NestClimate(ClimateDevice):
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the climate device."""
|
||||
return self._name
|
||||
return self.device_id
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
@@ -133,6 +155,11 @@ class NestClimate(ClimateDevice):
|
||||
"""Return the current temperature."""
|
||||
return self.device.current_temperature
|
||||
|
||||
@property
|
||||
def current_humidity(self):
|
||||
"""Return the current humidity."""
|
||||
return self.device.current_humidity
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
"""Return the temperature we try to reach."""
|
||||
|
88
custom_components/badnest/sensor.py
Normal file
88
custom_components/badnest/sensor.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .api import NestTemperatureSensorAPI
|
||||
from .const import DOMAIN, CONF_APIKEY, CONF_COOKIE, CONF_ISSUE_TOKEN
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
CONF_EMAIL,
|
||||
CONF_PASSWORD,
|
||||
TEMP_CELSIUS
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(hass,
|
||||
config,
|
||||
async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Nest climate device."""
|
||||
api = NestTemperatureSensorAPI(
|
||||
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]
|
||||
)
|
||||
|
||||
sensors = []
|
||||
_LOGGER.info("Adding temperature sensors")
|
||||
for sensor in api.get_devices():
|
||||
_LOGGER.info(f"Adding nest temp sensor uuid: {sensor}")
|
||||
sensors.append(
|
||||
NestTemperatureSensor(
|
||||
sensor,
|
||||
NestTemperatureSensorAPI(
|
||||
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],
|
||||
sensor
|
||||
)))
|
||||
|
||||
async_add_entities(sensors)
|
||||
|
||||
|
||||
class NestTemperatureSensor(Entity):
|
||||
"""Implementation of the DHT 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 name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self.device_id
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self.device.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.battery_level}
|
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"name": "Bad Nest Thermostat",
|
||||
"domains": ["climate", "camera"]
|
||||
"domains": ["climate", "camera", "sensor"]
|
||||
}
|
||||
|
10
info.md
10
info.md
@@ -9,11 +9,11 @@ This isn't an advertised or public API, it's still better than web scraping, but
|
||||
## Drawbacks
|
||||
|
||||
- No proper error handling
|
||||
- Won't work with 2FA enabled 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
|
||||
- Camera integration is untested by me
|
||||
- Nest could change their webapp api at any time, making this defunct
|
||||
- Presets don't work (Eco, Away)
|
||||
- Thermostat presets don't work (Eco, Away)
|
||||
|
||||
## Example configuration.yaml - When you're not using the Google Auth Login
|
||||
|
||||
@@ -28,6 +28,9 @@ climate:
|
||||
|
||||
camera:
|
||||
- platform: badnest
|
||||
|
||||
sensor:
|
||||
- platform: badnest
|
||||
```
|
||||
|
||||
## Example configuration.yaml - When you are using the Google Auth Login
|
||||
@@ -44,6 +47,9 @@ climate:
|
||||
|
||||
camera:
|
||||
- platform: badnest
|
||||
|
||||
sensor:
|
||||
- platform: badnest
|
||||
```
|
||||
|
||||
Google Login support added with many thanks to: chrisjshull from <https://github.com/chrisjshull/homebridge-nest/>
|
||||
|
Reference in New Issue
Block a user