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.
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.
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
supported.
@ -14,13 +12,11 @@ from homeassistant.const import DEVICE_DEFAULT_NAME
from homeassistant.helpers.entity import Entity
DEPENDENCIES = ['arduino']
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Arduino platform."""
# Verify that the Arduino board is present
if arduino.BOARD is None:
_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.
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):
"""Get the aREST sensor."""
resource = config.get(CONF_RESOURCE)
var_conf = config.get(CONF_MONITORED_VARIABLES)
pins = config.get('pins', None)
@ -53,7 +50,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
arest = ArestData(resource)
def make_renderer(value_template):
""" Creates renderer based on variable_template value """
"""Creates renderer based on variable_template value."""
if value_template is None:
return lambda value: value
@ -135,7 +132,7 @@ class ArestSensor(Entity):
@property
def state(self):
""" Returns the state of the device. """
"""Returns the state of the sensor."""
values = self.arest.data
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.
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):
"""Get the Bitcoin sensor."""
from blockchain.wallet import Wallet
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
class BitcoinSensor(Entity):
"""Implements a Bitcoin sensor."""
def __init__(self, data, option_type, currency, wallet=''):
self.data = data
self._name = OPTION_TYPES[option_type][0]
@ -98,16 +94,17 @@ class BitcoinSensor(Entity):
@property
def name(self):
""" Returns the name of the device. """
"""Returns the name of the sensor."""
return self._name
@property
def state(self):
""" Returns the state of the device. """
"""Returns the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
return self._unit_of_measurement
@property
@ -118,7 +115,6 @@ class BitcoinSensor(Entity):
# pylint: disable=too-many-branches
def update(self):
"""Gets the latest data and updates the states."""
self.data.update()
stats = self.data.stats
ticker = self.data.ticker
@ -177,7 +173,6 @@ class BitcoinSensor(Entity):
class BitcoinData(object):
"""Gets the latest data and updates the states."""
def __init__(self):
self.stats = None
self.ticker = None
@ -185,7 +180,6 @@ class BitcoinData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from blockchain.info."""
from blockchain import statistics, exchangerates
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.
For more details about this platform, please refer to the documentation at

View File

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

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.sensor.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has a couple of fake sensors.
"""
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):
"""A Demo sensor."""
def __init__(self, name, state, unit_of_measurement, battery):
self._name = name
self._state = state
@ -32,12 +29,12 @@ class DemoSensor(Entity):
@property
def name(self):
""" Returns the name of the device. """
"""Returns the name of the sensor."""
return self._name
@property
def state(self):
""" Returns the state of the device. """
"""Returns the state of the sensor."""
return self._state
@property

View File

@ -1,7 +1,5 @@
"""
homeassistant.components.sensor.dht
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adafruit DHT temperature and humidity sensor.
Support for Adafruit DHT temperature and humidity sensor.
For more details about this platform, please refer to the documentation at
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.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/'
'4101340de8d2457dd194bca1e8d11cbfc237e919.zip'
'#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):
"""Get the DHT sensor."""
# pylint: disable=import-error
import Adafruit_DHT
@ -71,7 +68,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class DHTSensor(Entity):
"""Implements an DHT sensor."""
def __init__(self, dht_client, sensor_type, temp_unit, name):
self.client_name = name
self._name = SENSOR_TYPES[sensor_type][0]
@ -84,11 +80,12 @@ class DHTSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
return '{} {}'.format(self.client_name, self._name)
@property
def state(self):
""" Returns the state of the device. """
"""Returns the state of the sensor."""
return self._state
@property
@ -98,7 +95,6 @@ class DHTSensor(Entity):
def update(self):
"""Gets the latest data from the DHT and updates the states."""
self.dht_client.update()
data = self.dht_client.data
@ -112,7 +108,6 @@ class DHTSensor(Entity):
class DHTClient(object):
"""Gets the latest data from the DHT sensor."""
def __init__(self, adafruit_dht, sensor, pin):
self.adafruit_dht = adafruit_dht
self.sensor = sensor

View File

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

View File

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

View File

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

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.sensor.eliqonline
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monitors home energy use for the eliq online service.
For more details about this platform, please refer to the documentation at
@ -52,7 +50,7 @@ class EliqSensor(Entity):
@property
def name(self):
""" Returns the name. """
"""Returns the name of the sensor."""
return self._name
@property
@ -76,4 +74,4 @@ class EliqSensor(Entity):
response = self.api.get_data_now(channelid=self.channel_id)
self._state = int(response.power)
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Forecast.io weather service.
Support for Forecast.io weather service.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.forecast/
@ -41,7 +39,7 @@ SENSOR_TYPES = {
'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)
@ -111,11 +109,12 @@ class ForeCastSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
return '{} {}'.format(self.client_name, self._name)
@property
def state(self):
""" Returns the state of the device. """
"""Returns the state of the sensor."""
return self._state
@property

View File

@ -1,7 +1,5 @@
"""
homeassistant.components.sensor.glances
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Gathers system information of hosts which running glances.
Support gahtering system information of hosts which are running glances.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.glances/
@ -39,7 +37,7 @@ SENSOR_TYPES = {
}
_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)
@ -156,7 +154,6 @@ class GlancesSensor(Entity):
# pylint: disable=too-few-public-methods
class GlancesData(object):
"""Class for handling the data retrieval."""
def __init__(self, resource):
self._resource = resource
self.data = dict()

View File

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

View File

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

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.modbus
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Modbus sensors.
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):
""" Read config and create Modbus devices. """
"""Create Modbus devices."""
sensors = []
slave = config.get("slave", None)
if modbus.TYPE == "serial" and not slave:
@ -66,14 +64,12 @@ class ModbusSensor(Entity):
self._coil = coil
def __str__(self):
"""Returns the name and the state of the sensor."""
return "%s: %s" % (self.name, self.state)
@property
def should_poll(self):
"""
We should poll, because slaves are not allowed to
initiate communication on Modbus networks.
"""
""" Polling needed."""
return True
@property

View File

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

View File

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

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.sensor.nest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Nest Thermostat Sensors.
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):
"""Setup Nest Sensor."""
logger = logging.getLogger(__name__)
try:
for structure in nest.NEST.structures:
@ -81,7 +78,6 @@ class NestSensor(Entity):
@property
def name(self):
"""Returns the name of the nest, if any."""
location = self.device.where
name = self.device.name
if location is None:
@ -97,7 +93,6 @@ class NestSensor(Entity):
class NestBasicSensor(NestSensor):
"""Represents a basic Nest sensor with state."""
@property
def state(self):
"""Returns the state of the sensor."""
@ -111,7 +106,6 @@ class NestBasicSensor(NestSensor):
class NestTempSensor(NestSensor):
"""Represents a Nest Temperature sensor."""
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
@ -129,7 +123,6 @@ class NestTempSensor(NestSensor):
class NestWeatherSensor(NestSensor):
"""Represents a basic Nest Weather Conditions sensor."""
@property
def state(self):
"""Returns the state of the sensor."""

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,5 @@
"""
homeassistant.components.sensor.swiss_public_transport
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
Support for transport.opendata.ch
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.swiss_public_transport/
@ -26,7 +23,7 @@ ATTR_TARGET = 'Destination'
ATTR_REMAINING_TIME = 'Remaining time'
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)
@ -67,12 +64,12 @@ class SwissPublicTransportSensor(Entity):
@property
def name(self):
""" Returns the name. """
"""Returns the name of the sensor."""
return self._name
@property
def state(self):
""" Returns the state of the device. """
"""Returns the state of the sensor."""
return self._state
@property
@ -116,7 +113,6 @@ class PublicTransportData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from opendata.ch."""
response = requests.get(
_RESOURCE +
'connections?' +

View File

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

View File

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

View File

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

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.sensor.temper
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for getting temperature from TEMPer devices.
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):
"""Represents an Temper temperature sensor."""
def __init__(self, temper_device, temp_unit, name):
self.temper_device = temper_device
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
from other entities.
@ -96,12 +94,12 @@ class SensorTemplate(Entity):
@property
def name(self):
""" Returns the name of the device. """
"""Returns the name of the sensor."""
return self._name
@property
def state(self):
""" Returns the state of the device. """
"""Returns the state of the sensor."""
return self._state
@property
@ -111,10 +109,11 @@ class SensorTemplate(Entity):
@property
def should_poll(self):
""" Tells Home Assistant not to poll this entity. """
"""No polling needed."""
return False
def update(self):
"""Gets the latest data and updates the states."""
try:
self._state = template.render(self.hass, self._template)
except TemplateError as ex:

View File

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

View File

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

View File

@ -1,7 +1,5 @@
"""
homeassistant.components.sensor.transmission
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monitors Transmission BitTorrent client API.
Support for monitoring the Transmission BitTorrent client API.
For more details about this platform, please refer to the documentation at
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)
return False
# import logging
# logging.getLogger('transmissionrpc').setLevel(logging.DEBUG)
transmission_api = transmissionrpc.Client(
host, port=port, user=username, password=password)
try:
@ -81,11 +76,12 @@ class TransmissionSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
return self.client_name + ' ' + self._name
@property
def state(self):
""" Returns the state of the device. """
"""Returns the state of the sensor."""
return self._state
@property

View File

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

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.sensor.vera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Vera sensors.
For more details about this platform, please refer to the documentation at
@ -40,7 +38,7 @@ def get_devices(hass, config):
if created:
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.")
vera_controller.stop()
@ -54,7 +52,7 @@ def get_devices(hass, config):
try:
devices = vera_controller.get_devices(categories)
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")
return False
@ -101,6 +99,7 @@ class VeraSensor(Entity):
@property
def state(self):
"""Returns the name of the sensor."""
return self.current_value
@property
@ -120,6 +119,7 @@ class VeraSensor(Entity):
@property
def device_state_attributes(self):
"""Returns the sensor's attributes."""
attr = {}
if self.vera_device.has_battery:
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
@ -144,10 +144,11 @@ class VeraSensor(Entity):
@property
def should_poll(self):
""" Tells Home Assistant not to poll this entity. """
"""No polling needed."""
return False
def update(self):
"""Updates the state."""
if self.vera_device.category == "Temperature Sensor":
current_temp = self.vera_device.temperature
vera_temp_units = (

View File

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

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.sensor.wink
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Wink sensors.
For more details about this platform, please refer to the documentation at
@ -46,7 +44,7 @@ class WinkSensorDevice(Entity):
@property
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())
@property
@ -77,7 +75,7 @@ class WinkEggMinder(Entity):
@property
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())
@property

View File

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

View File

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

View File

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

View File

@ -1,10 +1,8 @@
"""
homeassistant.components.sensor.zwave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Interfaces with Z-Wave sensors.
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
# pylint: disable=import-error
@ -67,7 +65,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
value.node.product_id,
value.index)
# Check workaround mappings for specific devices
# Check workaround mappings for specific devices.
if specific_sensor_key in DEVICE_MAPPINGS:
if DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_NO_OFF_EVENT:
# 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:
return
# generic Device mappings
# Generic Device mappings
elif value.command_class == COMMAND_CLASS_SENSOR_MULTILEVEL:
add_devices([ZWaveMultilevelSensor(value)])
@ -109,6 +107,7 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
return self._value.units
def value_changed(self, value):
@ -119,17 +118,11 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
class ZWaveTriggerSensor(ZWaveSensor):
"""
Represents a stateless sensor which
triggers events just 'On' within Z-Wave.
Represents a stateless sensor which triggers events just 'On'
within Z-Wave.
"""
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)
self._hass = hass
self.invalidate_after = dt_util.utcnow()
@ -160,7 +153,6 @@ class ZWaveTriggerSensor(ZWaveSensor):
class ZWaveMultilevelSensor(ZWaveSensor):
"""Represents a multi level sensor Z-Wave sensor."""
@property
def state(self):
"""Returns the state of the sensor."""
@ -175,6 +167,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
unit = self._value.units
if unit == 'C':
@ -186,16 +179,15 @@ class ZWaveMultilevelSensor(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
vibration capabilities. Z-Wave defines various alarm types
such as Smoke, Flood, Burglar, CarbonMonoxide, etc.
Examples include certain Multisensors that have motion and vibration
capabilities. Z-Wave defines various alarm types such as Smoke, Flood,
Burglar, CarbonMonoxide, etc.
This wraps these alarms and allows you to use them to
trigger things, etc.
This wraps these alarms and allows you to use them to trigger things, etc.
COMMAND_CLASS_ALARM is what we get here.
"""
# Empty subclass for now. Allows for later customizations
pass