fix multiple PR issues
parent
a39148dd38
commit
313cbda0aa
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue