Added scale and offset to the Temper component ()

🐬
pull/3191/head
Heiko Rothe 2016-09-04 18:37:10 +02:00 committed by Teagan Glenn
parent b4c8d10dbc
commit 29870b301e
2 changed files with 40 additions and 12 deletions
homeassistant/components/sensor

View File

@ -5,39 +5,66 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.temper/
"""
import logging
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME, DEVICE_DEFAULT_NAME, TEMP_FAHRENHEIT
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['https://github.com/rkabadi/temper-python/archive/'
'3dbdaf2d87b8db9a3cd6e5585fc704537dd2d09b.zip'
'#temperusb==1.2.3']
REQUIREMENTS = ['temperusb==1.5.1']
CONF_SCALE = 'scale'
CONF_OFFSET = 'offset'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): vol.Coerce(str),
vol.Optional(CONF_SCALE, default=1): vol.Coerce(float),
vol.Optional(CONF_OFFSET, default=0): vol.Coerce(float)
})
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Temper sensors."""
from temperusb.temper import TemperHandler
temp_unit = hass.config.units.temperature_unit
name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME)
name = config.get(CONF_NAME)
scaling = {
'scale': config.get(CONF_SCALE),
'offset': config.get(CONF_OFFSET)
}
temper_devices = TemperHandler().get_devices()
add_devices_callback([TemperSensor(dev, temp_unit, name + '_' + str(idx))
for idx, dev in enumerate(temper_devices)])
devices = []
for idx, dev in enumerate(temper_devices):
if idx != 0:
name = name + '_' + str(idx)
devices.append(TemperSensor(dev, temp_unit, name, scaling))
add_devices(devices)
class TemperSensor(Entity):
"""Representation of a Temper temperature sensor."""
def __init__(self, temper_device, temp_unit, name):
def __init__(self, temper_device, temp_unit, name, scaling):
"""Initialize the sensor."""
self.temper_device = temper_device
self.temp_unit = temp_unit
self.scale = scaling['scale']
self.offset = scaling['offset']
self.current_value = None
self._name = name
# set calibration data
self.temper_device.set_calibration_data(
scale=self.scale,
offset=self.offset
)
@property
def name(self):
"""Return the name of the temperature sensor."""
@ -58,7 +85,8 @@ class TemperSensor(Entity):
try:
format_str = ('fahrenheit' if self.temp_unit == TEMP_FAHRENHEIT
else 'celsius')
self.current_value = self.temper_device.get_temperature(format_str)
sensor_value = self.temper_device.get_temperature(format_str)
self.current_value = round(sensor_value, 1)
except IOError:
_LOGGER.error('Failed to get temperature due to insufficient '
'permissions. Try running with "sudo"')

View File

@ -182,9 +182,6 @@ https://github.com/nkgilley/python-join-api/archive/3e1e849f1af0b4080f551b62270c
# homeassistant.components.switch.edimax
https://github.com/rkabadi/pyedimax/archive/365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1
# homeassistant.components.sensor.temper
https://github.com/rkabadi/temper-python/archive/3dbdaf2d87b8db9a3cd6e5585fc704537dd2d09b.zip#temperusb==1.2.3
# homeassistant.components.sensor.gtfs
https://github.com/robbiet480/pygtfs/archive/00546724e4bbcb3053110d844ca44e2246267dd8.zip#pygtfs==0.1.3
@ -463,6 +460,9 @@ tellcore-py==1.1.2
# homeassistant.components.tellduslive
tellive-py==0.5.2
# homeassistant.components.sensor.temper
temperusb==1.5.1
# homeassistant.components.sensor.transmission
# homeassistant.components.switch.transmission
transmissionrpc==0.11