From 8d022bd74607f3f6bc7bb6953a5d3cc01cf7aecf Mon Sep 17 00:00:00 2001 From: Jacob McSwain Date: Sat, 19 Oct 2019 14:27:31 -0500 Subject: [PATCH] Fixup flake8 violations --- custom_components/badnest/__init__.py | 1 + custom_components/badnest/api.py | 171 ++++++++++++++------------ custom_components/badnest/climate.py | 17 ++- custom_components/badnest/const.py | 2 +- 4 files changed, 100 insertions(+), 91 deletions(-) diff --git a/custom_components/badnest/__init__.py b/custom_components/badnest/__init__.py index d4e665d..8d1a3ab 100644 --- a/custom_components/badnest/__init__.py +++ b/custom_components/badnest/__init__.py @@ -19,6 +19,7 @@ CONFIG_SCHEMA = vol.Schema( extra=vol.ALLOW_EXTRA, ) + def setup(hass, config): """Set up the asuswrt component.""" if config.get(DOMAIN) is not None: diff --git a/custom_components/badnest/api.py b/custom_components/badnest/api.py index ef0e0f0..deb9251 100644 --- a/custom_components/badnest/api.py +++ b/custom_components/badnest/api.py @@ -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}' + }) diff --git a/custom_components/badnest/climate.py b/custom_components/badnest/climate.py index 800bc34..ffac6b9 100644 --- a/custom_components/badnest/climate.py +++ b/custom_components/badnest/climate.py @@ -11,7 +11,6 @@ from homeassistant.components.climate.const import ( HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF, - SUPPORT_PRESET_MODE, SUPPORT_FAN_MODE, SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE, @@ -22,9 +21,8 @@ from homeassistant.components.climate.const import ( CURRENT_HVAC_IDLE, CURRENT_HVAC_COOL, ) -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS -from .api import NestAPI from .const import DOMAIN NEST_MODE_HEAT_COOL = "range" @@ -52,6 +50,7 @@ PRESET_AWAY_AND_ECO = "Away and Eco" PRESET_MODES = [PRESET_NONE, PRESET_AWAY, PRESET_ECO, PRESET_AWAY_AND_ECO] + def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Nest climate device.""" add_entities( @@ -71,7 +70,8 @@ class ShittyNestClimate(ClimateDevice): self._fan_modes = [FAN_ON, FAN_AUTO] # Set the default supported features - self._support_flags = SUPPORT_TARGET_TEMPERATURE #| SUPPORT_PRESET_MODE + self._support_flags = SUPPORT_TARGET_TEMPERATURE + # | SUPPORT_PRESET_MODE # Not all nest devices support cooling and heating remove unused self._operation_list = [] @@ -80,7 +80,7 @@ class ShittyNestClimate(ClimateDevice): if self.device.can_heat and self.device.can_cool: self._operation_list.append(HVAC_MODE_AUTO) - self._support_flags = self._support_flags | SUPPORT_TARGET_TEMPERATURE_RANGE + self._support_flags |= SUPPORT_TARGET_TEMPERATURE_RANGE # Add supported nest thermostat features if self.device.can_heat: @@ -131,7 +131,7 @@ class ShittyNestClimate(ClimateDevice): def target_temperature_high(self): """Return the highbound target temperature we try to reach.""" if self.device.mode == NEST_MODE_ECO: - #TODO: Grab properly + # TODO: Grab properly return None if self.device.mode == NEST_MODE_HEAT_COOL: return self.device.target_temperature_high @@ -141,7 +141,7 @@ class ShittyNestClimate(ClimateDevice): def target_temperature_low(self): """Return the lowbound target temperature we try to reach.""" if self.device.mode == NEST_MODE_ECO: - #TODO: Grab properly + # TODO: Grab properly return None if self.device.mode == NEST_MODE_HEAT_COOL: return self.device.target_temperature_low @@ -235,7 +235,7 @@ class ShittyNestClimate(ClimateDevice): if is_away != need_away: pass - #self.device.set_away() + # self.device.set_away() if is_eco != need_eco: if need_eco: @@ -246,4 +246,3 @@ class ShittyNestClimate(ClimateDevice): def update(self): """Updates data""" self.device.update() - diff --git a/custom_components/badnest/const.py b/custom_components/badnest/const.py index 2e6112d..2e5432f 100644 --- a/custom_components/badnest/const.py +++ b/custom_components/badnest/const.py @@ -1 +1 @@ -DOMAIN='badnest' +DOMAIN = 'badnest'