2015-12-27 11:32:08 +00:00
|
|
|
"""
|
2016-02-23 05:21:49 +00:00
|
|
|
Support for Tellstick Net/Telstick Live.
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/sensor.tellduslive/
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2016-12-12 05:39:37 +00:00
|
|
|
from homeassistant.components.tellduslive import TelldusLiveEntity
|
|
|
|
from homeassistant.const import TEMP_CELSIUS
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2017-11-27 09:11:00 +00:00
|
|
|
SENSOR_TYPE_TEMPERATURE = 'temp'
|
2016-12-12 05:39:37 +00:00
|
|
|
SENSOR_TYPE_HUMIDITY = 'humidity'
|
|
|
|
SENSOR_TYPE_RAINRATE = 'rrate'
|
|
|
|
SENSOR_TYPE_RAINTOTAL = 'rtot'
|
|
|
|
SENSOR_TYPE_WINDDIRECTION = 'wdir'
|
|
|
|
SENSOR_TYPE_WINDAVERAGE = 'wavg'
|
|
|
|
SENSOR_TYPE_WINDGUST = 'wgust'
|
2017-11-27 09:11:00 +00:00
|
|
|
SENSOR_TYPE_UV = 'uv'
|
2016-12-12 05:39:37 +00:00
|
|
|
SENSOR_TYPE_WATT = 'watt'
|
|
|
|
SENSOR_TYPE_LUMINANCE = 'lum'
|
2017-11-27 09:11:00 +00:00
|
|
|
SENSOR_TYPE_DEW_POINT = 'dewp'
|
|
|
|
SENSOR_TYPE_BAROMETRIC_PRESSURE = 'barpress'
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
SENSOR_TYPES = {
|
2017-11-27 09:11:00 +00:00
|
|
|
SENSOR_TYPE_TEMPERATURE: ['Temperature', TEMP_CELSIUS, 'mdi:thermometer'],
|
2016-12-12 05:39:37 +00:00
|
|
|
SENSOR_TYPE_HUMIDITY: ['Humidity', '%', 'mdi:water'],
|
2017-11-27 09:11:00 +00:00
|
|
|
SENSOR_TYPE_RAINRATE: ['Rain rate', 'mm/h', 'mdi:water'],
|
2016-12-12 05:39:37 +00:00
|
|
|
SENSOR_TYPE_RAINTOTAL: ['Rain total', 'mm', 'mdi:water'],
|
|
|
|
SENSOR_TYPE_WINDDIRECTION: ['Wind direction', '', ''],
|
|
|
|
SENSOR_TYPE_WINDAVERAGE: ['Wind average', 'm/s', ''],
|
|
|
|
SENSOR_TYPE_WINDGUST: ['Wind gust', 'm/s', ''],
|
2017-11-27 09:11:00 +00:00
|
|
|
SENSOR_TYPE_UV: ['UV', 'UV', ''],
|
|
|
|
SENSOR_TYPE_WATT: ['Power', 'W', ''],
|
2016-12-12 05:39:37 +00:00
|
|
|
SENSOR_TYPE_LUMINANCE: ['Luminance', 'lx', ''],
|
2017-11-27 09:11:00 +00:00
|
|
|
SENSOR_TYPE_DEW_POINT: ['Dew Point', TEMP_CELSIUS, 'mdi:thermometer'],
|
|
|
|
SENSOR_TYPE_BAROMETRIC_PRESSURE: ['Barometric Pressure', 'kPa', ''],
|
2015-12-27 11:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the Tellstick sensors."""
|
2016-01-18 18:41:41 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2016-12-12 05:39:37 +00:00
|
|
|
add_devices(TelldusLiveSensor(hass, sensor) for sensor in discovery_info)
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
|
2016-12-12 05:39:37 +00:00
|
|
|
class TelldusLiveSensor(TelldusLiveEntity):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Representation of a Telldus Live sensor."""
|
2015-12-27 11:32:08 +00:00
|
|
|
|
2016-02-03 21:31:28 +00:00
|
|
|
@property
|
2016-12-12 05:39:37 +00:00
|
|
|
def device_id(self):
|
|
|
|
"""Return id of the device."""
|
|
|
|
return self._id[0]
|
2016-02-03 21:31:28 +00:00
|
|
|
|
|
|
|
@property
|
2016-12-12 05:39:37 +00:00
|
|
|
def _type(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the type of the sensor."""
|
2016-12-12 05:39:37 +00:00
|
|
|
return self._id[1]
|
2016-02-03 21:31:28 +00:00
|
|
|
|
|
|
|
@property
|
2016-12-12 05:39:37 +00:00
|
|
|
def _value(self):
|
|
|
|
"""Return value of the sensor."""
|
2017-01-31 19:08:11 +00:00
|
|
|
return self.device.value(*self._id[1:])
|
2016-02-03 21:31:28 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def _value_as_temperature(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the value as temperature."""
|
2016-12-12 05:39:37 +00:00
|
|
|
return round(float(self._value), 1)
|
2016-02-03 21:31:28 +00:00
|
|
|
|
2016-07-20 02:16:31 +00:00
|
|
|
@property
|
|
|
|
def _value_as_luminance(self):
|
|
|
|
"""Return the value as luminance."""
|
2016-12-12 05:39:37 +00:00
|
|
|
return round(float(self._value), 1)
|
2016-07-20 02:16:31 +00:00
|
|
|
|
2016-02-03 21:31:28 +00:00
|
|
|
@property
|
|
|
|
def _value_as_humidity(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the value as humidity."""
|
2016-12-12 05:39:37 +00:00
|
|
|
return int(round(float(self._value)))
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the name of the sensor."""
|
2016-12-12 05:39:37 +00:00
|
|
|
return '{} {}'.format(
|
|
|
|
super().name,
|
|
|
|
self.quantity_name or '')
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the state of the sensor."""
|
2017-02-09 17:00:18 +00:00
|
|
|
if not self.available:
|
|
|
|
return None
|
2017-11-27 09:11:00 +00:00
|
|
|
elif self._type == SENSOR_TYPE_TEMPERATURE:
|
2016-02-03 21:31:28 +00:00
|
|
|
return self._value_as_temperature
|
2016-12-12 05:39:37 +00:00
|
|
|
elif self._type == SENSOR_TYPE_HUMIDITY:
|
2016-02-03 21:31:28 +00:00
|
|
|
return self._value_as_humidity
|
2016-12-12 05:39:37 +00:00
|
|
|
elif self._type == SENSOR_TYPE_LUMINANCE:
|
2016-07-20 02:16:31 +00:00
|
|
|
return self._value_as_luminance
|
2017-07-06 06:30:01 +00:00
|
|
|
return self._value
|
2015-12-27 11:32:08 +00:00
|
|
|
|
2016-02-03 21:31:28 +00:00
|
|
|
@property
|
|
|
|
def quantity_name(self):
|
2016-02-23 05:21:49 +00:00
|
|
|
"""Name of quantity."""
|
2016-12-12 05:39:37 +00:00
|
|
|
return SENSOR_TYPES[self._type][0] \
|
|
|
|
if self._type in SENSOR_TYPES else None
|
2016-02-03 21:31:28 +00:00
|
|
|
|
2015-12-27 11:32:08 +00:00
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the unit of measurement."""
|
2016-12-12 05:39:37 +00:00
|
|
|
return SENSOR_TYPES[self._type][1] \
|
|
|
|
if self._type in SENSOR_TYPES else None
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the icon."""
|
2016-12-12 05:39:37 +00:00
|
|
|
return SENSOR_TYPES[self._type][2] \
|
|
|
|
if self._type in SENSOR_TYPES else None
|