Added support for temper temperature sensors

This commit is contained in:
Rohit Kabadi 2015-08-01 12:20:29 -07:00
parent dc2ed19105
commit 3c08a5ee6e
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,50 @@
"""
homeassistant.components.sensor.temper
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for getting temperature from TEMPer devices
"""
import logging
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
# 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
temper_devices = TemperHandler().get_devices()
add_devices_callback([TemperSensor(dev, temp_unit) for dev in temper_devices])
class TemperSensor(Entity):
def __init__(self, temper_device, temp_unit):
self.temper_device = temper_device
self.temp_unit = temp_unit
self.current_value = None
@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()
except Exception:
_LOGGER.error('Failed to get temperature due to insufficient permissions')

View File

@ -79,3 +79,6 @@ PyMata==2.07a
# Mysensors serial gateway
pyserial>=2.7
# Temper sensors
https://github.com/rkabadi/temper-python/archive/master.zip