mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-09-09 16:01:52 +01:00
Fixup flake8 violations
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
from datetime import time, timedelta, datetime
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
API_URL = 'https://home.nest.com'
|
||||
|
||||
|
||||
class NestAPI():
|
||||
def __init__(self, email, password):
|
||||
self._user_id = None
|
||||
@@ -50,13 +48,14 @@ class NestAPI():
|
||||
return 'off'
|
||||
|
||||
def update(self):
|
||||
r = requests.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}'
|
||||
})
|
||||
r = requests.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']
|
||||
|
||||
@@ -64,15 +63,21 @@ class NestAPI():
|
||||
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.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.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.'):
|
||||
@@ -85,76 +90,80 @@ class NestAPI():
|
||||
self.current_humidity = thermostat_data['current_humidity']
|
||||
self.away = thermostat_data['home_away_input']
|
||||
|
||||
def set_temp(self, temp, temp_high = None):
|
||||
def set_temp(self, temp, temp_high=None):
|
||||
if temp_high is None:
|
||||
requests.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}'
|
||||
})
|
||||
requests.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:
|
||||
requests.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}'
|
||||
})
|
||||
|
||||
requests.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):
|
||||
requests.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}'
|
||||
})
|
||||
requests.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):
|
||||
requests.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}'
|
||||
})
|
||||
requests.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):
|
||||
requests.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}'
|
||||
})
|
||||
requests.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}'
|
||||
})
|
||||
|
Reference in New Issue
Block a user