Update/add docstrings (PEP257)

This commit is contained in:
Fabian Affolter 2016-02-23 06:21:49 +01:00
parent c64da761f1
commit 60d579af84
46 changed files with 407 additions and 510 deletions

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to interface with various sensors that can be monitored. Component to interface with various sensors that can be monitored.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.apcupsd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides a sensor to track various status aspects of a UPS. Provides a sensor to track various status aspects of a UPS.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.arduino
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for getting information from Arduino pins. Only analog pins are Support for getting information from Arduino pins. Only analog pins are
supported. supported.
@ -14,13 +12,11 @@ from homeassistant.const import DEVICE_DEFAULT_NAME
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
DEPENDENCIES = ['arduino'] DEPENDENCIES = ['arduino']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Arduino platform.""" """Sets up the Arduino platform."""
# Verify that the Arduino board is present # Verify that the Arduino board is present
if arduino.BOARD is None: if arduino.BOARD is None:
_LOGGER.error('A connection has not been made to the Arduino board.') _LOGGER.error('A connection has not been made to the Arduino board.')

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.arest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The arest sensor will consume an exposed aREST API of a device. The arest sensor will consume an exposed aREST API of a device.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -28,7 +26,6 @@ CONF_MONITORED_VARIABLES = 'monitored_variables'
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the aREST sensor.""" """Get the aREST sensor."""
resource = config.get(CONF_RESOURCE) resource = config.get(CONF_RESOURCE)
var_conf = config.get(CONF_MONITORED_VARIABLES) var_conf = config.get(CONF_MONITORED_VARIABLES)
pins = config.get('pins', None) pins = config.get('pins', None)
@ -53,7 +50,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
arest = ArestData(resource) arest = ArestData(resource)
def make_renderer(value_template): def make_renderer(value_template):
""" Creates renderer based on variable_template value """ """Creates renderer based on variable_template value."""
if value_template is None: if value_template is None:
return lambda value: value return lambda value: value
@ -135,7 +132,7 @@ class ArestSensor(Entity):
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
values = self.arest.data values = self.arest.data
if 'error' in values: if 'error' in values:

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.bitcoin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bitcoin information service that uses blockchain.info and its online wallet. Bitcoin information service that uses blockchain.info and its online wallet.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -46,7 +44,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the Bitcoin sensor.""" """Get the Bitcoin sensor."""
from blockchain.wallet import Wallet from blockchain.wallet import Wallet
from blockchain import exchangerates, exceptions from blockchain import exchangerates, exceptions
@ -85,7 +82,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class BitcoinSensor(Entity): class BitcoinSensor(Entity):
"""Implements a Bitcoin sensor.""" """Implements a Bitcoin sensor."""
def __init__(self, data, option_type, currency, wallet=''): def __init__(self, data, option_type, currency, wallet=''):
self.data = data self.data = data
self._name = OPTION_TYPES[option_type][0] self._name = OPTION_TYPES[option_type][0]
@ -98,16 +94,17 @@ class BitcoinSensor(Entity):
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Returns the name of the sensor."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Unit the value is expressed in."""
return self._unit_of_measurement return self._unit_of_measurement
@property @property
@ -118,7 +115,6 @@ class BitcoinSensor(Entity):
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
def update(self): def update(self):
"""Gets the latest data and updates the states.""" """Gets the latest data and updates the states."""
self.data.update() self.data.update()
stats = self.data.stats stats = self.data.stats
ticker = self.data.ticker ticker = self.data.ticker
@ -177,7 +173,6 @@ class BitcoinSensor(Entity):
class BitcoinData(object): class BitcoinData(object):
"""Gets the latest data and updates the states.""" """Gets the latest data and updates the states."""
def __init__(self): def __init__(self):
self.stats = None self.stats = None
self.ticker = None self.ticker = None
@ -185,7 +180,6 @@ class BitcoinData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):
"""Gets the latest data from blockchain.info.""" """Gets the latest data from blockchain.info."""
from blockchain import statistics, exchangerates from blockchain import statistics, exchangerates
self.stats = statistics.get() self.stats = statistics.get()

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.command_sensor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure custom shell commands to turn a value for a sensor. Allows to configure custom shell commands to turn a value for a sensor.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.cpuspeed Support for displaying the current CPU speed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows the current CPU speed.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.cpuspeed/ https://home-assistant.io/components/sensor.cpuspeed/
@ -15,7 +13,6 @@ REQUIREMENTS = ['py-cpuinfo==0.1.8']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = "CPU speed" DEFAULT_NAME = "CPU speed"
ATTR_VENDOR = 'Vendor ID' ATTR_VENDOR = 'Vendor ID'
ATTR_BRAND = 'Brand' ATTR_BRAND = 'Brand'
ATTR_HZ = 'GHz Advertised' ATTR_HZ = 'GHz Advertised'
@ -25,13 +22,11 @@ ICON = 'mdi:pulse'
# pylint: disable=unused-variable # pylint: disable=unused-variable
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the CPU speed sensor.""" """Sets up the CPU speed sensor."""
add_devices([CpuSpeedSensor(config.get('name', DEFAULT_NAME))]) add_devices([CpuSpeedSensor(config.get('name', DEFAULT_NAME))])
class CpuSpeedSensor(Entity): class CpuSpeedSensor(Entity):
"""A CPU info sensor.""" """A CPU info sensor."""
def __init__(self, name): def __init__(self, name):
self._name = name self._name = name
self._state = None self._state = None
@ -45,7 +40,7 @@ class CpuSpeedSensor(Entity):
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has a couple of fake sensors. Demo platform that has a couple of fake sensors.
""" """
from homeassistant.const import ATTR_BATTERY_LEVEL, TEMP_CELCIUS from homeassistant.const import ATTR_BATTERY_LEVEL, TEMP_CELCIUS
@ -18,7 +16,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class DemoSensor(Entity): class DemoSensor(Entity):
"""A Demo sensor.""" """A Demo sensor."""
def __init__(self, name, state, unit_of_measurement, battery): def __init__(self, name, state, unit_of_measurement, battery):
self._name = name self._name = name
self._state = state self._state = state
@ -32,12 +29,12 @@ class DemoSensor(Entity):
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Returns the name of the sensor."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.dht Support for Adafruit DHT temperature and humidity sensor.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adafruit DHT temperature and humidity sensor.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.dht/ https://home-assistant.io/components/sensor.dht/
@ -13,7 +11,7 @@ from homeassistant.const import TEMP_FAHRENHEIT
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
# update this requirement to upstream as soon as it supports python3 # Update this requirement to upstream as soon as it supports Python 3.
REQUIREMENTS = ['http://github.com/mala-zaba/Adafruit_Python_DHT/archive/' REQUIREMENTS = ['http://github.com/mala-zaba/Adafruit_Python_DHT/archive/'
'4101340de8d2457dd194bca1e8d11cbfc237e919.zip' '4101340de8d2457dd194bca1e8d11cbfc237e919.zip'
'#Adafruit_DHT==1.1.0'] '#Adafruit_DHT==1.1.0']
@ -31,7 +29,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the DHT sensor.""" """Get the DHT sensor."""
# pylint: disable=import-error # pylint: disable=import-error
import Adafruit_DHT import Adafruit_DHT
@ -71,7 +68,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class DHTSensor(Entity): class DHTSensor(Entity):
"""Implements an DHT sensor.""" """Implements an DHT sensor."""
def __init__(self, dht_client, sensor_type, temp_unit, name): def __init__(self, dht_client, sensor_type, temp_unit, name):
self.client_name = name self.client_name = name
self._name = SENSOR_TYPES[sensor_type][0] self._name = SENSOR_TYPES[sensor_type][0]
@ -84,11 +80,12 @@ class DHTSensor(Entity):
@property @property
def name(self): def name(self):
"""Returns the name of the sensor."""
return '{} {}'.format(self.client_name, self._name) return '{} {}'.format(self.client_name, self._name)
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property
@ -98,7 +95,6 @@ class DHTSensor(Entity):
def update(self): def update(self):
"""Gets the latest data from the DHT and updates the states.""" """Gets the latest data from the DHT and updates the states."""
self.dht_client.update() self.dht_client.update()
data = self.dht_client.data data = self.dht_client.data
@ -112,7 +108,6 @@ class DHTSensor(Entity):
class DHTClient(object): class DHTClient(object):
"""Gets the latest data from the DHT sensor.""" """Gets the latest data from the DHT sensor."""
def __init__(self, adafruit_dht, sensor, pin): def __init__(self, adafruit_dht, sensor, pin):
self.adafruit_dht = adafruit_dht self.adafruit_dht = adafruit_dht
self.sensor = sensor self.sensor = sensor

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.dweet Support for showing values from Dweet.io.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Displays values from Dweet.io.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.dweet/ https://home-assistant.io/components/sensor.dweet/
@ -20,7 +18,7 @@ REQUIREMENTS = ['dweepy==0.2.0']
DEFAULT_NAME = 'Dweet.io Sensor' DEFAULT_NAME = 'Dweet.io Sensor'
CONF_DEVICE = 'device' CONF_DEVICE = 'device'
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago.
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
@ -61,7 +59,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
class DweetSensor(Entity): class DweetSensor(Entity):
"""Implements a Dweet sensor.""" """Implements a Dweet sensor."""
def __init__(self, hass, dweet, name, value_template, unit_of_measurement): def __init__(self, hass, dweet, name, value_template, unit_of_measurement):
self.hass = hass self.hass = hass
self.dweet = dweet self.dweet = dweet
@ -100,7 +97,6 @@ class DweetSensor(Entity):
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class DweetData(object): class DweetData(object):
"""Class for handling the data retrieval.""" """Class for handling the data retrieval."""
def __init__(self, device): def __init__(self, device):
self._device = device self._device = device
self.data = None self.data = None

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.ecobee Support for Ecobee sensors.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sensor platform for Ecobee sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.ecobee/ https://home-assistant.io/components/sensor.ecobee/
@ -55,12 +53,12 @@ class EcobeeSensor(Entity):
@property @property
def name(self): def name(self):
""" Returns the name of the Ecobee sensor.. """ """Returns the name of the Ecobee sensor."""
return self._name.rstrip() return self._name.rstrip()
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.efergy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monitors home energy use as measured by an efergy engage hub using its Monitors home energy use as measured by an efergy engage hub using its
(unofficial, undocumented) API. (unofficial, undocumented) API.
@ -66,12 +64,12 @@ class EfergySensor(Entity):
@property @property
def name(self): def name(self):
""" Returns the name. """ """Returns the name of the sensor."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.eliqonline
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monitors home energy use for the eliq online service. Monitors home energy use for the eliq online service.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -52,7 +50,7 @@ class EliqSensor(Entity):
@property @property
def name(self): def name(self):
""" Returns the name. """ """Returns the name of the sensor."""
return self._name return self._name
@property @property
@ -76,4 +74,4 @@ class EliqSensor(Entity):
response = self.api.get_data_now(channelid=self.channel_id) response = self.api.get_data_now(channelid=self.channel_id)
self._state = int(response.power) self._state = int(response.power)
except (TypeError, URLError): except (TypeError, URLError):
_LOGGER.error("could not connect to the eliqonline servers") _LOGGER.error("Could not connect to the eliqonline servers")

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.forecast Support for Forecast.io weather service.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Forecast.io weather service.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.forecast/ https://home-assistant.io/components/sensor.forecast/
@ -41,7 +39,7 @@ SENSOR_TYPES = {
'ozone': ['Ozone', 'DU', 'DU', 'DU', 'DU', 'DU'], 'ozone': ['Ozone', 'DU', 'DU', 'DU', 'DU', 'DU'],
} }
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago.
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
@ -111,11 +109,12 @@ class ForeCastSensor(Entity):
@property @property
def name(self): def name(self):
"""The name of the sensor."""
return '{} {}'.format(self.client_name, self._name) return '{} {}'.format(self.client_name, self._name)
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.glances Support gahtering system information of hosts which are running glances.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Gathers system information of hosts which running glances.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.glances/ https://home-assistant.io/components/sensor.glances/
@ -39,7 +37,7 @@ SENSOR_TYPES = {
} }
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago.
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
@ -156,7 +154,6 @@ class GlancesSensor(Entity):
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class GlancesData(object): class GlancesData(object):
"""Class for handling the data retrieval.""" """Class for handling the data retrieval."""
def __init__(self, resource): def __init__(self, resource):
self._resource = resource self._resource = resource
self.data = dict() self.data = dict()

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.isy994
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for ISY994 sensors. Support for ISY994 sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -33,12 +31,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=protected-access # pylint: disable=protected-access
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
devs = [] devs = []
# verify connection # Verify connection
if ISY is None or not ISY.connected: if ISY is None or not ISY.connected:
logger.error('A connection has not been made to the ISY controller.') logger.error('A connection has not been made to the ISY controller.')
return False return False
# import weather # Import weather
if ISY.climate is not None: if ISY.climate is not None:
for prop in ISY.climate._id2name: for prop in ISY.climate._id2name:
if prop is not None: if prop is not None:
@ -49,14 +47,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
getattr(ISY.climate, prop + '_units')) getattr(ISY.climate, prop + '_units'))
devs.append(ISYSensorDevice(node)) devs.append(ISYSensorDevice(node))
# import sensor nodes # Import sensor nodes
for (path, node) in ISY.nodes: for (path, node) in ISY.nodes:
if SENSOR_STRING in node.name: if SENSOR_STRING in node.name:
if HIDDEN_STRING in path: if HIDDEN_STRING in path:
node.name += HIDDEN_STRING node.name += HIDDEN_STRING
devs.append(ISYSensorDevice(node, [STATE_ON, STATE_OFF])) devs.append(ISYSensorDevice(node, [STATE_ON, STATE_OFF]))
# import sensor programs # Import sensor programs
for (folder_name, states) in ( for (folder_name, states) in (
('HA.locations', [STATE_HOME, STATE_NOT_HOME]), ('HA.locations', [STATE_HOME, STATE_NOT_HOME]),
('HA.sensors', [STATE_OPEN, STATE_CLOSED]), ('HA.sensors', [STATE_OPEN, STATE_CLOSED]),
@ -87,7 +85,6 @@ class WeatherPseudoNode(object):
class ISYSensorDevice(ISYDeviceABC): class ISYSensorDevice(ISYDeviceABC):
"""Represents a ISY sensor.""" """Represents a ISY sensor."""
_domain = 'sensor' _domain = 'sensor'
def __init__(self, node, states=None): def __init__(self, node, states=None):

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.mfi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Ubiquiti mFi sensors. Support for Ubiquiti mFi sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -37,7 +35,6 @@ SENSOR_MODELS = [
# pylint: disable=unused-variable # pylint: disable=unused-variable
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up mFi sensors.""" """Sets up mFi sensors."""
if not validate_config({DOMAIN: config}, if not validate_config({DOMAIN: config},
{DOMAIN: ['host', {DOMAIN: ['host',
CONF_USERNAME, CONF_USERNAME,
@ -74,10 +71,12 @@ class MfiSensor(Entity):
@property @property
def name(self): def name(self):
"""Returns the name of th sensor."""
return self._port.label return self._port.label
@property @property
def state(self): def state(self):
"""Returns the state of the sensor."""
if self._port.model == 'Input Digital': if self._port.model == 'Input Digital':
return self._port.value > 0 and STATE_ON or STATE_OFF return self._port.value > 0 and STATE_ON or STATE_OFF
else: else:
@ -86,6 +85,7 @@ class MfiSensor(Entity):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
if self._port.tag == 'temperature': if self._port.tag == 'temperature':
return TEMP_CELCIUS return TEMP_CELCIUS
elif self._port.tag == 'active_pwr': elif self._port.tag == 'active_pwr':
@ -95,4 +95,5 @@ class MfiSensor(Entity):
return self._port.tag return self._port.tag
def update(self): def update(self):
"""Gets the latest data."""
self._port.refresh() self._port.refresh()

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.modbus
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Modbus sensors. Support for Modbus sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -18,7 +16,7 @@ DEPENDENCIES = ['modbus']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Read config and create Modbus devices. """ """Create Modbus devices."""
sensors = [] sensors = []
slave = config.get("slave", None) slave = config.get("slave", None)
if modbus.TYPE == "serial" and not slave: if modbus.TYPE == "serial" and not slave:
@ -66,14 +64,12 @@ class ModbusSensor(Entity):
self._coil = coil self._coil = coil
def __str__(self): def __str__(self):
"""Returns the name and the state of the sensor."""
return "%s: %s" % (self.name, self.state) return "%s: %s" % (self.name, self.state)
@property @property
def should_poll(self): def should_poll(self):
""" """ Polling needed."""
We should poll, because slaves are not allowed to
initiate communication on Modbus networks.
"""
return True return True
@property @property

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.mqtt Support for MQTT sensors.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a MQTT sensor.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.mqtt/ https://home-assistant.io/components/sensor.mqtt/
@ -62,12 +60,12 @@ class MqttSensor(Entity):
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed """ """No polling needed."""
return False return False
@property @property
def name(self): def name(self):
""" The name of the sensor """ """The name of the sensor."""
return self._name return self._name
@property @property

View File

@ -110,7 +110,7 @@ class MySensorsSensor(Entity):
@property @property
def should_poll(self): def should_poll(self):
"""MySensor gateway pushes its state to HA.""" """No polling needed."""
return False return False
@property @property

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.nest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Nest Thermostat Sensors. Support for Nest Thermostat Sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -42,7 +40,6 @@ SENSOR_TEMP_TYPES = ['temperature',
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup Nest Sensor.""" """Setup Nest Sensor."""
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
try: try:
for structure in nest.NEST.structures: for structure in nest.NEST.structures:
@ -81,7 +78,6 @@ class NestSensor(Entity):
@property @property
def name(self): def name(self):
"""Returns the name of the nest, if any.""" """Returns the name of the nest, if any."""
location = self.device.where location = self.device.where
name = self.device.name name = self.device.name
if location is None: if location is None:
@ -97,7 +93,6 @@ class NestSensor(Entity):
class NestBasicSensor(NestSensor): class NestBasicSensor(NestSensor):
"""Represents a basic Nest sensor with state.""" """Represents a basic Nest sensor with state."""
@property @property
def state(self): def state(self):
"""Returns the state of the sensor.""" """Returns the state of the sensor."""
@ -111,7 +106,6 @@ class NestBasicSensor(NestSensor):
class NestTempSensor(NestSensor): class NestTempSensor(NestSensor):
"""Represents a Nest Temperature sensor.""" """Represents a Nest Temperature sensor."""
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Unit the value is expressed in.""" """Unit the value is expressed in."""
@ -129,7 +123,6 @@ class NestTempSensor(NestSensor):
class NestWeatherSensor(NestSensor): class NestWeatherSensor(NestSensor):
"""Represents a basic Nest Weather Conditions sensor.""" """Represents a basic Nest Weather Conditions sensor."""
@property @property
def state(self): def state(self):
"""Returns the state of the sensor.""" """Returns the state of the sensor."""

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.netatmo Support for the NetAtmo Weather Service.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NetAtmo Weather Service service.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.netatmo/ https://home-assistant.io/components/sensor.netatmo/
@ -42,7 +40,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the NetAtmo sensor.""" """Get the NetAtmo sensor."""
if not validate_config({DOMAIN: config}, if not validate_config({DOMAIN: config},
{DOMAIN: [CONF_API_KEY, {DOMAIN: [CONF_API_KEY,
CONF_USERNAME, CONF_USERNAME,
@ -103,10 +100,12 @@ class NetAtmoSensor(Entity):
@property @property
def name(self): def name(self):
"""The name of the sensor."""
return self._name return self._name
@property @property
def icon(self): def icon(self):
"""Icon to use in the frontend, if any."""
return SENSOR_TYPES[self.type][2] return SENSOR_TYPES[self.type][2]
@property @property
@ -122,7 +121,6 @@ class NetAtmoSensor(Entity):
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
def update(self): def update(self):
"""Gets the latest data from NetAtmo API and updates the states.""" """Gets the latest data from NetAtmo API and updates the states."""
self.netatmo_data.update() self.netatmo_data.update()
data = self.netatmo_data.data[self.module_name] data = self.netatmo_data.data[self.module_name]
@ -154,6 +152,5 @@ class NetAtmoData(object):
def update(self): def update(self):
"""Call the NetAtmo API to update the data.""" """Call the NetAtmo API to update the data."""
import lnetatmo import lnetatmo
# Gets the latest data from NetAtmo. """
dev_list = lnetatmo.DeviceList(self.auth) dev_list = lnetatmo.DeviceList(self.auth)
self.data = dev_list.lastData(exclude=3600) self.data = dev_list.lastData(exclude=3600)

View File

@ -1,7 +1,6 @@
""" """
homeassistant.components.sensor.neurio_energy Support for monitoring an neurio hub.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monitors home energy use as measured by an neurio hub using its official API.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.neurio_energy/ https://home-assistant.io/components/sensor.neurio_energy/
""" """
@ -56,12 +55,12 @@ class NeurioEnergy(Entity):
@property @property
def name(self): def name(self):
""" Returns the name. """ """Returns the name of th sensor."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.onewire
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for DS18B20 One Wire Sensors. Support for DS18B20 One Wire Sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -80,7 +78,7 @@ class OneWire(Entity):
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.openweathermap Support for the OpenWeatherMap (OWM) service.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OpenWeatherMap (OWM) service.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.openweathermap/ https://home-assistant.io/components/sensor.openweathermap/
@ -26,13 +24,12 @@ SENSOR_TYPES = {
'snow': ['Snow', 'mm'] 'snow': ['Snow', 'mm']
} }
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago.
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the OpenWeatherMap sensor.""" """Get the OpenWeatherMap sensor."""
if None in (hass.config.latitude, hass.config.longitude): if None in (hass.config.latitude, hass.config.longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config") _LOGGER.error("Latitude or longitude not set in Home Assistant config")
return False return False
@ -85,6 +82,7 @@ class OpenWeatherMapSensor(Entity):
@property @property
def name(self): def name(self):
"""The name of the sensor."""
return '{} {}'.format(self.client_name, self._name) return '{} {}'.format(self.client_name, self._name)
@property @property
@ -100,7 +98,6 @@ class OpenWeatherMapSensor(Entity):
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
def update(self): def update(self):
"""Gets the latest data from OWM and updates the states.""" """Gets the latest data from OWM and updates the states."""
self.owa_client.update() self.owa_client.update()
data = self.owa_client.data data = self.owa_client.data
fc_data = self.owa_client.fc_data fc_data = self.owa_client.fc_data

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.rest Support for REST API sensors..
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The rest sensor will consume responses sent by an exposed REST API.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.rest/ https://home-assistant.io/components/sensor.rest/

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.rfxtrx Support for RFXtrx sensors.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows sensor values from RFXtrx sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.rfxtrx/ https://home-assistant.io/components/sensor.rfxtrx/
@ -74,11 +72,12 @@ class RfxtrxSensor(Entity):
id_string) id_string)
def __str__(self): def __str__(self):
"""Returns the name."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
if self._data_type: if self._data_type:
return self.event.values[self._data_type] return self.event.values[self._data_type]
return None return None
@ -90,6 +89,7 @@ class RfxtrxSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Returns the state attributes."""
return self.event.values return self.event.values
@property @property

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.sabnzbd Support for monitoring an SABnzbd NZB client.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monitors SABnzbd NZB client API.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.sabnzbd/ https://home-assistant.io/components/sensor.sabnzbd/
@ -26,7 +24,6 @@ SENSOR_TYPES = {
} }
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
_THROTTLED_REFRESH = None _THROTTLED_REFRESH = None
@ -80,11 +77,12 @@ class SabnzbdSensor(Entity):
@property @property
def name(self): def name(self):
"""Returns the name of the sensor."""
return self.client_name + ' ' + self._name return self.client_name + ' ' + self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property
@ -104,6 +102,7 @@ class SabnzbdSensor(Entity):
) )
def update(self): def update(self):
"""Gets the latest data and updates the states."""
self.refresh_sabnzbd_data() self.refresh_sabnzbd_data()
if self.sabnzb_client.queue: if self.sabnzb_client.queue:
if self.type == 'current_status': if self.type == 'current_status':

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.speedtest Support for Speedtest.net based on speedtest-cli.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Speedtest.net sensor based on speedtest-cli.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.speedtest/ https://home-assistant.io/components/sensor.speedtest/
@ -74,6 +72,7 @@ class SpeedtestSensor(Entity):
@property @property
def name(self): def name(self):
"""The name of the sensor."""
return '{} {}'.format('Speedtest', self._name) return '{} {}'.format('Speedtest', self._name)
@property @property
@ -87,7 +86,7 @@ class SpeedtestSensor(Entity):
return self._unit_of_measurement return self._unit_of_measurement
def update(self): def update(self):
""" Gets the latest data from Forecast.io and updates the states. """ """Gets the latest data and updates the states."""
data = self.speedtest_client.data data = self.speedtest_client.data
if data is not None: if data is not None:
if self.type == 'ping': if self.type == 'ping':

View File

@ -1,8 +1,5 @@
""" """
homeassistant.components.sensor.swiss_public_transport Support for transport.opendata.ch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Swiss public transport sensor will give you the next two departure times
from a given location to another one. This sensor is limited to Switzerland.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.swiss_public_transport/ https://home-assistant.io/components/sensor.swiss_public_transport/
@ -26,7 +23,7 @@ ATTR_TARGET = 'Destination'
ATTR_REMAINING_TIME = 'Remaining time' ATTR_REMAINING_TIME = 'Remaining time'
ICON = 'mdi:bus' ICON = 'mdi:bus'
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago.
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
@ -67,12 +64,12 @@ class SwissPublicTransportSensor(Entity):
@property @property
def name(self): def name(self):
""" Returns the name. """ """Returns the name of the sensor."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property
@ -116,7 +113,6 @@ class PublicTransportData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):
"""Gets the latest data from opendata.ch.""" """Gets the latest data from opendata.ch."""
response = requests.get( response = requests.get(
_RESOURCE + _RESOURCE +
'connections?' + 'connections?' +

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.systemmonitor Support for monitoring the local system..
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows system monitor values such as: disk, memory, and processor use.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.systemmonitor/ https://home-assistant.io/components/sensor.systemmonitor/
@ -41,7 +39,6 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the sensors.""" """Sets up the sensors."""
dev = [] dev = []
for resource in config['resources']: for resource in config['resources']:
if 'arg' not in resource: if 'arg' not in resource:
@ -87,7 +84,7 @@ class SystemMonitorSensor(Entity):
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
def update(self): def update(self):
""" Get the latest system informations. """ """Get the latest system information."""
import psutil import psutil
if self.type == 'disk_use_percent': if self.type == 'disk_use_percent':
self._state = psutil.disk_usage(self.argument).percent self._state = psutil.disk_usage(self.argument).percent

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.tellduslive Support for Tellstick Net/Telstick Live.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows sensor values from Tellstick Net/Telstick Live.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.tellduslive/ https://home-assistant.io/components/sensor.tellduslive/
@ -56,55 +54,63 @@ class TelldusLiveSensor(Entity):
_LOGGER.debug("created sensor %s", self) _LOGGER.debug("created sensor %s", self)
def update(self): def update(self):
""" update sensor values """ """Update sensor values."""
tellduslive.NETWORK.update_sensors() tellduslive.NETWORK.update_sensors()
self._sensor = tellduslive.NETWORK.get_sensor(self._id) self._sensor = tellduslive.NETWORK.get_sensor(self._id)
@property @property
def _sensor_name(self): def _sensor_name(self):
return self._sensor["name"] return self._sensor["name"]
@property @property
def _sensor_value(self): def _sensor_value(self):
return self._sensor["data"]["value"] return self._sensor["data"]["value"]
@property @property
def _sensor_type(self): def _sensor_type(self):
return self._sensor["data"]["name"] return self._sensor["data"]["name"]
@property @property
def _battery_level(self): def _battery_level(self):
sensor_battery_level = self._sensor.get("battery") sensor_battery_level = self._sensor.get("battery")
return round(sensor_battery_level * 100 / 255) \ return round(sensor_battery_level * 100 / 255) \
if sensor_battery_level else None if sensor_battery_level else None
@property @property
def _last_updated(self): def _last_updated(self):
sensor_last_updated = self._sensor.get("lastUpdated") sensor_last_updated = self._sensor.get("lastUpdated")
return str(datetime.fromtimestamp(sensor_last_updated)) \ return str(datetime.fromtimestamp(sensor_last_updated)) \
if sensor_last_updated else None if sensor_last_updated else None
@property @property
def _value_as_temperature(self): def _value_as_temperature(self):
return round(float(self._sensor_value), 1) return round(float(self._sensor_value), 1)
@property @property
def _value_as_humidity(self): def _value_as_humidity(self):
return int(round(float(self._sensor_value))) return int(round(float(self._sensor_value)))
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Returns the name of the sensor."""
return "{} {}".format(self._sensor_name or DEVICE_DEFAULT_NAME, return "{} {}".format(self._sensor_name or DEVICE_DEFAULT_NAME,
self.quantity_name) self.quantity_name)
@property @property
def available(self): def available(self):
return not self._sensor.get("offline", False) return not self._sensor.get("offline", False)
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
if self._sensor_type == SENSOR_TYPE_TEMP: if self._sensor_type == SENSOR_TYPE_TEMP:
return self._value_as_temperature return self._value_as_temperature
elif self._sensor_type == SENSOR_TYPE_HUMIDITY: elif self._sensor_type == SENSOR_TYPE_HUMIDITY:
@ -112,6 +118,7 @@ class TelldusLiveSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Returns the state attributes."""
attrs = {} attrs = {}
if self._battery_level is not None: if self._battery_level is not None:
attrs[ATTR_BATTERY_LEVEL] = self._battery_level attrs[ATTR_BATTERY_LEVEL] = self._battery_level
@ -121,13 +128,15 @@ class TelldusLiveSensor(Entity):
@property @property
def quantity_name(self): def quantity_name(self):
""" name of quantity """ """Name of quantity."""
return SENSOR_TYPES[self._sensor_type][0] return SENSOR_TYPES[self._sensor_type][0]
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
return SENSOR_TYPES[self._sensor_type][1] return SENSOR_TYPES[self._sensor_type][1]
@property @property
def icon(self): def icon(self):
return SENSOR_TYPES[self._sensor_type][2] return SENSOR_TYPES[self._sensor_type][2]

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.tellstick Support for Tellstick sensors.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows sensor values from Tellstick sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.tellstick/ https://home-assistant.io/components/sensor.tellstick/
@ -90,14 +88,15 @@ class TellstickSensor(Entity):
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Returns the name of the sensor."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self.sensor.value(self.datatype).value return self.sensor.value(self.datatype).value
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
return self._unit_of_measurement return self._unit_of_measurement

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.temper
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for getting temperature from TEMPer devices. Support for getting temperature from TEMPer devices.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -32,6 +30,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class TemperSensor(Entity): class TemperSensor(Entity):
"""Represents an Temper temperature sensor.""" """Represents an Temper temperature sensor."""
def __init__(self, temper_device, temp_unit, name): def __init__(self, temper_device, temp_unit, name):
self.temper_device = temper_device self.temper_device = temper_device
self.temp_unit = temp_unit self.temp_unit = temp_unit

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.template
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows the creation of a sensor that breaks out state_attributes Allows the creation of a sensor that breaks out state_attributes
from other entities. from other entities.
@ -96,12 +94,12 @@ class SensorTemplate(Entity):
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Returns the name of the sensor."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property
@ -111,10 +109,11 @@ class SensorTemplate(Entity):
@property @property
def should_poll(self): def should_poll(self):
""" Tells Home Assistant not to poll this entity. """ """No polling needed."""
return False return False
def update(self): def update(self):
"""Gets the latest data and updates the states."""
try: try:
self._state = template.render(self.hass, self._template) self._state = template.render(self.hass, self._template)
except TemplateError as ex: except TemplateError as ex:

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.time_date Support for showing the date and the time.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date and Time service.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.time_date/ https://home-assistant.io/components/sensor.time_date/
@ -51,16 +49,17 @@ class TimeDateSensor(Entity):
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Returns the name of the sensor."""
return self._name return self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property
def icon(self): def icon(self):
"""Icon to use in the frontend, if any."""
if "date" in self.type and "time" in self.type: if "date" in self.type and "time" in self.type:
return "mdi:calendar-clock" return "mdi:calendar-clock"
elif "date" in self.type: elif "date" in self.type:
@ -70,7 +69,6 @@ class TimeDateSensor(Entity):
def update(self): def update(self):
"""Gets the latest data and updates the states.""" """Gets the latest data and updates the states."""
time_date = dt_util.utcnow() time_date = dt_util.utcnow()
time = dt_util.datetime_to_time_str(dt_util.as_local(time_date)) time = dt_util.datetime_to_time_str(dt_util.as_local(time_date))
time_utc = dt_util.datetime_to_time_str(time_date) time_utc = dt_util.datetime_to_time_str(time_date)

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.torque Support for the Torque OBD application.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get data from the Torque OBD application.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.torque/ https://home-assistant.io/components/sensor.torque/
@ -41,7 +39,6 @@ def convert_pid(value):
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Torque platform.""" """Set up Torque platform."""
vehicle = config.get('name', DEFAULT_NAME) vehicle = config.get('name', DEFAULT_NAME)
email = config.get('email', None) email = config.get('email', None)
sensors = {} sensors = {}

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.transmission Support for monitoring the Transmission BitTorrent client API.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monitors Transmission BitTorrent client API.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.transmission/ https://home-assistant.io/components/sensor.transmission/
@ -41,9 +39,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.error('Missing config variable %s', CONF_HOST) _LOGGER.error('Missing config variable %s', CONF_HOST)
return False return False
# import logging
# logging.getLogger('transmissionrpc').setLevel(logging.DEBUG)
transmission_api = transmissionrpc.Client( transmission_api = transmissionrpc.Client(
host, port=port, user=username, password=password) host, port=port, user=username, password=password)
try: try:
@ -81,11 +76,12 @@ class TransmissionSensor(Entity):
@property @property
def name(self): def name(self):
"""Returns the name of the sensor."""
return self.client_name + ' ' + self._name return self.client_name + ' ' + self._name
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return self._state return self._state
@property @property

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.twitch Support for the Twitch stream status.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A sensor for the Twitch stream status.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.twitch/ https://home-assistant.io/components/sensor.twitch/

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.vera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Vera sensors. Support for Vera sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -40,7 +38,7 @@ def get_devices(hass, config):
if created: if created:
def stop_subscription(event): def stop_subscription(event):
""" Shutdown Vera subscriptions and subscription thread on exit""" """Shutdown Vera subscriptions and subscription thread on exit."""
_LOGGER.info("Shutting down subscriptions.") _LOGGER.info("Shutting down subscriptions.")
vera_controller.stop() vera_controller.stop()
@ -54,7 +52,7 @@ def get_devices(hass, config):
try: try:
devices = vera_controller.get_devices(categories) devices = vera_controller.get_devices(categories)
except RequestException: except RequestException:
# There was a network related error connecting to the vera controller # There was a network related error connecting to the vera controller.
_LOGGER.exception("Error communicating with Vera API") _LOGGER.exception("Error communicating with Vera API")
return False return False
@ -101,6 +99,7 @@ class VeraSensor(Entity):
@property @property
def state(self): def state(self):
"""Returns the name of the sensor."""
return self.current_value return self.current_value
@property @property
@ -120,6 +119,7 @@ class VeraSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Returns the sensor's attributes."""
attr = {} attr = {}
if self.vera_device.has_battery: if self.vera_device.has_battery:
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%' attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
@ -144,10 +144,11 @@ class VeraSensor(Entity):
@property @property
def should_poll(self): def should_poll(self):
""" Tells Home Assistant not to poll this entity. """ """No polling needed."""
return False return False
def update(self): def update(self):
"""Updates the state."""
if self.vera_device.category == "Temperature Sensor": if self.vera_device.category == "Temperature Sensor":
current_temp = self.vera_device.temperature current_temp = self.vera_device.temperature
vera_temp_units = ( vera_temp_units = (

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.verisure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Interfaces with Verisure sensors. Interfaces with Verisure sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -17,7 +15,6 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Verisure platform.""" """Sets up the Verisure platform."""
if not verisure.MY_PAGES: if not verisure.MY_PAGES:
_LOGGER.error('A connection has not been made to Verisure mypages.') _LOGGER.error('A connection has not been made to Verisure mypages.')
return False return False
@ -49,7 +46,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class VerisureThermometer(Entity): class VerisureThermometer(Entity):
""" represents a Verisure thermometer within home assistant. """ """Represents a Verisure thermometer."""
def __init__(self, climate_status): def __init__(self, climate_status):
self._id = climate_status.id self._id = climate_status.id
@ -69,66 +66,66 @@ class VerisureThermometer(Entity):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
""" Unit of measurement of this entity """ """Unit of measurement of this entity."""
return TEMP_CELCIUS # can verisure report in fahrenheit? return TEMP_CELCIUS # can verisure report in fahrenheit?
def update(self): def update(self):
""" update sensor """ """Update the sensor."""
verisure.update_climate() verisure.update_climate()
class VerisureHygrometer(Entity): class VerisureHygrometer(Entity):
""" represents a Verisure hygrometer within home assistant. """ """Represents a Verisure hygrometer."""
def __init__(self, climate_status): def __init__(self, climate_status):
self._id = climate_status.id self._id = climate_status.id
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Returns the name of the sensor."""
return '{} {}'.format( return '{} {}'.format(
verisure.CLIMATE_STATUS[self._id].location, verisure.CLIMATE_STATUS[self._id].location,
"Humidity") "Humidity")
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
# remove % character # remove % character
return verisure.CLIMATE_STATUS[self._id].humidity[:-1] return verisure.CLIMATE_STATUS[self._id].humidity[:-1]
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
""" Unit of measurement of this entity """ """Unit of measurement of this sensor."""
return "%" return "%"
def update(self): def update(self):
""" update sensor """ """Update sensor the sensor."""
verisure.update_climate() verisure.update_climate()
class VerisureMouseDetection(Entity): class VerisureMouseDetection(Entity):
""" represents a Verisure mousedetector within home assistant. """ """ Represents a Verisure mouse detector."""
def __init__(self, mousedetection_status): def __init__(self, mousedetection_status):
self._id = mousedetection_status.deviceLabel self._id = mousedetection_status.deviceLabel
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """Returns the name of the sensor."""
return '{} {}'.format( return '{} {}'.format(
verisure.MOUSEDETECTION_STATUS[self._id].location, verisure.MOUSEDETECTION_STATUS[self._id].location,
"Mouse") "Mouse")
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """Returns the state of the sensor."""
return verisure.MOUSEDETECTION_STATUS[self._id].count return verisure.MOUSEDETECTION_STATUS[self._id].count
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
""" Unit of measurement of this entity """ """Unit of measurement of this sensor."""
return "Mice" return "Mice"
def update(self): def update(self):
""" update sensor """ """Update the sensor."""
verisure.update_mousedetection() verisure.update_mousedetection()

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.wink
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Wink sensors. Support for Wink sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -46,7 +44,7 @@ class WinkSensorDevice(Entity):
@property @property
def unique_id(self): def unique_id(self):
""" Returns the id of this wink sensor """ """Returns the id of this wink sensor."""
return "{}.{}".format(self.__class__, self.wink.device_id()) return "{}.{}".format(self.__class__, self.wink.device_id())
@property @property
@ -77,7 +75,7 @@ class WinkEggMinder(Entity):
@property @property
def unique_id(self): def unique_id(self):
""" Returns the id of this wink Egg Minder """ """Returns the id of this wink Egg Minder."""
return "{}.{}".format(self.__class__, self.wink.device_id()) return "{}.{}".format(self.__class__, self.wink.device_id())
@property @property

View File

@ -1,8 +1,5 @@
""" """
homeassistant.components.sensor.worldclock Support for showing the time in a different time zone.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Worldclock sensor let you display the current time of a different time
zone.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.worldclock/ https://home-assistant.io/components/sensor.worldclock/
@ -19,7 +16,6 @@ ICON = 'mdi:clock'
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the Worldclock sensor.""" """Get the Worldclock sensor."""
try: try:
time_zone = dt_util.get_time_zone(config.get('time_zone')) time_zone = dt_util.get_time_zone(config.get('time_zone'))
except AttributeError: except AttributeError:

View File

@ -1,7 +1,5 @@
""" """
homeassistant.components.sensor.yr Support for Yr.no weather service.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Yr.no weather service.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.yr/ https://home-assistant.io/components/sensor.yr/
@ -42,7 +40,6 @@ SENSOR_TYPES = {
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the Yr.no sensor.""" """Get the Yr.no sensor."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude) latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude) longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
elevation = config.get('elevation') elevation = config.get('elevation')
@ -92,6 +89,7 @@ class YrSensor(Entity):
@property @property
def name(self): def name(self):
"""The name of the sensor."""
return '{} {}'.format(self.client_name, self._name) return '{} {}'.format(self.client_name, self._name)
@property @property
@ -121,15 +119,14 @@ class YrSensor(Entity):
def update(self): def update(self):
"""Gets the latest data from yr.no and updates the states.""" """Gets the latest data from yr.no and updates the states."""
now = dt_util.utcnow() now = dt_util.utcnow()
# check if data should be updated # Check if data should be updated
if self._update is not None and now <= self._update: if self._update is not None and now <= self._update:
return return
self._weather.update() self._weather.update()
# find sensor # Find sensor
for time_entry in self._weather.data['product']['time']: for time_entry in self._weather.data['product']['time']:
valid_from = dt_util.str_to_datetime( valid_from = dt_util.str_to_datetime(
time_entry['@from'], "%Y-%m-%dT%H:%M:%SZ") time_entry['@from'], "%Y-%m-%dT%H:%M:%SZ")
@ -178,8 +175,8 @@ class YrData(object):
self.update() self.update()
def update(self): def update(self):
""" Gets the latest data from yr.no """ """Gets the latest data from yr.no."""
# check if new will be available # Check if new will be available
if self._nextrun is not None and dt_util.utcnow() <= self._nextrun: if self._nextrun is not None and dt_util.utcnow() <= self._nextrun:
return return
try: try:

View File

@ -1,6 +1,4 @@
""" """
homeassistant.components.sensor.zigbee
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Contains functionality to use a ZigBee device as a sensor. Contains functionality to use a ZigBee device as a sensor.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
@ -48,17 +46,21 @@ class ZigBeeTemperatureSensor(Entity):
@property @property
def name(self): def name(self):
"""The name of the sensor."""
return self._config.name return self._config.name
@property @property
def state(self): def state(self):
"""Returns the state of the sensor."""
return self._temp return self._temp
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Unit the value is expressed in."""
return TEMP_CELCIUS return TEMP_CELCIUS
def update(self, *args): def update(self, *args):
"""Gets the latest data."""
try: try:
self._temp = zigbee.DEVICE.get_temperature(self._config.address) self._temp = zigbee.DEVICE.get_temperature(self._config.address)
except zigbee.ZIGBEE_TX_FAILURE: except zigbee.ZIGBEE_TX_FAILURE:

View File

@ -1,10 +1,8 @@
""" """
homeassistant.components.sensor.zwave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Interfaces with Z-Wave sensors. Interfaces with Z-Wave sensors.
For more details about this platform, please refer to the documentation For more details about this platform, please refer to the documentation
at https://home-assistant.io/components/zwave/ at https://home-assistant.io/components/sensor.zwave/
""" """
# Because we do not compile openzwave on CI # Because we do not compile openzwave on CI
# pylint: disable=import-error # pylint: disable=import-error
@ -67,7 +65,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
value.node.product_id, value.node.product_id,
value.index) value.index)
# Check workaround mappings for specific devices # Check workaround mappings for specific devices.
if specific_sensor_key in DEVICE_MAPPINGS: if specific_sensor_key in DEVICE_MAPPINGS:
if DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_NO_OFF_EVENT: if DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_NO_OFF_EVENT:
# Default the multiplier to 4 # Default the multiplier to 4
@ -78,7 +76,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
elif DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_IGNORE: elif DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_IGNORE:
return return
# generic Device mappings # Generic Device mappings
elif value.command_class == COMMAND_CLASS_SENSOR_MULTILEVEL: elif value.command_class == COMMAND_CLASS_SENSOR_MULTILEVEL:
add_devices([ZWaveMultilevelSensor(value)]) add_devices([ZWaveMultilevelSensor(value)])
@ -109,6 +107,7 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Unit the value is expressed in."""
return self._value.units return self._value.units
def value_changed(self, value): def value_changed(self, value):
@ -119,17 +118,11 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
class ZWaveTriggerSensor(ZWaveSensor): class ZWaveTriggerSensor(ZWaveSensor):
""" """
Represents a stateless sensor which Represents a stateless sensor which triggers events just 'On'
triggers events just 'On' within Z-Wave. within Z-Wave.
""" """
def __init__(self, sensor_value, hass, re_arm_sec=60): def __init__(self, sensor_value, hass, re_arm_sec=60):
"""
:param sensor_value: The z-wave node
:param hass:
:param re_arm_sec: Set state to Off re_arm_sec after the last On event
:return:
"""
super(ZWaveTriggerSensor, self).__init__(sensor_value) super(ZWaveTriggerSensor, self).__init__(sensor_value)
self._hass = hass self._hass = hass
self.invalidate_after = dt_util.utcnow() self.invalidate_after = dt_util.utcnow()
@ -160,7 +153,6 @@ class ZWaveTriggerSensor(ZWaveSensor):
class ZWaveMultilevelSensor(ZWaveSensor): class ZWaveMultilevelSensor(ZWaveSensor):
"""Represents a multi level sensor Z-Wave sensor.""" """Represents a multi level sensor Z-Wave sensor."""
@property @property
def state(self): def state(self):
"""Returns the state of the sensor.""" """Returns the state of the sensor."""
@ -175,6 +167,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Unit the value is expressed in."""
unit = self._value.units unit = self._value.units
if unit == 'C': if unit == 'C':
@ -186,16 +179,15 @@ class ZWaveMultilevelSensor(ZWaveSensor):
class ZWaveAlarmSensor(ZWaveSensor): class ZWaveAlarmSensor(ZWaveSensor):
""" A Z-wave sensor that sends Alarm alerts """
A Z-wave sensor that sends Alarm alerts
Examples include certain Multisensors that have motion and Examples include certain Multisensors that have motion and vibration
vibration capabilities. Z-Wave defines various alarm types capabilities. Z-Wave defines various alarm types such as Smoke, Flood,
such as Smoke, Flood, Burglar, CarbonMonoxide, etc. Burglar, CarbonMonoxide, etc.
This wraps these alarms and allows you to use them to This wraps these alarms and allows you to use them to trigger things, etc.
trigger things, etc.
COMMAND_CLASS_ALARM is what we get here. COMMAND_CLASS_ALARM is what we get here.
""" """
# Empty subclass for now. Allows for later customizations
pass pass