1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-12 06:50:00 +00:00
Files
config
docs
homeassistant
components
alarm_control_panel
automation
binary_sensor
camera
device_tracker
frontend
light
lock
media_player
mqtt
notify
rollershutter
sensor
__init__.py
arduino.py
arest.py
bitcoin.py
command_sensor.py
cpuspeed.py
demo.py
dht.py
dweet.py
ecobee.py
efergy.py
eliqonline.py
forecast.py
glances.py
isy994.py
modbus.py
mqtt.py
mysensors.py
nest.py
netatmo.py
onewire.py
openweathermap.py
rest.py
rfxtrx.py
sabnzbd.py
swiss_public_transport.py
systemmonitor.py
tellduslive.py
tellstick.py
temper.py
template.py
time_date.py
torque.py
transmission.py
twitch.py
vera.py
verisure.py
wink.py
worldclock.py
yr.py
zwave.py
switch
thermostat
__init__.py
alexa.py
api.py
arduino.py
browser.py
configurator.py
conversation.py
demo.py
device_sun_light_trigger.py
discovery.py
downloader.py
ecobee.py
group.py
history.py
http.py
ifttt.py
influxdb.py
input_boolean.py
insteon.py
introduction.py
isy994.py
keyboard.py
logbook.py
logger.py
modbus.py
mqtt_eventstream.py
mysensors.py
nest.py
recorder.py
rfxtrx.py
rpi_gpio.py
scene.py
script.py
shell_command.py
simple_alarm.py
statsd.py
sun.py
tellduslive.py
updater.py
verisure.py
wink.py
zone.py
zwave.py
helpers
startup
util
__init__.py
__main__.py
bootstrap.py
config.py
const.py
core.py
exceptions.py
loader.py
remote.py
script
tests
.coveragerc
.gitignore
.gitmodules
.travis.yml
CONTRIBUTING.md
Dockerfile
LICENSE
MANIFEST.in
README.rst
pylintrc
requirements_all.txt
requirements_test.txt
setup.cfg
setup.py
core/homeassistant/components/sensor/nest.py
Fabian Affolter c750f16275 Update docstings
2016-01-27 09:34:14 +01:00

112 lines
3.4 KiB
Python

"""
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/
"""
import logging
import socket
import homeassistant.components.nest as nest
from homeassistant.helpers.entity import Entity
from homeassistant.const import TEMP_CELCIUS
DEPENDENCIES = ['nest']
SENSOR_TYPES = ['humidity',
'mode',
'last_ip',
'local_ip',
'last_connection',
'battery_level']
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):
""" Setup Nest Sensor. """
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([NestBasicSensor(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 "{} {}".format(name, self.variable)
else:
if name == '':
return "{} {}".format(location.capitalize(), self.variable)
else:
return "{}({}){}".format(location.capitalize(),
name,
self.variable)
class NestBasicSensor(NestSensor):
""" Represents a basic Nest sensor with state. """
@property
def state(self):
""" Returns the state of the sensor. """
return getattr(self.device, self.variable)
@property
def unit_of_measurement(self):
""" Unit the value is expressed in. """
return SENSOR_UNITS.get(self.variable, None)
class NestTempSensor(NestSensor):
""" Represents a Nest Temperature sensor. """
@property
def unit_of_measurement(self):
""" Unit the value is expressed in. """
return TEMP_CELCIUS
@property
def state(self):
""" Returns the state of the sensor. """
temp = getattr(self.device, self.variable)
if temp is None:
return None
return round(temp, 1)