mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
parent
b4c8d10dbc
commit
29870b301e
@ -5,39 +5,66 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/sensor.temper/
|
https://home-assistant.io/components/sensor.temper/
|
||||||
"""
|
"""
|
||||||
import logging
|
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.const import CONF_NAME, DEVICE_DEFAULT_NAME, TEMP_FAHRENHEIT
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQUIREMENTS = ['https://github.com/rkabadi/temper-python/archive/'
|
REQUIREMENTS = ['temperusb==1.5.1']
|
||||||
'3dbdaf2d87b8db9a3cd6e5585fc704537dd2d09b.zip'
|
|
||||||
'#temperusb==1.2.3']
|
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
|
# 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."""
|
"""Setup the Temper sensors."""
|
||||||
from temperusb.temper import TemperHandler
|
from temperusb.temper import TemperHandler
|
||||||
|
|
||||||
temp_unit = hass.config.units.temperature_unit
|
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()
|
temper_devices = TemperHandler().get_devices()
|
||||||
add_devices_callback([TemperSensor(dev, temp_unit, name + '_' + str(idx))
|
devices = []
|
||||||
for idx, dev in enumerate(temper_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):
|
class TemperSensor(Entity):
|
||||||
"""Representation of a Temper temperature sensor."""
|
"""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."""
|
"""Initialize the sensor."""
|
||||||
self.temper_device = temper_device
|
self.temper_device = temper_device
|
||||||
self.temp_unit = temp_unit
|
self.temp_unit = temp_unit
|
||||||
|
self.scale = scaling['scale']
|
||||||
|
self.offset = scaling['offset']
|
||||||
self.current_value = None
|
self.current_value = None
|
||||||
self._name = name
|
self._name = name
|
||||||
|
|
||||||
|
# set calibration data
|
||||||
|
self.temper_device.set_calibration_data(
|
||||||
|
scale=self.scale,
|
||||||
|
offset=self.offset
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the temperature sensor."""
|
"""Return the name of the temperature sensor."""
|
||||||
@ -58,7 +85,8 @@ class TemperSensor(Entity):
|
|||||||
try:
|
try:
|
||||||
format_str = ('fahrenheit' if self.temp_unit == TEMP_FAHRENHEIT
|
format_str = ('fahrenheit' if self.temp_unit == TEMP_FAHRENHEIT
|
||||||
else 'celsius')
|
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:
|
except IOError:
|
||||||
_LOGGER.error('Failed to get temperature due to insufficient '
|
_LOGGER.error('Failed to get temperature due to insufficient '
|
||||||
'permissions. Try running with "sudo"')
|
'permissions. Try running with "sudo"')
|
||||||
|
@ -182,9 +182,6 @@ https://github.com/nkgilley/python-join-api/archive/3e1e849f1af0b4080f551b62270c
|
|||||||
# homeassistant.components.switch.edimax
|
# homeassistant.components.switch.edimax
|
||||||
https://github.com/rkabadi/pyedimax/archive/365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1
|
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
|
# homeassistant.components.sensor.gtfs
|
||||||
https://github.com/robbiet480/pygtfs/archive/00546724e4bbcb3053110d844ca44e2246267dd8.zip#pygtfs==0.1.3
|
https://github.com/robbiet480/pygtfs/archive/00546724e4bbcb3053110d844ca44e2246267dd8.zip#pygtfs==0.1.3
|
||||||
|
|
||||||
@ -463,6 +460,9 @@ tellcore-py==1.1.2
|
|||||||
# homeassistant.components.tellduslive
|
# homeassistant.components.tellduslive
|
||||||
tellive-py==0.5.2
|
tellive-py==0.5.2
|
||||||
|
|
||||||
|
# homeassistant.components.sensor.temper
|
||||||
|
temperusb==1.5.1
|
||||||
|
|
||||||
# homeassistant.components.sensor.transmission
|
# homeassistant.components.sensor.transmission
|
||||||
# homeassistant.components.switch.transmission
|
# homeassistant.components.switch.transmission
|
||||||
transmissionrpc==0.11
|
transmissionrpc==0.11
|
||||||
|
Loading…
x
Reference in New Issue
Block a user