Fix PEPE257 issues

This commit is contained in:
Fabian Affolter 2016-03-08 16:46:34 +01:00
parent 49ebc6d0b0
commit 8bff97083c
49 changed files with 429 additions and 363 deletions

View file

@ -20,10 +20,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""
Ensure that the 'type' config value has been set and use a specific unit
of measurement if required.
"""
"""Setup the APCUPSd sensor."""
typ = config.get(apcupsd.CONF_TYPE)
if typ is None:
_LOGGER.error(
@ -44,10 +41,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
def infer_unit(value):
"""
If the value ends with any of the units from ALL_UNITS, split the unit
off the end of the value and return the value, unit tuple pair. Else return
the original value and None as the unit.
"""If the value ends with any of the units from ALL_UNITS.
Split the unit off the end of the value and return the value, unit tuple
pair. Else return the original value and None as the unit.
"""
from apcaccess.status import ALL_UNITS
for unit in ALL_UNITS:
@ -57,8 +54,10 @@ def infer_unit(value):
class Sensor(Entity):
"""Generic sensor entity for APCUPSd status values."""
"""Representation of a sensor entity for APCUPSd status values."""
def __init__(self, config, data, unit=None):
"""Initialize the sensor."""
self._config = config
self._unit = unit
self._data = data
@ -67,17 +66,17 @@ class Sensor(Entity):
@property
def name(self):
"""The name of the UPS sensor."""
"""Return the name of the UPS sensor."""
return self._config.get("name", DEFAULT_NAME)
@property
def state(self):
"""True if the UPS is online, else False."""
"""Return true if the UPS is online, else False."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
if self._unit is None:
return self._inferred_unit
return self._unit

View file

@ -1,6 +1,7 @@
"""
Support for getting information from Arduino pins. Only analog pins are
supported.
Support for getting information from Arduino pins.
Only analog pins are supported.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.arduino/
@ -16,7 +17,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Arduino platform."""
"""Setup 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.')
@ -33,8 +34,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ArduinoSensor(Entity):
"""Represents an Arduino Sensor."""
"""Representation of an Arduino Sensor."""
def __init__(self, name, pin, pin_type):
"""Initialize the sensor."""
self._pin = pin
self._name = name or DEVICE_DEFAULT_NAME
self.pin_type = pin_type
@ -45,7 +48,7 @@ class ArduinoSensor(Entity):
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._value
@property

View file

@ -26,7 +26,7 @@ CONF_MONITORED_VARIABLES = 'monitored_variables'
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the aREST sensor."""
"""Setup the aREST sensor."""
resource = config.get(CONF_RESOURCE)
var_conf = config.get(CONF_MONITORED_VARIABLES)
pins = config.get('pins', None)
@ -51,7 +51,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."""
"""Create a renderer based on variable_template value."""
if value_template is None:
return lambda value: value
@ -100,10 +100,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-instance-attributes, too-many-arguments
class ArestSensor(Entity):
"""Implements an aREST sensor for exposed variables."""
"""Implementation of an aREST sensor for exposed variables."""
def __init__(self, arest, resource, location, name, variable=None,
pin=None, unit_of_measurement=None, renderer=None):
"""Initialize the sensor."""
self.arest = arest
self._resource = resource
self._name = '{} {}'.format(location.title(), name.title()) \
@ -123,17 +124,17 @@ class ArestSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
values = self.arest.data
if 'error' in values:
@ -145,22 +146,23 @@ class ArestSensor(Entity):
return value
def update(self):
"""Gets the latest data from aREST API."""
"""Get the latest data from aREST API."""
self.arest.update()
# pylint: disable=too-few-public-methods
class ArestData(object):
"""Class for handling the data retrieval for variables."""
"""The Class for handling the data retrieval for variables."""
def __init__(self, resource, pin=None):
"""Initialize the data object."""
self._resource = resource
self._pin = pin
self.data = {}
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from aREST device."""
"""Get the latest data from aREST device."""
try:
if self._pin is None:
response = requests.get(self._resource, timeout=10)

View file

@ -38,12 +38,12 @@ OPTION_TYPES = {
}
ICON = 'mdi:currency-btc'
# 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 Bitcoin sensor."""
"""Setup the Bitcoin sensor."""
from blockchain.wallet import Wallet
from blockchain import exchangerates, exceptions
@ -81,8 +81,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class BitcoinSensor(Entity):
"""Implements a Bitcoin sensor."""
"""Representation of a Bitcoin sensor."""
def __init__(self, data, option_type, currency, wallet=''):
"""Initialize the sensor."""
self.data = data
self._name = OPTION_TYPES[option_type][0]
self._unit_of_measurement = OPTION_TYPES[option_type][1]
@ -94,27 +96,27 @@ class BitcoinSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def icon(self):
"""Icon to use in the frontend, if any."""
"""Return the icon to use in the frontend, if any."""
return ICON
# pylint: disable=too-many-branches
def update(self):
"""Gets the latest data and updates the states."""
"""Get the latest data and updates the states."""
self.data.update()
stats = self.data.stats
ticker = self.data.ticker
@ -172,14 +174,16 @@ class BitcoinSensor(Entity):
class BitcoinData(object):
"""Gets the latest data and updates the states."""
"""Get the latest data and update the states."""
def __init__(self):
"""Initialize the data object."""
self.stats = None
self.ticker = None
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from blockchain.info."""
"""Get the latest data from blockchain.info."""
from blockchain import statistics, exchangerates
self.stats = statistics.get()

View file

@ -31,7 +31,7 @@ FORMAT_NUMBERS = ["Temperature", "Pressure"]
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the available BloomSky weather sensors."""
"""Setup the available BloomSky weather sensors."""
logger = logging.getLogger(__name__)
bloomsky = get_component('bloomsky')
sensors = config.get('monitored_conditions', SENSOR_TYPES)
@ -47,7 +47,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class BloomSkySensor(Entity):
"""Represents a single sensor in a BloomSky device."""
"""Representation of a single sensor in a BloomSky device."""
def __init__(self, bs, device, sensor_name):
"""Initialize a bloomsky sensor."""
@ -65,12 +65,12 @@ class BloomSkySensor(Entity):
@property
def unique_id(self):
"""Unique ID for this sensor."""
"""Return the unique ID for this sensor."""
return self._unique_id
@property
def state(self):
"""The current state (i.e. value) of this sensor."""
"""The current state, eg. value, of this sensor."""
return self._state
@property

View file

@ -23,8 +23,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Add the Command Sensor."""
"""Setup the Command Sensor."""
if config.get('command') is None:
_LOGGER.error('Missing required variable: "command"')
return False
@ -42,8 +41,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-many-arguments
class CommandSensor(Entity):
"""Represents a sensor that is returning a value of a shell commands."""
"""Representation of a sensor that is using shell commands."""
def __init__(self, hass, data, name, unit_of_measurement, value_template):
"""Initialize the sensor."""
self._hass = hass
self.data = data
self._name = name
@ -54,21 +55,21 @@ class CommandSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
def update(self):
"""Gets the latest data and updates the state."""
"""Get the latest data and updates the state."""
self.data.update()
value = self.data.value
@ -81,15 +82,16 @@ class CommandSensor(Entity):
# pylint: disable=too-few-public-methods
class CommandSensorData(object):
"""Class for handling the data retrieval."""
"""The class for handling the data retrieval."""
def __init__(self, command):
"""Initialize the data object."""
self.command = command
self.value = None
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data with a shell command."""
"""Get the latest data with a shell command."""
_LOGGER.info('Running command: %s', self.command)
try:

View file

@ -21,13 +21,15 @@ ICON = 'mdi:pulse'
# pylint: disable=unused-variable
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the CPU speed sensor."""
"""Setup the CPU speed sensor."""
add_devices([CpuSpeedSensor(config.get('name', DEFAULT_NAME))])
class CpuSpeedSensor(Entity):
"""Represents a CPU sensor."""
"""Representation a CPU sensor."""
def __init__(self, name):
"""Initialize the sensor."""
self._name = name
self._state = None
self._unit_of_measurement = 'GHz'
@ -35,22 +37,22 @@ class CpuSpeedSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def device_state_attributes(self):
"""Returns the state attributes."""
"""Return the state attributes."""
if self.info is not None:
return {
ATTR_VENDOR: self.info['vendor_id'],
@ -60,11 +62,11 @@ class CpuSpeedSensor(Entity):
@property
def icon(self):
"""Icon to use in the frontend, if any."""
"""Return the icon to use in the frontend, if any."""
return ICON
def update(self):
"""Gets the latest data and updates the state."""
"""Get the latest data and updates the state."""
from cpuinfo import cpuinfo
self.info = cpuinfo.get_cpu_info()

View file

@ -10,7 +10,7 @@ from homeassistant.helpers.entity import Entity
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Demo sensors."""
"""Setup the Demo sensors."""
add_devices([
DemoSensor('Outside Temperature', 15.6, TEMP_CELCIUS, 12),
DemoSensor('Outside Humidity', 54, '%', None),
@ -18,8 +18,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class DemoSensor(Entity):
"""A Demo sensor."""
"""Representation of a Demo sensor."""
def __init__(self, name, state, unit_of_measurement, battery):
"""Initialize the sensor."""
self._name = name
self._state = state
self._unit_of_measurement = unit_of_measurement

View file

@ -37,8 +37,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-few-public-methods
class DeutscheBahnSensor(Entity):
"""Implement a Deutsche Bahn sensor."""
"""Implementation of a Deutsche Bahn sensor."""
def __init__(self, start, goal):
"""Initialize the sensor."""
self._name = start + ' to ' + goal
self.data = SchieneData(start, goal)
self.update()
@ -64,7 +66,7 @@ class DeutscheBahnSensor(Entity):
return self.data.connections[0]
def update(self):
"""Gets the latest delay from bahn.de and updates the state."""
"""Get the latest delay from bahn.de and updates the state."""
self.data.update()
self._state = self.data.connections[0].get('departure', 'Unknown')
delay = self.data.connections[0].get('delay',
@ -76,8 +78,10 @@ class DeutscheBahnSensor(Entity):
# pylint: disable=too-few-public-methods
class SchieneData(object):
"""Pulls data from the bahn.de web page."""
"""Pull data from the bahn.de web page."""
def __init__(self, start, goal):
"""Initialize the sensor."""
import schiene
self.start = start
self.goal = goal

View file

@ -28,7 +28,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the DHT sensor."""
"""Setup the DHT sensor."""
# pylint: disable=import-error
import Adafruit_DHT
@ -67,8 +67,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class DHTSensor(Entity):
"""Implements an DHT sensor."""
"""Implementation of the DHT sensor."""
def __init__(self, dht_client, sensor_type, temp_unit, name):
"""Initialize the sensor."""
self.client_name = name
self._name = SENSOR_TYPES[sensor_type][0]
self.dht_client = dht_client
@ -80,21 +82,21 @@ class DHTSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return '{} {}'.format(self.client_name, self._name)
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
def update(self):
"""Gets the latest data from the DHT and updates the states."""
"""Get the latest data from the DHT and updates the states."""
self.dht_client.update()
data = self.dht_client.data
@ -107,8 +109,10 @@ class DHTSensor(Entity):
class DHTClient(object):
"""Gets the latest data from the DHT sensor."""
"""Get the latest data from the DHT sensor."""
def __init__(self, adafruit_dht, sensor, pin):
"""Initialize the sensor."""
self.adafruit_dht = adafruit_dht
self.sensor = sensor
self.pin = pin
@ -116,7 +120,7 @@ class DHTClient(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data the DHT sensor."""
"""Get the latest data the DHT sensor."""
humidity, temperature = self.adafruit_dht.read_retry(self.sensor,
self.pin)
if temperature:

View file

@ -59,8 +59,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-arguments
class DweetSensor(Entity):
"""Implements a Dweet sensor."""
"""Representation of a Dweet sensor."""
def __init__(self, hass, dweet, name, value_template, unit_of_measurement):
"""Initialize the sensor."""
self.hass = hass
self.dweet = dweet
self._name = name
@ -71,17 +73,17 @@ class DweetSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def state(self):
"""Returns the state."""
"""Return the state."""
if self.dweet.data is None:
return STATE_UNKNOWN
else:
@ -91,20 +93,22 @@ class DweetSensor(Entity):
return value
def update(self):
"""Gets the latest data from REST API."""
"""Get the latest data from REST API."""
self.dweet.update()
# pylint: disable=too-few-public-methods
class DweetData(object):
"""Class for handling the data retrieval."""
"""The class for handling the data retrieval."""
def __init__(self, device):
"""Initialize the sensor."""
self._device = device
self.data = None
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from Dweet.io."""
"""Get the latest data from Dweet.io."""
import dweepy
try:

View file

@ -22,7 +22,7 @@ ECOBEE_CONFIG_FILE = 'ecobee.conf'
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Ecobee sensors."""
"""Setup the Ecobee sensors."""
if discovery_info is None:
return
data = ecobee.NETWORK
@ -40,9 +40,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class EcobeeSensor(Entity):
"""An Ecobee sensor."""
"""Representation of an Ecobee sensor."""
def __init__(self, sensor_name, sensor_type, sensor_index):
"""Initialize the sensor."""
self._name = sensor_name + ' ' + SENSOR_TYPES[sensor_type][0]
self.sensor_name = sensor_name
self.type = sensor_type
@ -53,22 +54,22 @@ class EcobeeSensor(Entity):
@property
def name(self):
"""Returns the name of the Ecobee sensor."""
"""Return the name of the Ecobee sensor."""
return self._name.rstrip()
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unique_id(self):
"""Unique id of this sensor."""
"""Return the unique ID of this sensor."""
return "sensor_ecobee_{}_{}".format(self._name, self.index)
@property
def unit_of_measurement(self):
"""Unit of measurement this sensor expresses itself in."""
"""Return the unit of measurement this sensor expresses itself in."""
return self._unit_of_measurement
def update(self):

View file

@ -1,6 +1,5 @@
"""
Monitors home energy use as measured by an efergy engage hub using its
(unofficial, undocumented) API.
Support for Efergy sensors.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.efergy/
@ -21,7 +20,7 @@ SENSOR_TYPES = {
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Efergy sensor."""
"""Setup the Efergy sensor."""
app_token = config.get("app_token")
if not app_token:
_LOGGER.error(
@ -46,10 +45,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-instance-attributes
class EfergySensor(Entity):
"""Implements an Efergy sensor."""
"""Implementation of an Efergy sensor."""
# pylint: disable=too-many-arguments
def __init__(self, sensor_type, app_token, utc_offset, period, currency):
"""Initialize the sensor."""
self._name = SENSOR_TYPES[sensor_type][0]
self.type = sensor_type
self.app_token = app_token
@ -64,21 +64,21 @@ class EfergySensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
def update(self):
"""Gets the Efergy monitor data from the web service."""
"""Get the Efergy monitor data from the web service."""
try:
if self.type == 'instant_readings':
url_string = _RESOURCE + 'getInstant?token=' + self.app_token

View file

@ -17,8 +17,7 @@ DEFAULT_NAME = "ELIQ Energy Usage"
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Eliq sensor."""
"""Setup the Eliq sensor."""
import eliqonline
access_token = config.get(CONF_ACCESS_TOKEN)
@ -37,9 +36,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class EliqSensor(Entity):
"""Implements a Eliq sensor."""
"""Implementation of an Eliq sensor."""
def __init__(self, api, channel_id, name):
"""Initialize the sensor."""
self._name = name
self._unit_of_measurement = "W"
self._state = STATE_UNKNOWN
@ -50,26 +50,26 @@ class EliqSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def icon(self):
"""Returns icon."""
"""Return icon."""
return "mdi:speedometer"
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
def update(self):
"""Gets the latest data."""
"""Get the latest data."""
try:
response = self.api.get_data_now(channelid=self.channel_id)
self._state = int(response.power)

View file

@ -44,7 +44,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the Forecast.io sensor."""
"""Setup the Forecast.io sensor."""
import forecastio
if None in (hass.config.latitude, hass.config.longitude):
@ -86,9 +86,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class ForeCastSensor(Entity):
"""Implements an Forecast.io sensor."""
"""Implementation of a Forecast.io sensor."""
def __init__(self, weather_data, sensor_type):
"""Initialize the sensor."""
self.client_name = 'Weather'
self._name = SENSOR_TYPES[sensor_type][0]
self.forecast_client = weather_data
@ -109,27 +110,27 @@ class ForeCastSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return '{} {}'.format(self.client_name, self._name)
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
@property
def unit_system(self):
"""Unit system of this entity."""
"""Return the unit system of this entity."""
return self._unit_system
# pylint: disable=too-many-branches
def update(self):
"""Gets the latest data from Forecast.io and updates the states."""
"""Get the latest data from Forecast.io and updates the states."""
import forecastio
self.forecast_client.update()
@ -179,6 +180,7 @@ class ForeCastData(object):
"""Gets the latest data from Forecast.io."""
def __init__(self, api_key, latitude, longitude, units):
"""Initialize the data object."""
self._api_key = api_key
self.latitude = latitude
self.longitude = longitude
@ -189,7 +191,7 @@ class ForeCastData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from Forecast.io."""
"""Get the latest data from Forecast.io."""
import forecastio
forecast = forecastio.load_forecast(self._api_key,

View file

@ -44,7 +44,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
# pylint: disable=unused-variable
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Glances sensor."""
host = config.get(CONF_HOST)
port = config.get('port', CONF_PORT)
url = 'http://{}:{}{}'.format(host, port, _RESOURCE)
@ -83,9 +82,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class GlancesSensor(Entity):
"""Implements a Glances sensor."""
"""Implementation of a Glances sensor."""
def __init__(self, rest, name, sensor_type):
"""Initialize the sensor."""
self.rest = rest
self._name = name
self.type = sensor_type
@ -103,13 +103,13 @@ class GlancesSensor(Entity):
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
# pylint: disable=too-many-branches, too-many-return-statements
@property
def state(self):
"""Returns the state of the resources."""
"""Return the state of the resources."""
value = self.rest.data
if value is not None:
@ -147,20 +147,22 @@ class GlancesSensor(Entity):
return value['processcount']['sleeping']
def update(self):
"""Gets the latest data from REST API."""
"""Get the latest data from REST API."""
self.rest.update()
# pylint: disable=too-few-public-methods
class GlancesData(object):
"""Class for handling the data retrieval."""
"""The class for handling the data retrieval."""
def __init__(self, resource):
"""Initialize the data object."""
self._resource = resource
self.data = dict()
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from the Glances REST API."""
"""Get the latest data from the Glances REST API."""
try:
response = requests.get(self._resource, timeout=10)
self.data = response.json()

View file

@ -27,7 +27,7 @@ DEFAULT_HIDDEN_WEATHER = ['Temperature_High', 'Temperature_Low', 'Feels_Like',
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the ISY994 platform."""
"""Setup the ISY994 platform."""
# pylint: disable=protected-access
logger = logging.getLogger(__name__)
devs = []
@ -74,9 +74,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class WeatherPseudoNode(object):
"""This class allows weather variable to act as regular nodes."""
# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods
def __init__(self, device_id, name, status, units=None):
"""Initialize the sensor."""
self._id = device_id
self.name = name
self.status = status
@ -84,9 +85,11 @@ class WeatherPseudoNode(object):
class ISYSensorDevice(ISYDeviceABC):
"""Represents a ISY sensor."""
"""Representation of an ISY sensor."""
_domain = 'sensor'
def __init__(self, node, states=None):
"""Initialize the device."""
super().__init__(node)
self._states = states or []

View file

@ -38,7 +38,7 @@ CONF_VERIFY_TLS = 'verify_tls'
# pylint: disable=unused-variable
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up mFi sensors."""
"""Setup mFi sensors."""
if not validate_config({DOMAIN: config},
{DOMAIN: ['host',
CONF_USERNAME,
@ -71,20 +71,21 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class MfiSensor(Entity):
"""An mFi sensor that exposes tag=value."""
"""Representation of a mFi sensor."""
def __init__(self, port, hass):
"""Initialize the sensor."""
self._port = port
self._hass = hass
@property
def name(self):
"""Returns the name of th sensor."""
"""Return the name of th sensor."""
return self._port.label
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
if self._port.model == 'Input Digital':
return self._port.value > 0 and STATE_ON or STATE_OFF
else:
@ -93,7 +94,7 @@ class MfiSensor(Entity):
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
if self._port.tag == 'temperature':
return TEMP_CELCIUS
elif self._port.tag == 'active_pwr':
@ -103,5 +104,5 @@ class MfiSensor(Entity):
return self._port.tag
def update(self):
"""Gets the latest data."""
"""Get the latest data."""
self._port.refresh()

View file

@ -16,7 +16,7 @@ DEPENDENCIES = ['modbus']
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Create Modbus devices."""
"""Setup Modbus devices."""
sensors = []
slave = config.get("slave", None)
if modbus.TYPE == "serial" and not slave:
@ -51,10 +51,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ModbusSensor(Entity):
# pylint: disable=too-many-arguments
"""Represents a Modbus Sensor."""
"""Representation of a Modbus Sensor."""
# pylint: disable=too-many-arguments
def __init__(self, name, slave, register, bit=None, unit=None, coil=False):
"""Initialize the sensor."""
self._name = name
self.slave = int(slave) if slave else 1
self.register = int(register)
@ -64,24 +65,24 @@ class ModbusSensor(Entity):
self._coil = coil
def __str__(self):
"""Returns the name and the state of the sensor."""
"""Return the name and the state of the sensor."""
return "%s: %s" % (self.name, self.state)
@property
def should_poll(self):
""" Polling needed."""
"""Polling needed."""
return True
@property
def unique_id(self):
"""Returns a unique id."""
"""Return a unique id."""
return "MODBUS-SENSOR-{}-{}-{}".format(self.slave,
self.register,
self.bit)
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
if self.bit:
return STATE_ON if self._value else STATE_OFF
else:
@ -89,12 +90,12 @@ class ModbusSensor(Entity):
@property
def name(self):
"""Get the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
if self._unit == "C":
return TEMP_CELCIUS
elif self._unit == "F":

View file

@ -21,8 +21,7 @@ DEPENDENCIES = ['mqtt']
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Add MQTT Sensor."""
"""Setup MQTT Sensor."""
if config.get('state_topic') is None:
_LOGGER.error("Missing required variable: state_topic")
return False
@ -38,9 +37,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-many-arguments, too-many-instance-attributes
class MqttSensor(Entity):
"""Represents a sensor that can be updated using MQTT."""
"""Representation of a sensor that can be updated using MQTT."""
def __init__(self, hass, name, state_topic, qos, unit_of_measurement,
value_template):
"""Initialize the sensor."""
self._state = STATE_UNKNOWN
self._hass = hass
self._name = name
@ -65,15 +66,15 @@ class MqttSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Unit this state is expressed in."""
"""Return the unit this state is expressed in."""
return self._unit_of_measurement
@property
def state(self):
"""Returns the state of the entity."""
"""Return the state of the entity."""
return self._state

View file

@ -117,7 +117,7 @@ class MySensorsSensor(Entity):
@property
def name(self):
"""The name of this entity."""
"""Return the name of this entity."""
return self._name
@property
@ -129,7 +129,7 @@ class MySensorsSensor(Entity):
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity."""
"""Return the unit of measurement of this entity."""
set_req = self.gateway.const.SetReq
unit_map = {
set_req.V_TEMP: (TEMP_CELCIUS

View file

@ -39,7 +39,7 @@ SENSOR_TEMP_TYPES = ['temperature',
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup Nest Sensor."""
"""Setup the Nest Sensor."""
logger = logging.getLogger(__name__)
try:
for structure in nest.NEST.structures:
@ -68,16 +68,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class NestSensor(Entity):
"""Represents a Nest sensor."""
"""Representation of a Nest sensor."""
def __init__(self, structure, device, variable):
"""Initialize the sensor."""
self.structure = structure
self.device = device
self.variable = variable
@property
def name(self):
"""Returns the name of the nest, if any."""
"""Return the name of the nest, if any."""
location = self.device.where
name = self.device.name
if location is None:
@ -92,28 +93,30 @@ class NestSensor(Entity):
class NestBasicSensor(NestSensor):
"""Represents a basic Nest sensor with state."""
"""Representation a basic Nest sensor."""
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return getattr(self.device, self.variable)
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return SENSOR_UNITS.get(self.variable, None)
class NestTempSensor(NestSensor):
"""Represents a Nest Temperature sensor."""
"""Representation of a Nest Temperature sensor."""
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return TEMP_CELCIUS
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
temp = getattr(self.device, self.variable)
if temp is None:
return None
@ -122,10 +125,11 @@ class NestTempSensor(NestSensor):
class NestWeatherSensor(NestSensor):
"""Represents a basic Nest Weather Conditions sensor."""
"""Representation a basic Nest Weather Conditions sensor."""
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
if self.variable == 'kph' or self.variable == 'direction':
return getattr(self.structure.weather.current.wind, self.variable)
else:
@ -133,5 +137,5 @@ class NestWeatherSensor(NestSensor):
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return SENSOR_UNITS.get(self.variable, None)

View file

@ -42,7 +42,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the NetAtmo sensor."""
"""Setup the NetAtmo sensor."""
if not validate_config({DOMAIN: config},
{DOMAIN: [CONF_API_KEY,
CONF_USERNAME,
@ -89,9 +89,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class NetAtmoSensor(Entity):
"""Implements a NetAtmo sensor."""
"""Implementation of a NetAtmo sensor."""
def __init__(self, netatmo_data, module_name, sensor_type):
"""Initialize the sensor."""
self._name = "NetAtmo {} {}".format(module_name,
SENSOR_TYPES[sensor_type][0])
self.netatmo_data = netatmo_data
@ -103,7 +104,7 @@ class NetAtmoSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
@ -113,17 +114,17 @@ class NetAtmoSensor(Entity):
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
# pylint: disable=too-many-branches
def update(self):
"""Gets the latest data from NetAtmo API and updates the states."""
"""Get the latest data from NetAtmo API and updates the states."""
self.netatmo_data.update()
data = self.netatmo_data.data[self.module_name]
@ -146,9 +147,10 @@ class NetAtmoSensor(Entity):
class NetAtmoData(object):
"""Gets the latest data from NetAtmo."""
"""Get the latest data from NetAtmo."""
def __init__(self, auth):
"""Initialize the data object."""
self.auth = auth
self.data = None

View file

@ -18,7 +18,7 @@ ICON = 'mdi:flash'
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Neurio sensor."""
"""Setup the Neurio sensor."""
api_key = config.get("api_key")
api_secret = config.get("api_secret")
sensor_id = config.get("sensor_id")
@ -42,10 +42,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-instance-attributes
class NeurioEnergy(Entity):
"""Implements an Neurio energy."""
"""Implementation of an Neurio energy."""
# pylint: disable=too-many-arguments
def __init__(self, api_key, api_secret, sensor_id):
"""Initialize the sensor."""
self._name = "Energy Usage"
self.api_key = api_key
self.api_secret = api_secret
@ -55,17 +56,17 @@ class NeurioEnergy(Entity):
@property
def name(self):
"""Returns the name of th sensor."""
"""Return the name of th sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
@property
@ -74,7 +75,7 @@ class NeurioEnergy(Entity):
return ICON
def update(self):
"""Gets the Neurio monitor data from the web service."""
"""Get the Neurio monitor data from the web service."""
import neurio
try:
neurio_tp = neurio.TokenProvider(key=self.api_key,

View file

@ -25,8 +25,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the one wire Sensors."""
"""Setup the one wire Sensors."""
if DEVICE_FILES == []:
_LOGGER.error('No onewire sensor found.')
_LOGGER.error('Check if dtoverlay=w1-gpio,gpiopin=4.')
@ -56,9 +55,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class OneWire(Entity):
"""An One wire Sensor."""
"""Implementation of an One wire Sensor."""
def __init__(self, name, device_file):
"""Initialize the sensor."""
self._name = name
self._device_file = device_file
self._state = STATE_UNKNOWN
@ -73,21 +73,21 @@ class OneWire(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return TEMP_CELCIUS
def update(self):
"""Gets the latest data from the device."""
"""Get the latest data from the device."""
lines = self._read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)

View file

@ -29,7 +29,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the OpenWeatherMap sensor."""
"""Setup 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
@ -68,9 +68,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class OpenWeatherMapSensor(Entity):
"""Implements an OpenWeatherMap sensor."""
"""Implementation of an OpenWeatherMap sensor."""
def __init__(self, weather_data, sensor_type, temp_unit):
"""Initialize the sensor."""
self.client_name = 'Weather'
self._name = SENSOR_TYPES[sensor_type][0]
self.owa_client = weather_data
@ -82,22 +83,22 @@ class OpenWeatherMapSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return '{} {}'.format(self.client_name, self._name)
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
# pylint: disable=too-many-branches
def update(self):
"""Gets the latest data from OWM and updates the states."""
"""Get 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
@ -140,9 +141,10 @@ class OpenWeatherMapSensor(Entity):
class WeatherData(object):
"""Gets the latest data from OpenWeatherMap."""
"""Get the latest data from OpenWeatherMap."""
def __init__(self, owm, forecast, latitude, longitude):
"""Initialize the data object."""
self.owm = owm
self.forecast = forecast
self.latitude = latitude
@ -152,7 +154,7 @@ class WeatherData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from OpenWeatherMap."""
"""Get the latest data from OpenWeatherMap."""
obs = self.owm.weather_at_coords(self.latitude, self.longitude)
if obs is None:
_LOGGER.warning('Failed to fetch data from OWM')

View file

@ -25,7 +25,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
# pylint: disable=unused-variable
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the REST sensor."""
"""Setup the REST sensor."""
resource = config.get('resource', None)
method = config.get('method', DEFAULT_METHOD)
payload = config.get('payload', None)
@ -45,9 +45,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-arguments
class RestSensor(Entity):
"""Implements a REST sensor."""
"""Implementation of a REST sensor."""
def __init__(self, hass, rest, name, unit_of_measurement, value_template):
"""Initialize the sensor."""
self._hass = hass
self.rest = rest
self._name = name
@ -58,21 +59,21 @@ class RestSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
def update(self):
"""Gets the latest data from REST API and updates the state."""
"""Get the latest data from REST API and update the state."""
self.rest.update()
value = self.rest.data
@ -90,13 +91,14 @@ class RestData(object):
"""Class for handling the data retrieval."""
def __init__(self, method, resource, data, verify_ssl):
"""Initialize the data object."""
self._request = requests.Request(method, resource, data=data).prepare()
self._verify_ssl = verify_ssl
self.data = None
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from REST service with GET method."""
"""Get the latest data from REST service with GET method."""
try:
with requests.Session() as sess:
response = sess.send(self._request, timeout=10,

View file

@ -73,9 +73,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxSensor(Entity):
"""Represents a RFXtrx sensor."""
"""Representation of a RFXtrx sensor."""
def __init__(self, event, name, data_type=None):
"""Initialize the sensor."""
self.event = event
self._unit_of_measurement = None
self._data_type = None
@ -91,12 +92,12 @@ class RfxtrxSensor(Entity):
break
def __str__(self):
"""Returns the name."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
if self._data_type:
return self.event.values[self._data_type]
return None
@ -108,10 +109,10 @@ class RfxtrxSensor(Entity):
@property
def device_state_attributes(self):
"""Returns the state attributes."""
"""Return the state attributes."""
return self.event.values
@property
def unit_of_measurement(self):
"""Unit this state is expressed in."""
"""Return the unit this state is expressed in."""
return self._unit_of_measurement

View file

@ -29,7 +29,7 @@ _THROTTLED_REFRESH = None
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the SABnzbd sensors."""
"""Setup the SABnzbd sensors."""
from pysabnzbd import SabnzbdApi, SabnzbdApiException
api_key = config.get("api_key")
@ -65,9 +65,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class SabnzbdSensor(Entity):
"""Represents an SABnzbd sensor."""
"""Representation of an SABnzbd sensor."""
def __init__(self, sensor_type, sabnzb_client, client_name):
"""Initialize the sensor."""
self._name = SENSOR_TYPES[sensor_type][0]
self.sabnzb_client = sabnzb_client
self.type = sensor_type
@ -77,21 +78,21 @@ class SabnzbdSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self.client_name + ' ' + self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
def refresh_sabnzbd_data(self):
"""Calls the throttled SABnzbd refresh method."""
"""Call the throttled SABnzbd refresh method."""
if _THROTTLED_REFRESH is not None:
from pysabnzbd import SabnzbdApiException
try:
@ -102,7 +103,7 @@ class SabnzbdSensor(Entity):
)
def update(self):
"""Gets the latest data and updates the states."""
"""Get the latest data and updates the states."""
self.refresh_sabnzbd_data()
if self.sabnzb_client.queue:
if self.type == 'current_status':

View file

@ -39,7 +39,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Speedtest sensor."""
data = SpeedtestData(hass, config)
dev = []
for sensor in config[CONF_MONITORED_CONDITIONS]:
@ -61,9 +60,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class SpeedtestSensor(Entity):
"""Implements a speedtest.net sensor."""
"""Implementation of a speedtest.net sensor."""
def __init__(self, speedtest_data, sensor_type):
"""Initialize the sensor."""
self._name = SENSOR_TYPES[sensor_type][0]
self.speedtest_client = speedtest_data
self.type = sensor_type
@ -72,21 +72,21 @@ class SpeedtestSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return '{} {}'.format('Speedtest', self._name)
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
def update(self):
"""Gets the latest data and updates the states."""
"""Get the latest data and update the states."""
data = self.speedtest_client.data
if data is not None:
if self.type == 'ping':
@ -98,9 +98,10 @@ class SpeedtestSensor(Entity):
class SpeedtestData(object):
"""Gets the latest data from speedtest.net."""
"""Get the latest data from speedtest.net."""
def __init__(self, hass, config):
"""Initialize the data object."""
self.data = None
self.hass = hass
self.path = hass.config.path
@ -111,7 +112,7 @@ class SpeedtestData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self, now):
"""Gets the latest data from speedtest.net."""
"""Get the latest data from speedtest.net."""
_LOGGER.info('Executing speedtest')
re_output = _SPEEDTEST_REGEX.split(
check_output([sys.executable, self.path(

View file

@ -24,8 +24,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class SteamSensor(Entity):
"""A class for the Steam account."""
# pylint: disable=abstract-method
def __init__(self, account, steamod):
"""Initialize the sensor."""
self._steamod = steamod
self._account = account
self.update()
@ -64,7 +66,7 @@ class SteamSensor(Entity):
@property
def device_state_attributes(self):
"""Returns the state attributes."""
"""Return the state attributes."""
return {'Game': self._game}
@property

View file

@ -1,5 +1,5 @@
"""
Support for transport.opendata.ch
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/
@ -29,7 +29,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the Swiss public transport sensor."""
# journal contains [0] Station ID start, [1] Station ID destination
# [2] Station name start, and [3] Station name destination
journey = [config.get('from'), config.get('to')]
@ -53,9 +52,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class SwissPublicTransportSensor(Entity):
"""Implements an Swiss public transport sensor."""
"""Implementation of an Swiss public transport sensor."""
def __init__(self, data, journey):
"""Initialize the sensor."""
self.data = data
self._name = 'Next Departure'
self._from = journey[2]
@ -64,17 +64,17 @@ class SwissPublicTransportSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def device_state_attributes(self):
"""Returns the state attributes."""
"""Return the state attributes."""
if self._times is not None:
return {
ATTR_DEPARTURE_TIME1: self._times[0],
@ -92,7 +92,7 @@ class SwissPublicTransportSensor(Entity):
# pylint: disable=too-many-branches
def update(self):
"""Gets the latest data from opendata.ch and updates the states."""
"""Get the latest data from opendata.ch and update the states."""
self.data.update()
self._times = self.data.times
try:
@ -103,16 +103,17 @@ class SwissPublicTransportSensor(Entity):
# pylint: disable=too-few-public-methods
class PublicTransportData(object):
"""Class for handling the data retrieval."""
"""The Class for handling the data retrieval."""
def __init__(self, journey):
"""Initialize the data object."""
self.start = journey[0]
self.destination = journey[1]
self.times = {}
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from opendata.ch."""
"""Get the latest data from opendata.ch."""
response = requests.get(
_RESOURCE +
'connections?' +

View file

@ -38,7 +38,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the sensors."""
"""Setup the sensors."""
dev = []
for resource in config['resources']:
if 'arg' not in resource:
@ -52,8 +52,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class SystemMonitorSensor(Entity):
"""A system monitor sensor."""
"""Implementation of a system monitor sensor."""
def __init__(self, sensor_type, argument=''):
"""Initialize the sensor."""
self._name = SENSOR_TYPES[sensor_type][0] + ' ' + argument
self.argument = argument
self.type = sensor_type
@ -63,7 +65,7 @@ class SystemMonitorSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name.rstrip()
@property
@ -73,12 +75,12 @@ class SystemMonitorSensor(Entity):
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
# pylint: disable=too-many-branches

View file

@ -1,5 +1,5 @@
"""
Provides a sensor which gets its values from a TCP socket.
Support for TCP socket based sensors.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.tcp/
@ -30,14 +30,15 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Create the TCP Sensor."""
"""Setup the TCP Sensor."""
if not Sensor.validate_config(config):
return False
add_entities((Sensor(hass, config),))
class Sensor(Entity):
"""Sensor entity which gets its value from a TCP socket."""
"""Implementation of a TCP socket based sensor."""
required = tuple()
def __init__(self, hass, config):
@ -71,7 +72,7 @@ class Sensor(Entity):
@property
def name(self):
"""The name of this sensor."""
"""Return the name of this sensor."""
name = self._config[CONF_NAME]
if name is not None:
return name
@ -84,7 +85,7 @@ class Sensor(Entity):
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity."""
"""Return the unit of measurement of this entity."""
return self._config[CONF_UNIT]
def update(self):

View file

@ -39,16 +39,17 @@ SENSOR_TYPES = {
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up Tellstick sensors."""
"""Setup Tellstick sensors."""
if discovery_info is None:
return
add_devices(TelldusLiveSensor(sensor) for sensor in discovery_info)
class TelldusLiveSensor(Entity):
""" Represents a Telldus Live sensor."""
"""Representation of a Telldus Live sensor."""
def __init__(self, sensor_id):
"""Initialize the sensor."""
self._id = sensor_id
self.update()
_LOGGER.debug("created sensor %s", self)
@ -60,57 +61,57 @@ class TelldusLiveSensor(Entity):
@property
def _sensor_name(self):
"""Return the name of the sensor."""
return self._sensor["name"]
@property
def _sensor_value(self):
"""Return the value the sensor."""
return self._sensor["data"]["value"]
@property
def _sensor_type(self):
"""Return the type of the sensor."""
return self._sensor["data"]["name"]
@property
def _battery_level(self):
"""Return the battery level of a sensor."""
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):
"""Return the last update."""
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 the value as temperature."""
return round(float(self._sensor_value), 1)
@property
def _value_as_humidity(self):
"""Return the value as humidity."""
return int(round(float(self._sensor_value)))
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return "{} {}".format(self._sensor_name or DEVICE_DEFAULT_NAME,
self.quantity_name)
@property
def available(self):
"""Return true if the sensor is available."""
return not self._sensor.get("offline", False)
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
if self._sensor_type == SENSOR_TYPE_TEMP:
return self._value_as_temperature
elif self._sensor_type == SENSOR_TYPE_HUMIDITY:
@ -118,7 +119,7 @@ class TelldusLiveSensor(Entity):
@property
def device_state_attributes(self):
"""Returns the state attributes."""
"""Return the state attributes."""
attrs = {}
if self._battery_level is not None:
attrs[ATTR_BATTERY_LEVEL] = self._battery_level
@ -133,10 +134,10 @@ class TelldusLiveSensor(Entity):
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return SENSOR_TYPES[self._sensor_type][1]
@property
def icon(self):
"""Return the icon."""
return SENSOR_TYPES[self._sensor_type][2]

View file

@ -18,7 +18,7 @@ REQUIREMENTS = ['tellcore-py==1.1.2']
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up Tellstick sensors."""
"""Setup Tellstick sensors."""
import tellcore.telldus as telldus
import tellcore.constants as tellcore_constants
@ -77,9 +77,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class TellstickSensor(Entity):
"""Represents a Tellstick sensor."""
"""Representation of a Tellstick sensor."""
def __init__(self, name, sensor, datatype, sensor_info):
"""Initialize the sensor."""
self.datatype = datatype
self.sensor = sensor
self._unit_of_measurement = sensor_info.unit or None
@ -88,15 +89,15 @@ class TellstickSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return 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 the unit of measurement of this entity, if any."""
return self._unit_of_measurement

View file

@ -18,7 +18,7 @@ REQUIREMENTS = ['https://github.com/rkabadi/temper-python/archive/'
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Find and return Temper sensors."""
"""Setup the Temper sensors."""
from temperusb.temper import TemperHandler
temp_unit = hass.config.temperature_unit
@ -29,9 +29,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class TemperSensor(Entity):
"""Represents an Temper temperature sensor."""
"""Representation of a Temper temperature sensor."""
def __init__(self, temper_device, temp_unit, name):
"""Initialize the sensor."""
self.temper_device = temper_device
self.temp_unit = temp_unit
self.current_value = None
@ -39,17 +40,17 @@ class TemperSensor(Entity):
@property
def name(self):
"""Returns the name of the temperature sensor."""
"""Return the name of the temperature sensor."""
return self._name
@property
def state(self):
"""Returns the state of the entity."""
"""Return the state of the entity."""
return self.current_value
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self.temp_unit
def update(self):

View file

@ -1,6 +1,5 @@
"""
Allows the creation of a sensor that breaks out state_attributes
from other entities.
Allows the creation of a sensor that breaks out state_attributes.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.template/
@ -25,15 +24,13 @@ STATE_ERROR = 'error'
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the sensors."""
"""Setup the template sensors."""
sensors = []
if config.get(CONF_SENSORS) is None:
_LOGGER.error("Missing configuration data for sensor platform")
return False
for device, device_config in config[CONF_SENSORS].items():
if device != slugify(device):
_LOGGER.error("Found invalid key for sensor.template: %s. "
"Use %s instead", device, slugify(device))
@ -67,19 +64,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class SensorTemplate(Entity):
"""Represents a Template Sensor."""
"""Representation of a Template Sensor."""
# pylint: disable=too-many-arguments
def __init__(self,
hass,
device_id,
friendly_name,
unit_of_measurement,
def __init__(self, hass, device_id, friendly_name, unit_of_measurement,
state_template):
self.entity_id = generate_entity_id(
ENTITY_ID_FORMAT, device_id,
hass=hass)
"""Initialize the sensor."""
self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, device_id,
hass=hass)
self.hass = hass
self._name = friendly_name
@ -89,24 +81,24 @@ class SensorTemplate(Entity):
self.hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener)
def _event_listener(self, event):
""" Called when the target device changes state. """
"""Called when the target device changes state."""
if not hasattr(self, 'hass'):
return
self.update_ha_state(True)
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Returns the unit_of_measurement of the device."""
"""Return the unit_of_measurement of the device."""
return self._unit_of_measurement
@property
@ -115,7 +107,7 @@ class SensorTemplate(Entity):
return False
def update(self):
"""Gets the latest data and updates the states."""
"""Get the latest data and update the states."""
try:
self._state = template.render(self.hass, self._template)
except TemplateError as ex:

View file

@ -21,8 +21,7 @@ OPTION_TYPES = {
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the Time and Date sensor."""
"""Setup the Time and Date sensor."""
if hass.config.time_zone is None:
_LOGGER.error("Timezone is not set in Home Assistant config")
return False
@ -39,9 +38,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods
class TimeDateSensor(Entity):
"""Implements a Time and Date sensor."""
"""Implementation of a Time and Date sensor."""
def __init__(self, option_type):
"""Initialize the sensor."""
self._name = OPTION_TYPES[option_type]
self.type = option_type
self._state = None
@ -49,12 +49,12 @@ class TimeDateSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
@ -68,7 +68,7 @@ class TimeDateSensor(Entity):
return "mdi:clock"
def update(self):
"""Gets the latest data and updates the states."""
"""Get 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

@ -38,7 +38,7 @@ def convert_pid(value):
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Torque platform."""
"""Setup Torque platform."""
vehicle = config.get('name', DEFAULT_NAME)
email = config.get('email', None)
sensors = {}
@ -81,31 +81,32 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class TorqueSensor(Entity):
"""Represents a Torque sensor."""
"""Representation of a Torque sensor."""
def __init__(self, name, unit):
"""Initialize the sensor."""
self._name = name
self._unit = unit
self._state = None
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Returns the unit of measurement."""
"""Return the unit of measurement."""
return self._unit
@property
def state(self):
"""State of the sensor."""
"""return the state of the sensor."""
return self._state
@property
def icon(self):
"""Sensor default icon."""
"""Return the default icon of the sensor."""
return 'mdi:car'
def on_update(self, value):

View file

@ -25,7 +25,7 @@ _THROTTLED_REFRESH = None
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Transmission sensors."""
"""Setup the Transmission sensors."""
import transmissionrpc
from transmissionrpc.error import TransmissionError
@ -64,9 +64,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class TransmissionSensor(Entity):
"""A Transmission sensor."""
"""representation of a Transmission sensor."""
def __init__(self, sensor_type, transmission_client, client_name):
"""Initialize the sensor."""
self._name = SENSOR_TYPES[sensor_type][0]
self.transmission_client = transmission_client
self.type = sensor_type
@ -76,21 +77,21 @@ class TransmissionSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self.client_name + ' ' + self._name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
def refresh_transmission_data(self):
""" Calls the throttled Transmission refresh method. """
"""Call the throttled Transmission refresh method."""
from transmissionrpc.error import TransmissionError
if _THROTTLED_REFRESH is not None:
@ -102,7 +103,7 @@ class TransmissionSensor(Entity):
)
def update(self):
"""Gets the latest data from Transmission and updates the state."""
"""Get the latest data from Transmission and updates the state."""
self.refresh_transmission_data()
if self.type == 'current_status':
if self.transmission_client.session:

View file

@ -18,16 +18,17 @@ DOMAIN = 'twitch'
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Twitch platform."""
"""Setup the Twitch platform."""
add_devices(
[TwitchSensor(channel) for channel in config.get('channels', [])])
class TwitchSensor(Entity):
"""Represents an Twitch channel."""
"""Representation of an Twitch channel."""
# pylint: disable=abstract-method
def __init__(self, channel):
"""Initialize the sensor."""
self._channel = channel
self._state = STATE_OFFLINE
self._preview = None
@ -42,17 +43,17 @@ class TwitchSensor(Entity):
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self._channel
@property
def state(self):
"""State of the sensor."""
"""Return the state of the sensor."""
return self._state
@property
def entity_picture(self):
"""Preview of current game."""
"""Return preview of current game."""
return self._preview
# pylint: disable=no-member
@ -71,7 +72,7 @@ class TwitchSensor(Entity):
@property
def device_state_attributes(self):
"""Returns the state attributes."""
"""Return the state attributes."""
if self._state == STATE_STREAMING:
return {
ATTR_GAME: self._game,

View file

@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def get_devices(hass, config):
"""Find and return Vera Sensors."""
"""Setup the Vera Sensors."""
import pyvera as veraApi
base_url = config.get('vera_controller_url')
@ -69,14 +69,15 @@ def get_devices(hass, config):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Performs setup for Vera controller devices."""
"""Perform the setup for Vera controller devices."""
add_devices(get_devices(hass, config))
class VeraSensor(Entity):
"""Represents a Vera Sensor."""
"""Representation of a Vera Sensor."""
def __init__(self, vera_device, controller, extra_data=None):
"""Initialize the sensor."""
self.vera_device = vera_device
self.controller = controller
self.extra_data = extra_data
@ -99,17 +100,17 @@ class VeraSensor(Entity):
@property
def state(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return self.current_value
@property
def name(self):
"""Get the mame of the sensor."""
"""Return the mame of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
if self.vera_device.category == "Temperature Sensor":
return self._temperature_units
elif self.vera_device.category == "Light Sensor":
@ -119,7 +120,7 @@ class VeraSensor(Entity):
@property
def device_state_attributes(self):
"""Returns the sensor's attributes."""
"""Return the state attributes."""
attr = {}
if self.vera_device.has_battery:
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
@ -148,7 +149,7 @@ class VeraSensor(Entity):
return False
def update(self):
"""Updates the state."""
"""Update the state."""
if self.vera_device.category == "Temperature Sensor":
current_temp = self.vera_device.temperature
vera_temp_units = (

View file

@ -14,8 +14,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Verisure platform."""
"""Setup the Verisure platform."""
sensors = []
if int(hub.config.get('temperature', '1')):
@ -47,28 +46,29 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class VerisureThermometer(Entity):
"""Represents a Verisure thermometer."""
"""Representation of a Verisure thermometer."""
def __init__(self, device_id):
"""Initialize the sensor."""
self._id = device_id
@property
def name(self):
"""Returns the name of the device."""
"""Return the name of the device."""
return '{} {}'.format(
hub.climate_status[self._id].location,
"Temperature")
@property
def state(self):
"""Returns the state of the device."""
# remove ° character
"""Return the state of the device."""
# Remove ° character
return hub.climate_status[self._id].temperature[:-1]
@property
def unit_of_measurement(self):
"""Unit of measurement of this entity."""
return TEMP_CELCIUS # can verisure report in fahrenheit?
"""Return the unit of measurement of this entity."""
return TEMP_CELCIUS
def update(self):
"""Update the sensor."""
@ -76,27 +76,28 @@ class VerisureThermometer(Entity):
class VerisureHygrometer(Entity):
"""Represents a Verisure hygrometer."""
"""Representation of a Verisure hygrometer."""
def __init__(self, device_id):
"""Initialize the sensor."""
self._id = device_id
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return '{} {}'.format(
hub.climate_status[self._id].location,
"Humidity")
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
# remove % character
return hub.climate_status[self._id].humidity[:-1]
@property
def unit_of_measurement(self):
"""Unit of measurement of this sensor."""
"""Return the unit of measurement of this sensor."""
return "%"
def update(self):
@ -105,26 +106,27 @@ class VerisureHygrometer(Entity):
class VerisureMouseDetection(Entity):
""" Represents a Verisure mouse detector."""
"""Representation of a Verisure mouse detector."""
def __init__(self, device_id):
"""Initialize the sensor."""
self._id = device_id
@property
def name(self):
"""Returns the name of the sensor."""
"""Return the name of the sensor."""
return '{} {}'.format(
hub.mouse_status[self._id].location,
"Mouse")
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return hub.mouse_status[self._id].count
@property
def unit_of_measurement(self):
"""Unit of measurement of this sensor."""
"""Return the unit of measurement of this sensor."""
return "Mice"
def update(self):

View file

@ -16,7 +16,7 @@ SENSOR_TYPES = ['temperature', 'humidity']
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Wink platform."""
"""Setup the Wink platform."""
import pywink
if discovery_info is None:
@ -38,9 +38,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class WinkSensorDevice(Entity):
"""Represents a Wink sensor."""
"""Representation of a Wink sensor."""
def __init__(self, wink):
"""Initialize the sensor."""
self.wink = wink
self.capability = self.wink.capability()
if self.wink.UNIT == "°":
@ -50,7 +51,7 @@ class WinkSensorDevice(Entity):
@property
def state(self):
"""Returns the state."""
"""Return the state."""
if self.capability == "humidity":
return self.wink.humidity_percentage()
elif self.capability == "temperature":
@ -60,17 +61,17 @@ class WinkSensorDevice(Entity):
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity, if any. """
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
@property
def unique_id(self):
"""Returns the id of this wink sensor."""
"""Return the ID of this wink sensor."""
return "{}.{}".format(self.__class__, self.wink.device_id())
@property
def name(self):
"""Returns the name of the sensor if any."""
"""Return the name of the sensor if any."""
return self.wink.name()
def update(self):
@ -79,29 +80,30 @@ class WinkSensorDevice(Entity):
@property
def is_open(self):
"""True if door is open."""
"""Return true if door is open."""
return self.wink.state()
class WinkEggMinder(Entity):
"""Represents a Wink Egg Minder."""
"""Representation of a Wink Egg Minder."""
def __init__(self, wink):
"""Initialize the sensor."""
self.wink = wink
@property
def state(self):
"""Returns the state."""
"""Return the state."""
return self.wink.state()
@property
def unique_id(self):
"""Returns the id of this wink Egg Minder."""
"""Return the id of this wink Egg Minder."""
return "{}.{}".format(self.__class__, self.wink.device_id())
@property
def name(self):
"""Returns the name of the Egg Minder if any."""
"""Return the name of the Egg Minder if any."""
return self.wink.name()
def update(self):

View file

@ -15,7 +15,7 @@ ICON = 'mdi:clock'
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the Worldclock sensor."""
"""Setup the Worldclock sensor."""
try:
time_zone = dt_util.get_time_zone(config.get('time_zone'))
except AttributeError:
@ -33,9 +33,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class WorldClockSensor(Entity):
"""Implements a Worldclock sensor."""
"""Represenatation of a Worldclock sensor."""
def __init__(self, time_zone, name):
"""Initialize the sensor."""
self._name = name
self._time_zone = time_zone
self._state = None
@ -43,12 +44,12 @@ class WorldClockSensor(Entity):
@property
def name(self):
"""Returns the name of the device."""
"""Return the name of the device."""
return self._name
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
@property
@ -57,6 +58,6 @@ class WorldClockSensor(Entity):
return ICON
def update(self):
"""Gets the time and updates the states."""
"""Get the time and updates the states."""
self._state = dt_util.datetime_to_time_str(
dt_util.now(time_zone=self._time_zone))

View file

@ -38,7 +38,7 @@ SENSOR_TYPES = {
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the Yr.no sensor."""
"""Setup the Yr.no sensor."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
elevation = config.get('elevation')
@ -73,9 +73,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-instance-attributes
class YrSensor(Entity):
"""Implements an Yr.no sensor."""
"""Representation of an Yr.no sensor."""
def __init__(self, sensor_type, weather):
"""Initialize the sensor."""
self.client_name = 'yr'
self._name = SENSOR_TYPES[sensor_type][0]
self.type = sensor_type
@ -88,12 +89,12 @@ class YrSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return '{} {}'.format(self.client_name, self._name)
@property
def state(self):
"""Returns the state of the device."""
"""Return the state of the device."""
return self._state
@property
@ -106,7 +107,7 @@ class YrSensor(Entity):
@property
def device_state_attributes(self):
"""Returns state attributes. """
"""Return the state attributes."""
return {
'about': "Weather forecast from yr.no, delivered by the"
" Norwegian Meteorological Institute and the NRK"
@ -114,11 +115,11 @@ class YrSensor(Entity):
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity, if any."""
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
def update(self):
"""Gets the latest data from yr.no and updates the states."""
"""Get the latest data from yr.no and updates the states."""
now = dt_util.utcnow()
# Check if data should be updated
if self._update is not None and now <= self._update:
@ -164,9 +165,10 @@ class YrSensor(Entity):
# pylint: disable=too-few-public-methods
class YrData(object):
"""Gets the latest data and updates the states."""
"""Get the latest data and updates the states."""
def __init__(self, coordinates):
"""Initialize the data object."""
self._url = 'http://api.yr.no/weatherapi/locationforecast/1.9/?' \
'lat={lat};lon={lon};msl={msl}'.format(**coordinates)
@ -175,7 +177,7 @@ class YrData(object):
self.update()
def update(self):
"""Gets the latest data from yr.no."""
"""Get 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

View file

@ -1,9 +1,8 @@
"""
Contains functionality to use a ZigBee device as a sensor.
Support for functionality to use a ZigBee device as a sensor.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.zigbee/
"""
import logging
from binascii import hexlify
@ -18,7 +17,8 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""
"""Setup the Z-Wave platform.
Uses the 'type' config value to work out which type of ZigBee sensor we're
dealing with and instantiates the relevant classes to handle it.
"""
@ -36,8 +36,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class ZigBeeTemperatureSensor(Entity):
"""Allows usage of an XBee Pro as a temperature sensor."""
"""Representation of XBee Pro temperature sensor."""
def __init__(self, hass, config):
"""Initialize the sensor."""
self._config = config
self._temp = None
# Get initial state
@ -46,12 +48,12 @@ class ZigBeeTemperatureSensor(Entity):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._config.name
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._temp
@property
@ -60,7 +62,7 @@ class ZigBeeTemperatureSensor(Entity):
return TEMP_CELCIUS
def update(self, *args):
"""Gets the latest data."""
"""Get the latest data."""
try:
self._temp = zigbee.DEVICE.get_temperature(self._config.address)
except zigbee.ZIGBEE_TX_FAILURE:

View file

@ -30,8 +30,7 @@ DEVICE_MAPPINGS = {
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up Z-Wave sensors."""
"""Setup Z-Wave sensors."""
# Return on empty `discovery_info`. Given you configure HA with:
#
# sensor:
@ -75,9 +74,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ZWaveSensor(ZWaveDeviceEntity, Entity):
"""Represents a Z-Wave sensor."""
"""Representation of a Z-Wave sensor."""
def __init__(self, sensor_value):
"""Initialize the sensor."""
from openzwave.network import ZWaveNetwork
from pydispatch import dispatcher
@ -88,12 +88,12 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
return self._value.data
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit of measurement the value is expressed in."""
return self._value.units
def value_changed(self, value):
@ -103,10 +103,11 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
class ZWaveMultilevelSensor(ZWaveSensor):
"""Represents a multi level sensor Z-Wave sensor."""
"""Representation of a multi level sensor Z-Wave sensor."""
@property
def state(self):
"""Returns the state of the sensor."""
"""Return the state of the sensor."""
value = self._value.data
if self._value.units in ('C', 'F'):
@ -118,7 +119,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
@property
def unit_of_measurement(self):
"""Unit the value is expressed in."""
"""Return the unit the value is expressed in."""
unit = self._value.units
if unit == 'C':
@ -130,8 +131,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
class ZWaveAlarmSensor(ZWaveSensor):
"""
A Z-wave sensor that sends Alarm alerts
"""Representation of 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,
@ -141,4 +141,5 @@ class ZWaveAlarmSensor(ZWaveSensor):
COMMAND_CLASS_ALARM is what we get here.
"""
pass