From 0e6a60b0866f46e2e4d7d5922c4421790cd296f5 Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Wed, 13 Jan 2016 21:05:47 -0700 Subject: [PATCH 01/11] Add the nest sensor for tracking data from nest --- homeassistant/components/nest.py | 45 ++++++++ homeassistant/components/sensor/nest.py | 116 ++++++++++++++++++++ homeassistant/components/thermostat/nest.py | 29 +---- 3 files changed, 165 insertions(+), 25 deletions(-) create mode 100644 homeassistant/components/nest.py create mode 100644 homeassistant/components/sensor/nest.py diff --git a/homeassistant/components/nest.py b/homeassistant/components/nest.py new file mode 100644 index 00000000000..af71774b591 --- /dev/null +++ b/homeassistant/components/nest.py @@ -0,0 +1,45 @@ +""" +homeassistant.components.thermostat.nest +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Adds support for Nest thermostats. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/thermostat.nest/ +""" +import logging + +from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD) + +REQUIREMENTS = ['python-nest==2.6.0'] +DOMAIN = 'nest' + +NEST = None + + +# pylint: disable=unused-argument +def setup(hass, config): + """ Sets up the nest thermostat. """ + global NEST + + logger = logging.getLogger(__name__) + print("nest config", config[DOMAIN]) + username = config[DOMAIN].get(CONF_USERNAME) + password = config[DOMAIN].get(CONF_PASSWORD) + + if username is None or password is None: + logger.error("Missing required configuration items %s or %s", + CONF_USERNAME, CONF_PASSWORD) + return + + try: + import nest + except ImportError: + logger.exception( + "Error while importing dependency nest. " + "Did you maybe not install the python-nest dependency?") + + return + + NEST = nest.Nest(username, password) + + return True diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py new file mode 100644 index 00000000000..6f850a30b72 --- /dev/null +++ b/homeassistant/components/sensor/nest.py @@ -0,0 +1,116 @@ +""" +homeassistant.components.sensor.nest +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Support for Nest Thermostat Sensors. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/sensor.nest/ +""" +from homeassistant.helpers.entity import Entity +from homeassistant.const import (STATE_ON, STATE_OFF, TEMP_CELCIUS) +from homeassistant.helpers.temperature import convert + +import homeassistant.components.nest as nest +import logging +import socket + +DEPENDENCIES = ['nest'] +SENSOR_TYPES = ['humidity', + 'mode', + 'last_ip', + 'local_ip', + 'last_connection', + 'battery_level'] + +BINARY_TYPES = ['fan', + 'hvac_ac_state', + 'hvac_aux_heater_state', + 'hvac_heat_x2_state', + 'hvac_heat_x3_state', + 'hvac_alt_heat_state', + 'hvac_alt_heat_x2_state', + 'hvac_emer_heat_state', + 'online'] + +SENSOR_UNITS = {'humidity': '%', 'battery_level': '%'} + +SENSOR_TEMP_TYPES = ['temperature', + 'target', + 'away_temperature[0]', + 'away_temperature[1]'] + +def setup_platform(hass, config, add_devices, discovery_info=None): + logger = logging.getLogger(__name__) + try: + for structure in nest.NEST.structures: + for device in structure.devices: + for variable in config['monitored_conditions']: + if variable in SENSOR_TYPES: + add_devices([NestSensor(structure, device, variable)]) + elif variable in BINARY_TYPES: + add_devices([NestBinarySensor(structure, device, variable)]) + elif variable in SENSOR_TEMP_TYPES: + add_devices([NestTempSensor(structure, device, variable)]) + else: + logger.error('Nest sensor type: "%s" does not exist', variable) + except socket.error: + logger.error( + "Connection error logging into the nest web service." + ) + +class NestSensor(Entity): + """ Represents a Nest sensor. """ + + def __init__(self, structure, device, variable): + self.structure = structure + self.device = device + self.variable = variable + + @property + def name(self): + """ Returns the name of the nest, if any. """ + location = self.device.where + name = self.device.name + if location is None: + return name + ' ' + self.variable + else: + if name == '': + return location.capitalize() + ' ' + self.variable + else: + return location.capitalize() + '(' + name + ')' + self.variable + @property + def state(self): + """ Returns the state of the sensor. """ + return getattr(self.device, self.variable) + + @property + def unit_of_measurement(self): + return SENSOR_UNITS.get(self.variable, None) + +class NestTempSensor(NestSensor): + """ Represents a Nest Temperature sensor. """ + + @property + def unit_of_measurement(self): + return self.hass.config.temperature_unit + + @property + def state(self): + temp = getattr(self.device, self.variable) + if temp is None: + return None + + value = convert(temp, TEMP_CELCIUS, + self.hass.config.temperature_unit) + + return round(value, 1) + +class NestBinarySensor(NestSensor): + """ Represents a Nst Binary sensor. """ + + @property + def state(self): + if getattr(self.device, self.variable): + return STATE_ON + else: + return STATE_OFF diff --git a/homeassistant/components/thermostat/nest.py b/homeassistant/components/thermostat/nest.py index f38935b726e..5530f021755 100644 --- a/homeassistant/components/thermostat/nest.py +++ b/homeassistant/components/thermostat/nest.py @@ -11,38 +11,18 @@ import logging from homeassistant.components.thermostat import (ThermostatDevice, STATE_COOL, STATE_IDLE, STATE_HEAT) -from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS) +from homeassistant.const import (TEMP_CELCIUS) +import homeassistant.components.nest as nest -REQUIREMENTS = ['python-nest==2.6.0'] +DEPENDENCIES = ['nest'] - -# pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): - """ Sets up the nest thermostat. """ logger = logging.getLogger(__name__) - username = config.get(CONF_USERNAME) - password = config.get(CONF_PASSWORD) - - if username is None or password is None: - logger.error("Missing required configuration items %s or %s", - CONF_USERNAME, CONF_PASSWORD) - return - - try: - import nest - except ImportError: - logger.exception( - "Error while importing dependency nest. " - "Did you maybe not install the python-nest dependency?") - - return - - napi = nest.Nest(username, password) try: add_devices([ NestThermostat(structure, device) - for structure in napi.structures + for structure in nest.NEST.structures for device in structure.devices ]) except socket.error: @@ -50,7 +30,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): "Connection error logging into the nest web service." ) - class NestThermostat(ThermostatDevice): """ Represents a Nest thermostat. """ From 7b993da0de09917a3bf654e240ca2e163e5bf35e Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Thu, 14 Jan 2016 10:48:24 -0700 Subject: [PATCH 02/11] address PR comments for Nest Sensor --- .coveragerc | 2 + .../components/binary_sensor/nest.py | 50 +++++++++++++++++++ homeassistant/components/sensor/nest.py | 24 +-------- requirements_all.txt | 6 +-- 4 files changed, 56 insertions(+), 26 deletions(-) create mode 100644 homeassistant/components/binary_sensor/nest.py diff --git a/.coveragerc b/.coveragerc index ea9f302fbb1..69e83f26adb 100644 --- a/.coveragerc +++ b/.coveragerc @@ -37,6 +37,7 @@ omit = homeassistant/components/*/rfxtrx.py homeassistant/components/binary_sensor/arest.py + homeassistant/components/binary_sensor/nest.py homeassistant/components/binary_sensor/rest.py homeassistant/components/browser.py homeassistant/components/camera/* @@ -93,6 +94,7 @@ omit = homeassistant/components/sensor/forecast.py homeassistant/components/sensor/glances.py homeassistant/components/sensor/mysensors.py + homeassistant/components/sensor/nest.py homeassistant/components/sensor/openweathermap.py homeassistant/components/sensor/rest.py homeassistant/components/sensor/rpi_gpio.py diff --git a/homeassistant/components/binary_sensor/nest.py b/homeassistant/components/binary_sensor/nest.py new file mode 100644 index 00000000000..def04f520ed --- /dev/null +++ b/homeassistant/components/binary_sensor/nest.py @@ -0,0 +1,50 @@ +""" +homeassistant.components.binary.nest +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Support for Nest Thermostat Binary Sensors. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/sensor.nest/ +""" +import logging +import socket +import homeassistant.components.nest as nest + +from homeassistant.components.sensor.nest import NestSensor +from homeassistant.const import (STATE_ON, STATE_OFF) + + +BINARY_TYPES = ['fan', + 'hvac_ac_state', + 'hvac_aux_heater_state', + 'hvac_heat_x2_state', + 'hvac_heat_x3_state', + 'hvac_alt_heat_state', + 'hvac_alt_heat_x2_state', + 'hvac_emer_heat_state', + 'online'] + +def setup_platform(hass, config, add_devices, discovery_info=None): + logger = logging.getLogger(__name__) + try: + for structure in nest.NEST.structures: + for device in structure.devices: + for variable in config['monitored_conditions']: + if variable in BINARY_TYPES: + add_devices([NestBinarySensor(structure, device, variable)]) + else: + logger.error('Nest sensor type: "%s" does not exist', variable) + except socket.error: + logger.error( + "Connection error logging into the nest web service." + ) + +class NestBinarySensor(NestSensor): + """ Represents a Nst Binary sensor. """ + + @property + def state(self): + if getattr(self.device, self.variable): + return STATE_ON + else: + return STATE_OFF diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py index 6f850a30b72..3e0f09b1a41 100644 --- a/homeassistant/components/sensor/nest.py +++ b/homeassistant/components/sensor/nest.py @@ -7,7 +7,7 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.nest/ """ from homeassistant.helpers.entity import Entity -from homeassistant.const import (STATE_ON, STATE_OFF, TEMP_CELCIUS) +from homeassistant.const import TEMP_CELCIUS from homeassistant.helpers.temperature import convert import homeassistant.components.nest as nest @@ -22,16 +22,6 @@ SENSOR_TYPES = ['humidity', 'last_connection', 'battery_level'] -BINARY_TYPES = ['fan', - 'hvac_ac_state', - 'hvac_aux_heater_state', - 'hvac_heat_x2_state', - 'hvac_heat_x3_state', - 'hvac_alt_heat_state', - 'hvac_alt_heat_x2_state', - 'hvac_emer_heat_state', - 'online'] - SENSOR_UNITS = {'humidity': '%', 'battery_level': '%'} SENSOR_TEMP_TYPES = ['temperature', @@ -47,8 +37,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for variable in config['monitored_conditions']: if variable in SENSOR_TYPES: add_devices([NestSensor(structure, device, variable)]) - elif variable in BINARY_TYPES: - add_devices([NestBinarySensor(structure, device, variable)]) elif variable in SENSOR_TEMP_TYPES: add_devices([NestTempSensor(structure, device, variable)]) else: @@ -104,13 +92,3 @@ class NestTempSensor(NestSensor): self.hass.config.temperature_unit) return round(value, 1) - -class NestBinarySensor(NestSensor): - """ Represents a Nst Binary sensor. """ - - @property - def state(self): - if getattr(self.device, self.variable): - return STATE_ON - else: - return STATE_OFF diff --git a/requirements_all.txt b/requirements_all.txt index 7aca45c6069..eb30dae0203 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -89,6 +89,9 @@ https://github.com/bashwork/pymodbus/archive/d7fc4f1cc975631e0a9011390e8017f64b6 # homeassistant.components.mqtt paho-mqtt==1.1 +# homeassistant.components.nest +python-nest==2.6.0 + # homeassistant.components.notify.pushbullet pushbullet.py==0.9.0 @@ -184,9 +187,6 @@ heatmiserV3==0.9.1 # homeassistant.components.thermostat.honeywell evohomeclient==0.2.4 -# homeassistant.components.thermostat.nest -python-nest==2.6.0 - # homeassistant.components.thermostat.radiotherm radiotherm==1.2 From 65a3bf232537f19f111533e6b9c5925050d9bbfc Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Thu, 14 Jan 2016 11:01:53 -0700 Subject: [PATCH 03/11] fix merge error --- homeassistant/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/const.py b/homeassistant/const.py index e4d94039068..97e26f8d33a 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -1,7 +1,7 @@ # coding: utf-8 """ Constants used by Home Assistant components. """ -__version__ = "0.10.1" +__version__ = "0.11.0.dev0" # Can be used to specify a catch all when registering state or event listeners. MATCH_ALL = '*' From b8c8c71b7828cc2420c0236a7882e1c09f3c11b9 Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Thu, 14 Jan 2016 11:28:28 -0700 Subject: [PATCH 04/11] run requirements_all again for nest sensor --- requirements_all.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index 0547e7b89a5..097fc743b33 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -89,12 +89,12 @@ https://github.com/bashwork/pymodbus/archive/d7fc4f1cc975631e0a9011390e8017f64b6 # homeassistant.components.mqtt paho-mqtt==1.1 -# homeassistant.components.nest -python-nest==2.6.0 - # homeassistant.components.mysensors https://github.com/theolind/pymysensors/archive/005bff4c5ca7a56acd30e816bc3bcdb5cb2d46fd.zip#pymysensors==0.4 +# homeassistant.components.nest +python-nest==2.6.0 + # homeassistant.components.notify.free_mobile freesms==0.1.0 From a39148dd38d68f5698d8334e4131f318e59d33ce Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Thu, 14 Jan 2016 11:37:17 -0700 Subject: [PATCH 05/11] fix pylint errors for Nest Sensor --- homeassistant/components/binary_sensor/nest.py | 1 + homeassistant/components/sensor/nest.py | 9 +++++---- homeassistant/components/thermostat/nest.py | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/binary_sensor/nest.py b/homeassistant/components/binary_sensor/nest.py index def04f520ed..99bb5e045fd 100644 --- a/homeassistant/components/binary_sensor/nest.py +++ b/homeassistant/components/binary_sensor/nest.py @@ -25,6 +25,7 @@ BINARY_TYPES = ['fan', 'online'] def setup_platform(hass, config, add_devices, discovery_info=None): + "Setup nest binary sensors from config file" logger = logging.getLogger(__name__) try: for structure in nest.NEST.structures: diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py index 3e0f09b1a41..86cd38f2b39 100644 --- a/homeassistant/components/sensor/nest.py +++ b/homeassistant/components/sensor/nest.py @@ -6,14 +6,14 @@ Support for Nest Thermostat Sensors. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.nest/ """ +import logging +import socket +import homeassistant.components.nest as nest + from homeassistant.helpers.entity import Entity from homeassistant.const import TEMP_CELCIUS from homeassistant.helpers.temperature import convert -import homeassistant.components.nest as nest -import logging -import socket - DEPENDENCIES = ['nest'] SENSOR_TYPES = ['humidity', 'mode', @@ -30,6 +30,7 @@ SENSOR_TEMP_TYPES = ['temperature', 'away_temperature[1]'] def setup_platform(hass, config, add_devices, discovery_info=None): + "Setup Nest Sensor from config file" logger = logging.getLogger(__name__) try: for structure in nest.NEST.structures: diff --git a/homeassistant/components/thermostat/nest.py b/homeassistant/components/thermostat/nest.py index 5530f021755..24f9153c50e 100644 --- a/homeassistant/components/thermostat/nest.py +++ b/homeassistant/components/thermostat/nest.py @@ -17,6 +17,7 @@ import homeassistant.components.nest as nest DEPENDENCIES = ['nest'] def setup_platform(hass, config, add_devices, discovery_info=None): + "Setup nest thermostat" logger = logging.getLogger(__name__) try: From 313cbda0aa281b69ad74eb5ca365033736ca95c0 Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Thu, 14 Jan 2016 14:17:28 -0700 Subject: [PATCH 06/11] fix multiple PR issues --- .../components/binary_sensor/nest.py | 19 ++++++++++--------- homeassistant/components/nest.py | 10 +--------- homeassistant/components/sensor/nest.py | 19 ++++++++++++++----- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/binary_sensor/nest.py b/homeassistant/components/binary_sensor/nest.py index 99bb5e045fd..d980205c33c 100644 --- a/homeassistant/components/binary_sensor/nest.py +++ b/homeassistant/components/binary_sensor/nest.py @@ -10,8 +10,7 @@ import logging import socket import homeassistant.components.nest as nest -from homeassistant.components.sensor.nest import NestSensor -from homeassistant.const import (STATE_ON, STATE_OFF) +from homeassistant.components.sensor.nest import NestSensor BINARY_TYPES = ['fan', @@ -26,15 +25,20 @@ BINARY_TYPES = ['fan', def setup_platform(hass, config, add_devices, discovery_info=None): "Setup nest binary sensors from config file" + logger = logging.getLogger(__name__) try: for structure in nest.NEST.structures: for device in structure.devices: for variable in config['monitored_conditions']: if variable in BINARY_TYPES: - add_devices([NestBinarySensor(structure, device, variable)]) + add_devices([NestBinarySensor( + structure, + device, + variable)]) else: - logger.error('Nest sensor type: "%s" does not exist', variable) + logger.error('Nest sensor type: "%s" does not exist', + variable) except socket.error: logger.error( "Connection error logging into the nest web service." @@ -44,8 +48,5 @@ class NestBinarySensor(NestSensor): """ Represents a Nst Binary sensor. """ @property - def state(self): - if getattr(self.device, self.variable): - return STATE_ON - else: - return STATE_OFF + def is_on(self): + return bool(getattr(self.device, self.variable)) diff --git a/homeassistant/components/nest.py b/homeassistant/components/nest.py index af71774b591..1b1d940595a 100644 --- a/homeassistant/components/nest.py +++ b/homeassistant/components/nest.py @@ -22,7 +22,6 @@ def setup(hass, config): global NEST logger = logging.getLogger(__name__) - print("nest config", config[DOMAIN]) username = config[DOMAIN].get(CONF_USERNAME) password = config[DOMAIN].get(CONF_PASSWORD) @@ -31,14 +30,7 @@ def setup(hass, config): CONF_USERNAME, CONF_PASSWORD) return - try: - import nest - except ImportError: - logger.exception( - "Error while importing dependency nest. " - "Did you maybe not install the python-nest dependency?") - - return + import nest NEST = nest.Nest(username, password) diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py index 86cd38f2b39..f900d2eba93 100644 --- a/homeassistant/components/sensor/nest.py +++ b/homeassistant/components/sensor/nest.py @@ -31,6 +31,7 @@ SENSOR_TEMP_TYPES = ['temperature', def setup_platform(hass, config, add_devices, discovery_info=None): "Setup Nest Sensor from config file" + logger = logging.getLogger(__name__) try: for structure in nest.NEST.structures: @@ -39,14 +40,18 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if variable in SENSOR_TYPES: add_devices([NestSensor(structure, device, variable)]) elif variable in SENSOR_TEMP_TYPES: - add_devices([NestTempSensor(structure, device, variable)]) + add_devices([NestTempSensor(structure, + device, + variable)]) else: - logger.error('Nest sensor type: "%s" does not exist', variable) + logger.error('Nest sensor type: "%s" does not exist', + variable) except socket.error: logger.error( "Connection error logging into the nest web service." ) + class NestSensor(Entity): """ Represents a Nest sensor. """ @@ -58,18 +63,22 @@ class NestSensor(Entity): @property def name(self): """ Returns the name of the nest, if any. """ + location = self.device.where name = self.device.name if location is None: - return name + ' ' + self.variable + return "{} {}".format(name, self.variable) else: if name == '': - return location.capitalize() + ' ' + self.variable + return "{} {}".format(location.capitalize(), self.variable) else: - return location.capitalize() + '(' + name + ')' + self.variable + return "{}({}){}".format(location.capitalize(), + name, + self.variable) @property def state(self): """ Returns the state of the sensor. """ + return getattr(self.device, self.variable) @property From 9210c57c2d55637dd15e843d74b4d382ff18d14a Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Thu, 14 Jan 2016 14:19:35 -0700 Subject: [PATCH 07/11] Fix lint errors and PR comments --- .coveragerc | 6 +++--- homeassistant/components/binary_sensor/nest.py | 7 +++++-- homeassistant/components/sensor/nest.py | 11 +++++------ homeassistant/components/thermostat/nest.py | 3 +++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.coveragerc b/.coveragerc index 44263c15572..b927fd28255 100644 --- a/.coveragerc +++ b/.coveragerc @@ -39,8 +39,10 @@ omit = homeassistant/components/mysensors.py homeassistant/components/*/mysensors.py + homeassistant/components/nest.py + homeassistant/components/*/nest.py + homeassistant/components/binary_sensor/arest.py - homeassistant/components/binary_sensor/nest.py homeassistant/components/binary_sensor/rest.py homeassistant/components/browser.py homeassistant/components/camera/* @@ -97,7 +99,6 @@ omit = homeassistant/components/sensor/eliqonline.py homeassistant/components/sensor/forecast.py homeassistant/components/sensor/glances.py - homeassistant/components/sensor/nest.py homeassistant/components/sensor/netatmo.py homeassistant/components/sensor/openweathermap.py homeassistant/components/sensor/rest.py @@ -123,7 +124,6 @@ omit = homeassistant/components/thermostat/heatmiser.py homeassistant/components/thermostat/homematic.py homeassistant/components/thermostat/honeywell.py - homeassistant/components/thermostat/nest.py homeassistant/components/thermostat/radiotherm.py diff --git a/homeassistant/components/binary_sensor/nest.py b/homeassistant/components/binary_sensor/nest.py index d980205c33c..421a39e51f5 100644 --- a/homeassistant/components/binary_sensor/nest.py +++ b/homeassistant/components/binary_sensor/nest.py @@ -23,6 +23,7 @@ BINARY_TYPES = ['fan', 'hvac_emer_heat_state', 'online'] + def setup_platform(hass, config, add_devices, discovery_info=None): "Setup nest binary sensors from config file" @@ -32,8 +33,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for device in structure.devices: for variable in config['monitored_conditions']: if variable in BINARY_TYPES: - add_devices([NestBinarySensor( - structure, + add_devices([NestBinarySensor(structure, device, variable)]) else: @@ -44,9 +44,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None): "Connection error logging into the nest web service." ) + class NestBinarySensor(NestSensor): """ Represents a Nst Binary sensor. """ @property def is_on(self): + "Returns is the binary sensor is on or off" + return bool(getattr(self.device, self.variable)) diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py index f900d2eba93..ed8052b23d8 100644 --- a/homeassistant/components/sensor/nest.py +++ b/homeassistant/components/sensor/nest.py @@ -12,7 +12,6 @@ import homeassistant.components.nest as nest from homeassistant.helpers.entity import Entity from homeassistant.const import TEMP_CELCIUS -from homeassistant.helpers.temperature import convert DEPENDENCIES = ['nest'] SENSOR_TYPES = ['humidity', @@ -29,6 +28,7 @@ SENSOR_TEMP_TYPES = ['temperature', 'away_temperature[0]', 'away_temperature[1]'] + def setup_platform(hass, config, add_devices, discovery_info=None): "Setup Nest Sensor from config file" @@ -75,6 +75,7 @@ class NestSensor(Entity): return "{}({}){}".format(location.capitalize(), name, self.variable) + @property def state(self): """ Returns the state of the sensor. """ @@ -85,12 +86,13 @@ class NestSensor(Entity): def unit_of_measurement(self): return SENSOR_UNITS.get(self.variable, None) + class NestTempSensor(NestSensor): """ Represents a Nest Temperature sensor. """ @property def unit_of_measurement(self): - return self.hass.config.temperature_unit + return TEMP_CELCIUS @property def state(self): @@ -98,7 +100,4 @@ class NestTempSensor(NestSensor): if temp is None: return None - value = convert(temp, TEMP_CELCIUS, - self.hass.config.temperature_unit) - - return round(value, 1) + return round(temp, 1) diff --git a/homeassistant/components/thermostat/nest.py b/homeassistant/components/thermostat/nest.py index 24f9153c50e..423a3195976 100644 --- a/homeassistant/components/thermostat/nest.py +++ b/homeassistant/components/thermostat/nest.py @@ -16,8 +16,10 @@ import homeassistant.components.nest as nest DEPENDENCIES = ['nest'] + def setup_platform(hass, config, add_devices, discovery_info=None): "Setup nest thermostat" + logger = logging.getLogger(__name__) try: @@ -31,6 +33,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): "Connection error logging into the nest web service." ) + class NestThermostat(ThermostatDevice): """ Represents a Nest thermostat. """ From 9617288bd5677b86eb2890b2c7f86693e616a2c2 Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Fri, 15 Jan 2016 08:16:33 -0700 Subject: [PATCH 08/11] multiple inheritance for nest binary sensor --- homeassistant/components/binary_sensor/nest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/binary_sensor/nest.py b/homeassistant/components/binary_sensor/nest.py index 421a39e51f5..e1414de5648 100644 --- a/homeassistant/components/binary_sensor/nest.py +++ b/homeassistant/components/binary_sensor/nest.py @@ -11,6 +11,7 @@ import socket import homeassistant.components.nest as nest from homeassistant.components.sensor.nest import NestSensor +from homeassistant.components.binary_sensor import BinarySensorDevice BINARY_TYPES = ['fan', @@ -45,7 +46,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): ) -class NestBinarySensor(NestSensor): +class NestBinarySensor(NestSensor, BinarySensorDevice): """ Represents a Nst Binary sensor. """ @property From dd35551047c1f634092e5ff390660b539cce1f6c Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Sat, 16 Jan 2016 12:47:08 -0700 Subject: [PATCH 09/11] fix order of inhertiance --- homeassistant/components/binary_sensor/nest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/binary_sensor/nest.py b/homeassistant/components/binary_sensor/nest.py index e1414de5648..1150e9cc682 100644 --- a/homeassistant/components/binary_sensor/nest.py +++ b/homeassistant/components/binary_sensor/nest.py @@ -46,7 +46,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): ) -class NestBinarySensor(NestSensor, BinarySensorDevice): +class NestBinarySensor(BinarySensorDevice, NestSensor): """ Represents a Nst Binary sensor. """ @property From 4dbd84ead0c0055c7fdee1a40171dba5da550162 Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Sat, 16 Jan 2016 12:53:42 -0700 Subject: [PATCH 10/11] make sure everything inherits from NesSensor --- homeassistant/components/sensor/nest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py index 578c80e3c0f..fa2a245411c 100644 --- a/homeassistant/components/sensor/nest.py +++ b/homeassistant/components/sensor/nest.py @@ -89,7 +89,7 @@ class NestBasicSensor(NestSensor): return SENSOR_UNITS.get(self.variable, None) -class NestTempSensor(NestBasicSensor): +class NestTempSensor(NestSensor): """ Represents a Nest Temperature sensor. """ @property From 4ca4941c8265e7a880d03f4e0c3c97fca783358a Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Sat, 16 Jan 2016 12:56:38 -0700 Subject: [PATCH 11/11] fix pylint errors in sensor/nest --- homeassistant/components/sensor/nest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py index fa2a245411c..040469d2e13 100644 --- a/homeassistant/components/sensor/nest.py +++ b/homeassistant/components/sensor/nest.py @@ -38,7 +38,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for device in structure.devices: for variable in config['monitored_conditions']: if variable in SENSOR_TYPES: - add_devices([NestBasicSensor(structure, device, variable)]) + add_devices([NestBasicSensor(structure, + device, + variable)]) elif variable in SENSOR_TEMP_TYPES: add_devices([NestTempSensor(structure, device, @@ -78,6 +80,8 @@ class NestSensor(Entity): class NestBasicSensor(NestSensor): + """ Represents a basic Nest sensor with state. """ + @property def state(self): """ Returns the state of the sensor. """