2015-08-01 19:20:29 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.sensor.temper
|
2015-08-06 17:15:37 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
Support for getting temperature from TEMPer devices.
|
2015-08-01 19:20:29 +00:00
|
|
|
|
2015-08-06 17:15:37 +00:00
|
|
|
Configuration:
|
|
|
|
To use the temper sensors you will need to add something like the following to
|
|
|
|
your config/configuration.yaml
|
|
|
|
|
|
|
|
Example:
|
2015-08-01 19:20:29 +00:00
|
|
|
|
2015-08-06 17:15:37 +00:00
|
|
|
sensor:
|
|
|
|
platform: temper
|
|
|
|
"""
|
2015-08-01 19:20:29 +00:00
|
|
|
import logging
|
|
|
|
from homeassistant.helpers.entity import Entity
|
2015-08-01 19:46:28 +00:00
|
|
|
from homeassistant.const import CONF_NAME, DEVICE_DEFAULT_NAME
|
2015-08-01 19:20:29 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2015-08-30 01:39:50 +00:00
|
|
|
REQUIREMENTS = ['https://github.com/rkabadi/temper-python/archive/' +
|
|
|
|
'3dbdaf2d87b8db9a3cd6e5585fc704537dd2d09b.zip']
|
2015-08-01 19:20:29 +00:00
|
|
|
|
2015-08-03 01:58:30 +00:00
|
|
|
|
2015-08-01 19:20:29 +00:00
|
|
|
# pylint: disable=unused-argument
|
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|
|
|
""" Find and return Temper sensors. """
|
|
|
|
try:
|
|
|
|
# pylint: disable=no-name-in-module, import-error
|
|
|
|
from temperusb.temper import TemperHandler
|
|
|
|
except ImportError:
|
|
|
|
_LOGGER.error('Failed to import temperusb')
|
|
|
|
return False
|
|
|
|
|
|
|
|
temp_unit = hass.config.temperature_unit
|
2015-08-01 19:46:28 +00:00
|
|
|
name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME)
|
2015-08-01 19:20:29 +00:00
|
|
|
temper_devices = TemperHandler().get_devices()
|
2015-08-01 19:46:28 +00:00
|
|
|
add_devices_callback([TemperSensor(dev, temp_unit, name + '_' + str(idx))
|
|
|
|
for idx, dev in enumerate(temper_devices)])
|
2015-08-01 19:20:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TemperSensor(Entity):
|
2015-08-06 17:15:37 +00:00
|
|
|
""" Represents an Temper temperature sensor. """
|
2015-08-01 19:46:28 +00:00
|
|
|
def __init__(self, temper_device, temp_unit, name):
|
2015-08-01 19:20:29 +00:00
|
|
|
self.temper_device = temper_device
|
|
|
|
self.temp_unit = temp_unit
|
|
|
|
self.current_value = None
|
2015-08-01 19:46:28 +00:00
|
|
|
self._name = name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
""" Returns the name of the temperature sensor. """
|
|
|
|
return self._name
|
2015-08-01 19:20:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
""" Returns the state of the entity. """
|
|
|
|
return self.current_value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
""" Unit of measurement of this entity, if any. """
|
|
|
|
return self.temp_unit
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
""" Retrieve latest state. """
|
|
|
|
try:
|
|
|
|
self.current_value = self.temper_device.get_temperature()
|
2015-08-03 01:51:13 +00:00
|
|
|
except IOError:
|
2015-08-01 19:46:28 +00:00
|
|
|
_LOGGER.error('Failed to get temperature due to insufficient '
|
|
|
|
'permissions. Try running with "sudo"')
|