Fix PEPE257 issues
This commit is contained in:
parent
49ebc6d0b0
commit
8bff97083c
49 changed files with 429 additions and 363 deletions
|
@ -20,10 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""
|
"""Setup the APCUPSd sensor."""
|
||||||
Ensure that the 'type' config value has been set and use a specific unit
|
|
||||||
of measurement if required.
|
|
||||||
"""
|
|
||||||
typ = config.get(apcupsd.CONF_TYPE)
|
typ = config.get(apcupsd.CONF_TYPE)
|
||||||
if typ is None:
|
if typ is None:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
@ -44,10 +41,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
def infer_unit(value):
|
def infer_unit(value):
|
||||||
"""
|
"""If the value ends with any of the units from ALL_UNITS.
|
||||||
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
|
Split the unit off the end of the value and return the value, unit tuple
|
||||||
the original value and None as the unit.
|
pair. Else return the original value and None as the unit.
|
||||||
"""
|
"""
|
||||||
from apcaccess.status import ALL_UNITS
|
from apcaccess.status import ALL_UNITS
|
||||||
for unit in ALL_UNITS:
|
for unit in ALL_UNITS:
|
||||||
|
@ -57,8 +54,10 @@ def infer_unit(value):
|
||||||
|
|
||||||
|
|
||||||
class Sensor(Entity):
|
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):
|
def __init__(self, config, data, unit=None):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._config = config
|
self._config = config
|
||||||
self._unit = unit
|
self._unit = unit
|
||||||
self._data = data
|
self._data = data
|
||||||
|
@ -67,17 +66,17 @@ class Sensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the UPS sensor."""
|
"""Return the name of the UPS sensor."""
|
||||||
return self._config.get("name", DEFAULT_NAME)
|
return self._config.get("name", DEFAULT_NAME)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""True if the UPS is online, else False."""
|
"""Return true if the UPS is online, else False."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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:
|
if self._unit is None:
|
||||||
return self._inferred_unit
|
return self._inferred_unit
|
||||||
return self._unit
|
return self._unit
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Support for getting information from Arduino pins. Only analog pins are
|
Support for getting information from Arduino pins.
|
||||||
supported.
|
|
||||||
|
Only analog pins are supported.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.arduino/
|
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):
|
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
|
# Verify that the Arduino board is present
|
||||||
if arduino.BOARD is None:
|
if arduino.BOARD is None:
|
||||||
_LOGGER.error('A connection has not been made to the Arduino board.')
|
_LOGGER.error('A connection has not been made to the Arduino board.')
|
||||||
|
@ -33,8 +34,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class ArduinoSensor(Entity):
|
class ArduinoSensor(Entity):
|
||||||
"""Represents an Arduino Sensor."""
|
"""Representation of an Arduino Sensor."""
|
||||||
|
|
||||||
def __init__(self, name, pin, pin_type):
|
def __init__(self, name, pin, pin_type):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._pin = pin
|
self._pin = pin
|
||||||
self._name = name or DEVICE_DEFAULT_NAME
|
self._name = name or DEVICE_DEFAULT_NAME
|
||||||
self.pin_type = pin_type
|
self.pin_type = pin_type
|
||||||
|
@ -45,7 +48,7 @@ class ArduinoSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -26,7 +26,7 @@ CONF_MONITORED_VARIABLES = 'monitored_variables'
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the aREST sensor."""
|
"""Setup the aREST sensor."""
|
||||||
resource = config.get(CONF_RESOURCE)
|
resource = config.get(CONF_RESOURCE)
|
||||||
var_conf = config.get(CONF_MONITORED_VARIABLES)
|
var_conf = config.get(CONF_MONITORED_VARIABLES)
|
||||||
pins = config.get('pins', None)
|
pins = config.get('pins', None)
|
||||||
|
@ -51,7 +51,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
arest = ArestData(resource)
|
arest = ArestData(resource)
|
||||||
|
|
||||||
def make_renderer(value_template):
|
def make_renderer(value_template):
|
||||||
"""Creates renderer based on variable_template value."""
|
"""Create a renderer based on variable_template value."""
|
||||||
if value_template is None:
|
if value_template is None:
|
||||||
return lambda value: value
|
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
|
# pylint: disable=too-many-instance-attributes, too-many-arguments
|
||||||
class ArestSensor(Entity):
|
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,
|
def __init__(self, arest, resource, location, name, variable=None,
|
||||||
pin=None, unit_of_measurement=None, renderer=None):
|
pin=None, unit_of_measurement=None, renderer=None):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.arest = arest
|
self.arest = arest
|
||||||
self._resource = resource
|
self._resource = resource
|
||||||
self._name = '{} {}'.format(location.title(), name.title()) \
|
self._name = '{} {}'.format(location.title(), name.title()) \
|
||||||
|
@ -123,17 +124,17 @@ class ArestSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
values = self.arest.data
|
values = self.arest.data
|
||||||
|
|
||||||
if 'error' in values:
|
if 'error' in values:
|
||||||
|
@ -145,22 +146,23 @@ class ArestSensor(Entity):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from aREST API."""
|
"""Get the latest data from aREST API."""
|
||||||
self.arest.update()
|
self.arest.update()
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class ArestData(object):
|
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):
|
def __init__(self, resource, pin=None):
|
||||||
|
"""Initialize the data object."""
|
||||||
self._resource = resource
|
self._resource = resource
|
||||||
self._pin = pin
|
self._pin = pin
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from aREST device."""
|
"""Get the latest data from aREST device."""
|
||||||
try:
|
try:
|
||||||
if self._pin is None:
|
if self._pin is None:
|
||||||
response = requests.get(self._resource, timeout=10)
|
response = requests.get(self._resource, timeout=10)
|
||||||
|
|
|
@ -38,12 +38,12 @@ OPTION_TYPES = {
|
||||||
}
|
}
|
||||||
ICON = 'mdi:currency-btc'
|
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)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the Bitcoin sensor."""
|
"""Setup the Bitcoin sensor."""
|
||||||
from blockchain.wallet import Wallet
|
from blockchain.wallet import Wallet
|
||||||
from blockchain import exchangerates, exceptions
|
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
|
# pylint: disable=too-few-public-methods
|
||||||
class BitcoinSensor(Entity):
|
class BitcoinSensor(Entity):
|
||||||
"""Implements a Bitcoin sensor."""
|
"""Representation of a Bitcoin sensor."""
|
||||||
|
|
||||||
def __init__(self, data, option_type, currency, wallet=''):
|
def __init__(self, data, option_type, currency, wallet=''):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.data = data
|
self.data = data
|
||||||
self._name = OPTION_TYPES[option_type][0]
|
self._name = OPTION_TYPES[option_type][0]
|
||||||
self._unit_of_measurement = OPTION_TYPES[option_type][1]
|
self._unit_of_measurement = OPTION_TYPES[option_type][1]
|
||||||
|
@ -94,27 +96,27 @@ class BitcoinSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Icon to use in the frontend, if any."""
|
"""Return the icon to use in the frontend, if any."""
|
||||||
return ICON
|
return ICON
|
||||||
|
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data and updates the states."""
|
"""Get the latest data and updates the states."""
|
||||||
self.data.update()
|
self.data.update()
|
||||||
stats = self.data.stats
|
stats = self.data.stats
|
||||||
ticker = self.data.ticker
|
ticker = self.data.ticker
|
||||||
|
@ -172,14 +174,16 @@ class BitcoinSensor(Entity):
|
||||||
|
|
||||||
|
|
||||||
class BitcoinData(object):
|
class BitcoinData(object):
|
||||||
"""Gets the latest data and updates the states."""
|
"""Get the latest data and update the states."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""Initialize the data object."""
|
||||||
self.stats = None
|
self.stats = None
|
||||||
self.ticker = None
|
self.ticker = None
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from blockchain.info."""
|
"""Get the latest data from blockchain.info."""
|
||||||
from blockchain import statistics, exchangerates
|
from blockchain import statistics, exchangerates
|
||||||
|
|
||||||
self.stats = statistics.get()
|
self.stats = statistics.get()
|
||||||
|
|
|
@ -31,7 +31,7 @@ FORMAT_NUMBERS = ["Temperature", "Pressure"]
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the available BloomSky weather sensors."""
|
"""Setup the available BloomSky weather sensors."""
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
bloomsky = get_component('bloomsky')
|
bloomsky = get_component('bloomsky')
|
||||||
sensors = config.get('monitored_conditions', SENSOR_TYPES)
|
sensors = config.get('monitored_conditions', SENSOR_TYPES)
|
||||||
|
@ -47,7 +47,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class BloomSkySensor(Entity):
|
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):
|
def __init__(self, bs, device, sensor_name):
|
||||||
"""Initialize a bloomsky sensor."""
|
"""Initialize a bloomsky sensor."""
|
||||||
|
@ -65,12 +65,12 @@ class BloomSkySensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Unique ID for this sensor."""
|
"""Return the unique ID for this sensor."""
|
||||||
return self._unique_id
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""The current state (i.e. value) of this sensor."""
|
"""The current state, eg. value, of this sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -23,8 +23,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
"""Add the Command Sensor."""
|
"""Setup the Command Sensor."""
|
||||||
|
|
||||||
if config.get('command') is None:
|
if config.get('command') is None:
|
||||||
_LOGGER.error('Missing required variable: "command"')
|
_LOGGER.error('Missing required variable: "command"')
|
||||||
return False
|
return False
|
||||||
|
@ -42,8 +41,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
class CommandSensor(Entity):
|
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):
|
def __init__(self, hass, data, name, unit_of_measurement, value_template):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self.data = data
|
self.data = data
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -54,21 +55,21 @@ class CommandSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data and updates the state."""
|
"""Get the latest data and updates the state."""
|
||||||
self.data.update()
|
self.data.update()
|
||||||
value = self.data.value
|
value = self.data.value
|
||||||
|
|
||||||
|
@ -81,15 +82,16 @@ class CommandSensor(Entity):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class CommandSensorData(object):
|
class CommandSensorData(object):
|
||||||
"""Class for handling the data retrieval."""
|
"""The class for handling the data retrieval."""
|
||||||
|
|
||||||
def __init__(self, command):
|
def __init__(self, command):
|
||||||
|
"""Initialize the data object."""
|
||||||
self.command = command
|
self.command = command
|
||||||
self.value = None
|
self.value = None
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
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)
|
_LOGGER.info('Running command: %s', self.command)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -21,13 +21,15 @@ ICON = 'mdi:pulse'
|
||||||
|
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the CPU speed sensor."""
|
"""Setup the CPU speed sensor."""
|
||||||
add_devices([CpuSpeedSensor(config.get('name', DEFAULT_NAME))])
|
add_devices([CpuSpeedSensor(config.get('name', DEFAULT_NAME))])
|
||||||
|
|
||||||
|
|
||||||
class CpuSpeedSensor(Entity):
|
class CpuSpeedSensor(Entity):
|
||||||
"""Represents a CPU sensor."""
|
"""Representation a CPU sensor."""
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = None
|
self._state = None
|
||||||
self._unit_of_measurement = 'GHz'
|
self._unit_of_measurement = 'GHz'
|
||||||
|
@ -35,22 +37,22 @@ class CpuSpeedSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""return the unit the value is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Returns the state attributes."""
|
"""Return the state attributes."""
|
||||||
if self.info is not None:
|
if self.info is not None:
|
||||||
return {
|
return {
|
||||||
ATTR_VENDOR: self.info['vendor_id'],
|
ATTR_VENDOR: self.info['vendor_id'],
|
||||||
|
@ -60,11 +62,11 @@ class CpuSpeedSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Icon to use in the frontend, if any."""
|
"""Return the icon to use in the frontend, if any."""
|
||||||
return ICON
|
return ICON
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data and updates the state."""
|
"""Get the latest data and updates the state."""
|
||||||
from cpuinfo import cpuinfo
|
from cpuinfo import cpuinfo
|
||||||
|
|
||||||
self.info = cpuinfo.get_cpu_info()
|
self.info = cpuinfo.get_cpu_info()
|
||||||
|
|
|
@ -10,7 +10,7 @@ from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the Demo sensors."""
|
"""Setup the Demo sensors."""
|
||||||
add_devices([
|
add_devices([
|
||||||
DemoSensor('Outside Temperature', 15.6, TEMP_CELCIUS, 12),
|
DemoSensor('Outside Temperature', 15.6, TEMP_CELCIUS, 12),
|
||||||
DemoSensor('Outside Humidity', 54, '%', None),
|
DemoSensor('Outside Humidity', 54, '%', None),
|
||||||
|
@ -18,8 +18,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class DemoSensor(Entity):
|
class DemoSensor(Entity):
|
||||||
"""A Demo sensor."""
|
"""Representation of a Demo sensor."""
|
||||||
|
|
||||||
def __init__(self, name, state, unit_of_measurement, battery):
|
def __init__(self, name, state, unit_of_measurement, battery):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = state
|
self._state = state
|
||||||
self._unit_of_measurement = unit_of_measurement
|
self._unit_of_measurement = unit_of_measurement
|
||||||
|
|
|
@ -37,8 +37,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class DeutscheBahnSensor(Entity):
|
class DeutscheBahnSensor(Entity):
|
||||||
"""Implement a Deutsche Bahn sensor."""
|
"""Implementation of a Deutsche Bahn sensor."""
|
||||||
|
|
||||||
def __init__(self, start, goal):
|
def __init__(self, start, goal):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = start + ' to ' + goal
|
self._name = start + ' to ' + goal
|
||||||
self.data = SchieneData(start, goal)
|
self.data = SchieneData(start, goal)
|
||||||
self.update()
|
self.update()
|
||||||
|
@ -64,7 +66,7 @@ class DeutscheBahnSensor(Entity):
|
||||||
return self.data.connections[0]
|
return self.data.connections[0]
|
||||||
|
|
||||||
def update(self):
|
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.data.update()
|
||||||
self._state = self.data.connections[0].get('departure', 'Unknown')
|
self._state = self.data.connections[0].get('departure', 'Unknown')
|
||||||
delay = self.data.connections[0].get('delay',
|
delay = self.data.connections[0].get('delay',
|
||||||
|
@ -76,8 +78,10 @@ class DeutscheBahnSensor(Entity):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class SchieneData(object):
|
class SchieneData(object):
|
||||||
"""Pulls data from the bahn.de web page."""
|
"""Pull data from the bahn.de web page."""
|
||||||
|
|
||||||
def __init__(self, start, goal):
|
def __init__(self, start, goal):
|
||||||
|
"""Initialize the sensor."""
|
||||||
import schiene
|
import schiene
|
||||||
self.start = start
|
self.start = start
|
||||||
self.goal = goal
|
self.goal = goal
|
||||||
|
|
|
@ -28,7 +28,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the DHT sensor."""
|
"""Setup the DHT sensor."""
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
import Adafruit_DHT
|
import Adafruit_DHT
|
||||||
|
|
||||||
|
@ -67,8 +67,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class DHTSensor(Entity):
|
class DHTSensor(Entity):
|
||||||
"""Implements an DHT sensor."""
|
"""Implementation of the DHT sensor."""
|
||||||
|
|
||||||
def __init__(self, dht_client, sensor_type, temp_unit, name):
|
def __init__(self, dht_client, sensor_type, temp_unit, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.client_name = name
|
self.client_name = name
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.dht_client = dht_client
|
self.dht_client = dht_client
|
||||||
|
@ -80,21 +82,21 @@ class DHTSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return '{} {}'.format(self.client_name, self._name)
|
return '{} {}'.format(self.client_name, self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
def update(self):
|
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()
|
self.dht_client.update()
|
||||||
data = self.dht_client.data
|
data = self.dht_client.data
|
||||||
|
|
||||||
|
@ -107,8 +109,10 @@ class DHTSensor(Entity):
|
||||||
|
|
||||||
|
|
||||||
class DHTClient(object):
|
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):
|
def __init__(self, adafruit_dht, sensor, pin):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.adafruit_dht = adafruit_dht
|
self.adafruit_dht = adafruit_dht
|
||||||
self.sensor = sensor
|
self.sensor = sensor
|
||||||
self.pin = pin
|
self.pin = pin
|
||||||
|
@ -116,7 +120,7 @@ class DHTClient(object):
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
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,
|
humidity, temperature = self.adafruit_dht.read_retry(self.sensor,
|
||||||
self.pin)
|
self.pin)
|
||||||
if temperature:
|
if temperature:
|
||||||
|
|
|
@ -59,8 +59,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
class DweetSensor(Entity):
|
class DweetSensor(Entity):
|
||||||
"""Implements a Dweet sensor."""
|
"""Representation of a Dweet sensor."""
|
||||||
|
|
||||||
def __init__(self, hass, dweet, name, value_template, unit_of_measurement):
|
def __init__(self, hass, dweet, name, value_template, unit_of_measurement):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.dweet = dweet
|
self.dweet = dweet
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -71,17 +73,17 @@ class DweetSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state."""
|
"""Return the state."""
|
||||||
if self.dweet.data is None:
|
if self.dweet.data is None:
|
||||||
return STATE_UNKNOWN
|
return STATE_UNKNOWN
|
||||||
else:
|
else:
|
||||||
|
@ -91,20 +93,22 @@ class DweetSensor(Entity):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from REST API."""
|
"""Get the latest data from REST API."""
|
||||||
self.dweet.update()
|
self.dweet.update()
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class DweetData(object):
|
class DweetData(object):
|
||||||
"""Class for handling the data retrieval."""
|
"""The class for handling the data retrieval."""
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._device = device
|
self._device = device
|
||||||
self.data = None
|
self.data = None
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from Dweet.io."""
|
"""Get the latest data from Dweet.io."""
|
||||||
import dweepy
|
import dweepy
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -22,7 +22,7 @@ ECOBEE_CONFIG_FILE = 'ecobee.conf'
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the Ecobee sensors."""
|
"""Setup the Ecobee sensors."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
data = ecobee.NETWORK
|
data = ecobee.NETWORK
|
||||||
|
@ -40,9 +40,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class EcobeeSensor(Entity):
|
class EcobeeSensor(Entity):
|
||||||
"""An Ecobee sensor."""
|
"""Representation of an Ecobee sensor."""
|
||||||
|
|
||||||
def __init__(self, sensor_name, sensor_type, sensor_index):
|
def __init__(self, sensor_name, sensor_type, sensor_index):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = sensor_name + ' ' + SENSOR_TYPES[sensor_type][0]
|
self._name = sensor_name + ' ' + SENSOR_TYPES[sensor_type][0]
|
||||||
self.sensor_name = sensor_name
|
self.sensor_name = sensor_name
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
|
@ -53,22 +54,22 @@ class EcobeeSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the Ecobee sensor."""
|
"""Return the name of the Ecobee sensor."""
|
||||||
return self._name.rstrip()
|
return self._name.rstrip()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Unique id of this sensor."""
|
"""Return the unique ID of this sensor."""
|
||||||
return "sensor_ecobee_{}_{}".format(self._name, self.index)
|
return "sensor_ecobee_{}_{}".format(self._name, self.index)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Monitors home energy use as measured by an efergy engage hub using its
|
Support for Efergy sensors.
|
||||||
(unofficial, undocumented) API.
|
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.efergy/
|
https://home-assistant.io/components/sensor.efergy/
|
||||||
|
@ -21,7 +20,7 @@ SENSOR_TYPES = {
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
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")
|
app_token = config.get("app_token")
|
||||||
if not app_token:
|
if not app_token:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
@ -46,10 +45,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
class EfergySensor(Entity):
|
class EfergySensor(Entity):
|
||||||
"""Implements an Efergy sensor."""
|
"""Implementation of an Efergy sensor."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self, sensor_type, app_token, utc_offset, period, currency):
|
def __init__(self, sensor_type, app_token, utc_offset, period, currency):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
self.app_token = app_token
|
self.app_token = app_token
|
||||||
|
@ -64,21 +64,21 @@ class EfergySensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the Efergy monitor data from the web service."""
|
"""Get the Efergy monitor data from the web service."""
|
||||||
try:
|
try:
|
||||||
if self.type == 'instant_readings':
|
if self.type == 'instant_readings':
|
||||||
url_string = _RESOURCE + 'getInstant?token=' + self.app_token
|
url_string = _RESOURCE + 'getInstant?token=' + self.app_token
|
||||||
|
|
|
@ -17,8 +17,7 @@ DEFAULT_NAME = "ELIQ Energy Usage"
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Eliq sensor."""
|
"""Setup the Eliq sensor."""
|
||||||
|
|
||||||
import eliqonline
|
import eliqonline
|
||||||
|
|
||||||
access_token = config.get(CONF_ACCESS_TOKEN)
|
access_token = config.get(CONF_ACCESS_TOKEN)
|
||||||
|
@ -37,9 +36,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class EliqSensor(Entity):
|
class EliqSensor(Entity):
|
||||||
"""Implements a Eliq sensor."""
|
"""Implementation of an Eliq sensor."""
|
||||||
|
|
||||||
def __init__(self, api, channel_id, name):
|
def __init__(self, api, channel_id, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._unit_of_measurement = "W"
|
self._unit_of_measurement = "W"
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
|
@ -50,26 +50,26 @@ class EliqSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Returns icon."""
|
"""Return icon."""
|
||||||
return "mdi:speedometer"
|
return "mdi:speedometer"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data."""
|
"""Get the latest data."""
|
||||||
try:
|
try:
|
||||||
response = self.api.get_data_now(channelid=self.channel_id)
|
response = self.api.get_data_now(channelid=self.channel_id)
|
||||||
self._state = int(response.power)
|
self._state = int(response.power)
|
||||||
|
|
|
@ -44,7 +44,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the Forecast.io sensor."""
|
"""Setup the Forecast.io sensor."""
|
||||||
import forecastio
|
import forecastio
|
||||||
|
|
||||||
if None in (hass.config.latitude, hass.config.longitude):
|
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
|
# pylint: disable=too-few-public-methods
|
||||||
class ForeCastSensor(Entity):
|
class ForeCastSensor(Entity):
|
||||||
"""Implements an Forecast.io sensor."""
|
"""Implementation of a Forecast.io sensor."""
|
||||||
|
|
||||||
def __init__(self, weather_data, sensor_type):
|
def __init__(self, weather_data, sensor_type):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.client_name = 'Weather'
|
self.client_name = 'Weather'
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.forecast_client = weather_data
|
self.forecast_client = weather_data
|
||||||
|
@ -109,27 +110,27 @@ class ForeCastSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return '{} {}'.format(self.client_name, self._name)
|
return '{} {}'.format(self.client_name, self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_system(self):
|
def unit_system(self):
|
||||||
"""Unit system of this entity."""
|
"""Return the unit system of this entity."""
|
||||||
return self._unit_system
|
return self._unit_system
|
||||||
|
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def update(self):
|
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
|
import forecastio
|
||||||
|
|
||||||
self.forecast_client.update()
|
self.forecast_client.update()
|
||||||
|
@ -179,6 +180,7 @@ class ForeCastData(object):
|
||||||
"""Gets the latest data from Forecast.io."""
|
"""Gets the latest data from Forecast.io."""
|
||||||
|
|
||||||
def __init__(self, api_key, latitude, longitude, units):
|
def __init__(self, api_key, latitude, longitude, units):
|
||||||
|
"""Initialize the data object."""
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
self.latitude = latitude
|
self.latitude = latitude
|
||||||
self.longitude = longitude
|
self.longitude = longitude
|
||||||
|
@ -189,7 +191,7 @@ class ForeCastData(object):
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from Forecast.io."""
|
"""Get the latest data from Forecast.io."""
|
||||||
import forecastio
|
import forecastio
|
||||||
|
|
||||||
forecast = forecastio.load_forecast(self._api_key,
|
forecast = forecastio.load_forecast(self._api_key,
|
||||||
|
|
|
@ -44,7 +44,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Glances sensor."""
|
"""Setup the Glances sensor."""
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
port = config.get('port', CONF_PORT)
|
port = config.get('port', CONF_PORT)
|
||||||
url = 'http://{}:{}{}'.format(host, port, _RESOURCE)
|
url = 'http://{}:{}{}'.format(host, port, _RESOURCE)
|
||||||
|
@ -83,9 +82,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class GlancesSensor(Entity):
|
class GlancesSensor(Entity):
|
||||||
"""Implements a Glances sensor."""
|
"""Implementation of a Glances sensor."""
|
||||||
|
|
||||||
def __init__(self, rest, name, sensor_type):
|
def __init__(self, rest, name, sensor_type):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.rest = rest
|
self.rest = rest
|
||||||
self._name = name
|
self._name = name
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
|
@ -103,13 +103,13 @@ class GlancesSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
# pylint: disable=too-many-branches, too-many-return-statements
|
# pylint: disable=too-many-branches, too-many-return-statements
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the resources."""
|
"""Return the state of the resources."""
|
||||||
value = self.rest.data
|
value = self.rest.data
|
||||||
|
|
||||||
if value is not None:
|
if value is not None:
|
||||||
|
@ -147,20 +147,22 @@ class GlancesSensor(Entity):
|
||||||
return value['processcount']['sleeping']
|
return value['processcount']['sleeping']
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from REST API."""
|
"""Get the latest data from REST API."""
|
||||||
self.rest.update()
|
self.rest.update()
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class GlancesData(object):
|
class GlancesData(object):
|
||||||
"""Class for handling the data retrieval."""
|
"""The class for handling the data retrieval."""
|
||||||
|
|
||||||
def __init__(self, resource):
|
def __init__(self, resource):
|
||||||
|
"""Initialize the data object."""
|
||||||
self._resource = resource
|
self._resource = resource
|
||||||
self.data = dict()
|
self.data = dict()
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from the Glances REST API."""
|
"""Get the latest data from the Glances REST API."""
|
||||||
try:
|
try:
|
||||||
response = requests.get(self._resource, timeout=10)
|
response = requests.get(self._resource, timeout=10)
|
||||||
self.data = response.json()
|
self.data = response.json()
|
||||||
|
|
|
@ -27,7 +27,7 @@ DEFAULT_HIDDEN_WEATHER = ['Temperature_High', 'Temperature_Low', 'Feels_Like',
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the ISY994 platform."""
|
"""Setup the ISY994 platform."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
devs = []
|
devs = []
|
||||||
|
@ -74,9 +74,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
class WeatherPseudoNode(object):
|
class WeatherPseudoNode(object):
|
||||||
"""This class allows weather variable to act as regular nodes."""
|
"""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):
|
def __init__(self, device_id, name, status, units=None):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._id = device_id
|
self._id = device_id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.status = status
|
self.status = status
|
||||||
|
@ -84,9 +85,11 @@ class WeatherPseudoNode(object):
|
||||||
|
|
||||||
|
|
||||||
class ISYSensorDevice(ISYDeviceABC):
|
class ISYSensorDevice(ISYDeviceABC):
|
||||||
"""Represents a ISY sensor."""
|
"""Representation of an ISY sensor."""
|
||||||
|
|
||||||
_domain = 'sensor'
|
_domain = 'sensor'
|
||||||
|
|
||||||
def __init__(self, node, states=None):
|
def __init__(self, node, states=None):
|
||||||
|
"""Initialize the device."""
|
||||||
super().__init__(node)
|
super().__init__(node)
|
||||||
self._states = states or []
|
self._states = states or []
|
||||||
|
|
|
@ -38,7 +38,7 @@ CONF_VERIFY_TLS = 'verify_tls'
|
||||||
|
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up mFi sensors."""
|
"""Setup mFi sensors."""
|
||||||
if not validate_config({DOMAIN: config},
|
if not validate_config({DOMAIN: config},
|
||||||
{DOMAIN: ['host',
|
{DOMAIN: ['host',
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
|
@ -71,20 +71,21 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class MfiSensor(Entity):
|
class MfiSensor(Entity):
|
||||||
"""An mFi sensor that exposes tag=value."""
|
"""Representation of a mFi sensor."""
|
||||||
|
|
||||||
def __init__(self, port, hass):
|
def __init__(self, port, hass):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._port = port
|
self._port = port
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of th sensor."""
|
"""Return the name of th sensor."""
|
||||||
return self._port.label
|
return self._port.label
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self._port.model == 'Input Digital':
|
if self._port.model == 'Input Digital':
|
||||||
return self._port.value > 0 and STATE_ON or STATE_OFF
|
return self._port.value > 0 and STATE_ON or STATE_OFF
|
||||||
else:
|
else:
|
||||||
|
@ -93,7 +94,7 @@ class MfiSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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':
|
if self._port.tag == 'temperature':
|
||||||
return TEMP_CELCIUS
|
return TEMP_CELCIUS
|
||||||
elif self._port.tag == 'active_pwr':
|
elif self._port.tag == 'active_pwr':
|
||||||
|
@ -103,5 +104,5 @@ class MfiSensor(Entity):
|
||||||
return self._port.tag
|
return self._port.tag
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data."""
|
"""Get the latest data."""
|
||||||
self._port.refresh()
|
self._port.refresh()
|
||||||
|
|
|
@ -16,7 +16,7 @@ DEPENDENCIES = ['modbus']
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Create Modbus devices."""
|
"""Setup Modbus devices."""
|
||||||
sensors = []
|
sensors = []
|
||||||
slave = config.get("slave", None)
|
slave = config.get("slave", None)
|
||||||
if modbus.TYPE == "serial" and not slave:
|
if modbus.TYPE == "serial" and not slave:
|
||||||
|
@ -51,10 +51,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class ModbusSensor(Entity):
|
class ModbusSensor(Entity):
|
||||||
# pylint: disable=too-many-arguments
|
"""Representation of a Modbus Sensor."""
|
||||||
"""Represents a Modbus Sensor."""
|
|
||||||
|
|
||||||
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self, name, slave, register, bit=None, unit=None, coil=False):
|
def __init__(self, name, slave, register, bit=None, unit=None, coil=False):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self.slave = int(slave) if slave else 1
|
self.slave = int(slave) if slave else 1
|
||||||
self.register = int(register)
|
self.register = int(register)
|
||||||
|
@ -64,24 +65,24 @@ class ModbusSensor(Entity):
|
||||||
self._coil = coil
|
self._coil = coil
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Returns the name and the state of the sensor."""
|
"""Return the name and the state of the sensor."""
|
||||||
return "%s: %s" % (self.name, self.state)
|
return "%s: %s" % (self.name, self.state)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
""" Polling needed."""
|
"""Polling needed."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Returns a unique id."""
|
"""Return a unique id."""
|
||||||
return "MODBUS-SENSOR-{}-{}-{}".format(self.slave,
|
return "MODBUS-SENSOR-{}-{}-{}".format(self.slave,
|
||||||
self.register,
|
self.register,
|
||||||
self.bit)
|
self.bit)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self.bit:
|
if self.bit:
|
||||||
return STATE_ON if self._value else STATE_OFF
|
return STATE_ON if self._value else STATE_OFF
|
||||||
else:
|
else:
|
||||||
|
@ -89,12 +90,12 @@ class ModbusSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Get the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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":
|
if self._unit == "C":
|
||||||
return TEMP_CELCIUS
|
return TEMP_CELCIUS
|
||||||
elif self._unit == "F":
|
elif self._unit == "F":
|
||||||
|
|
|
@ -21,8 +21,7 @@ DEPENDENCIES = ['mqtt']
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
"""Add MQTT Sensor."""
|
"""Setup MQTT Sensor."""
|
||||||
|
|
||||||
if config.get('state_topic') is None:
|
if config.get('state_topic') is None:
|
||||||
_LOGGER.error("Missing required variable: state_topic")
|
_LOGGER.error("Missing required variable: state_topic")
|
||||||
return False
|
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
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
class MqttSensor(Entity):
|
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,
|
def __init__(self, hass, name, state_topic, qos, unit_of_measurement,
|
||||||
value_template):
|
value_template):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -65,15 +66,15 @@ class MqttSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit this state is expressed in."""
|
"""Return the unit this state is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the entity."""
|
"""Return the state of the entity."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
|
@ -117,7 +117,7 @@ class MySensorsSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of this entity."""
|
"""Return the name of this entity."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -129,7 +129,7 @@ class MySensorsSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
set_req = self.gateway.const.SetReq
|
||||||
unit_map = {
|
unit_map = {
|
||||||
set_req.V_TEMP: (TEMP_CELCIUS
|
set_req.V_TEMP: (TEMP_CELCIUS
|
||||||
|
|
|
@ -39,7 +39,7 @@ SENSOR_TEMP_TYPES = ['temperature',
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup Nest Sensor."""
|
"""Setup the Nest Sensor."""
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
try:
|
try:
|
||||||
for structure in nest.NEST.structures:
|
for structure in nest.NEST.structures:
|
||||||
|
@ -68,16 +68,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class NestSensor(Entity):
|
class NestSensor(Entity):
|
||||||
"""Represents a Nest sensor."""
|
"""Representation of a Nest sensor."""
|
||||||
|
|
||||||
def __init__(self, structure, device, variable):
|
def __init__(self, structure, device, variable):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.structure = structure
|
self.structure = structure
|
||||||
self.device = device
|
self.device = device
|
||||||
self.variable = variable
|
self.variable = variable
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the nest, if any."""
|
"""Return the name of the nest, if any."""
|
||||||
location = self.device.where
|
location = self.device.where
|
||||||
name = self.device.name
|
name = self.device.name
|
||||||
if location is None:
|
if location is None:
|
||||||
|
@ -92,28 +93,30 @@ class NestSensor(Entity):
|
||||||
|
|
||||||
|
|
||||||
class NestBasicSensor(NestSensor):
|
class NestBasicSensor(NestSensor):
|
||||||
"""Represents a basic Nest sensor with state."""
|
"""Representation a basic Nest sensor."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return getattr(self.device, self.variable)
|
return getattr(self.device, self.variable)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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)
|
return SENSOR_UNITS.get(self.variable, None)
|
||||||
|
|
||||||
|
|
||||||
class NestTempSensor(NestSensor):
|
class NestTempSensor(NestSensor):
|
||||||
"""Represents a Nest Temperature sensor."""
|
"""Representation of a Nest Temperature sensor."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return TEMP_CELCIUS
|
return TEMP_CELCIUS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
temp = getattr(self.device, self.variable)
|
temp = getattr(self.device, self.variable)
|
||||||
if temp is None:
|
if temp is None:
|
||||||
return None
|
return None
|
||||||
|
@ -122,10 +125,11 @@ class NestTempSensor(NestSensor):
|
||||||
|
|
||||||
|
|
||||||
class NestWeatherSensor(NestSensor):
|
class NestWeatherSensor(NestSensor):
|
||||||
"""Represents a basic Nest Weather Conditions sensor."""
|
"""Representation a basic Nest Weather Conditions sensor."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self.variable == 'kph' or self.variable == 'direction':
|
if self.variable == 'kph' or self.variable == 'direction':
|
||||||
return getattr(self.structure.weather.current.wind, self.variable)
|
return getattr(self.structure.weather.current.wind, self.variable)
|
||||||
else:
|
else:
|
||||||
|
@ -133,5 +137,5 @@ class NestWeatherSensor(NestSensor):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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)
|
return SENSOR_UNITS.get(self.variable, None)
|
||||||
|
|
|
@ -42,7 +42,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the NetAtmo sensor."""
|
"""Setup the NetAtmo sensor."""
|
||||||
if not validate_config({DOMAIN: config},
|
if not validate_config({DOMAIN: config},
|
||||||
{DOMAIN: [CONF_API_KEY,
|
{DOMAIN: [CONF_API_KEY,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
|
@ -89,9 +89,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class NetAtmoSensor(Entity):
|
class NetAtmoSensor(Entity):
|
||||||
"""Implements a NetAtmo sensor."""
|
"""Implementation of a NetAtmo sensor."""
|
||||||
|
|
||||||
def __init__(self, netatmo_data, module_name, sensor_type):
|
def __init__(self, netatmo_data, module_name, sensor_type):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = "NetAtmo {} {}".format(module_name,
|
self._name = "NetAtmo {} {}".format(module_name,
|
||||||
SENSOR_TYPES[sensor_type][0])
|
SENSOR_TYPES[sensor_type][0])
|
||||||
self.netatmo_data = netatmo_data
|
self.netatmo_data = netatmo_data
|
||||||
|
@ -103,7 +104,7 @@ class NetAtmoSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -113,17 +114,17 @@ class NetAtmoSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from NetAtmo API and updates the states."""
|
"""Get the latest data from NetAtmo API and updates the states."""
|
||||||
self.netatmo_data.update()
|
self.netatmo_data.update()
|
||||||
data = self.netatmo_data.data[self.module_name]
|
data = self.netatmo_data.data[self.module_name]
|
||||||
|
|
||||||
|
@ -146,9 +147,10 @@ class NetAtmoSensor(Entity):
|
||||||
|
|
||||||
|
|
||||||
class NetAtmoData(object):
|
class NetAtmoData(object):
|
||||||
"""Gets the latest data from NetAtmo."""
|
"""Get the latest data from NetAtmo."""
|
||||||
|
|
||||||
def __init__(self, auth):
|
def __init__(self, auth):
|
||||||
|
"""Initialize the data object."""
|
||||||
self.auth = auth
|
self.auth = auth
|
||||||
self.data = None
|
self.data = None
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ ICON = 'mdi:flash'
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
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_key = config.get("api_key")
|
||||||
api_secret = config.get("api_secret")
|
api_secret = config.get("api_secret")
|
||||||
sensor_id = config.get("sensor_id")
|
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
|
# pylint: disable=too-many-instance-attributes
|
||||||
class NeurioEnergy(Entity):
|
class NeurioEnergy(Entity):
|
||||||
"""Implements an Neurio energy."""
|
"""Implementation of an Neurio energy."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self, api_key, api_secret, sensor_id):
|
def __init__(self, api_key, api_secret, sensor_id):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = "Energy Usage"
|
self._name = "Energy Usage"
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.api_secret = api_secret
|
self.api_secret = api_secret
|
||||||
|
@ -55,17 +56,17 @@ class NeurioEnergy(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of th sensor."""
|
"""Return the name of th sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -74,7 +75,7 @@ class NeurioEnergy(Entity):
|
||||||
return ICON
|
return ICON
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the Neurio monitor data from the web service."""
|
"""Get the Neurio monitor data from the web service."""
|
||||||
import neurio
|
import neurio
|
||||||
try:
|
try:
|
||||||
neurio_tp = neurio.TokenProvider(key=self.api_key,
|
neurio_tp = neurio.TokenProvider(key=self.api_key,
|
||||||
|
|
|
@ -25,8 +25,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the one wire Sensors."""
|
"""Setup the one wire Sensors."""
|
||||||
|
|
||||||
if DEVICE_FILES == []:
|
if DEVICE_FILES == []:
|
||||||
_LOGGER.error('No onewire sensor found.')
|
_LOGGER.error('No onewire sensor found.')
|
||||||
_LOGGER.error('Check if dtoverlay=w1-gpio,gpiopin=4.')
|
_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):
|
class OneWire(Entity):
|
||||||
"""An One wire Sensor."""
|
"""Implementation of an One wire Sensor."""
|
||||||
|
|
||||||
def __init__(self, name, device_file):
|
def __init__(self, name, device_file):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._device_file = device_file
|
self._device_file = device_file
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
|
@ -73,21 +73,21 @@ class OneWire(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return TEMP_CELCIUS
|
return TEMP_CELCIUS
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from the device."""
|
"""Get the latest data from the device."""
|
||||||
lines = self._read_temp_raw()
|
lines = self._read_temp_raw()
|
||||||
while lines[0].strip()[-3:] != 'YES':
|
while lines[0].strip()[-3:] != 'YES':
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
|
@ -29,7 +29,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the OpenWeatherMap sensor."""
|
"""Setup the OpenWeatherMap sensor."""
|
||||||
if None in (hass.config.latitude, hass.config.longitude):
|
if None in (hass.config.latitude, hass.config.longitude):
|
||||||
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
||||||
return False
|
return False
|
||||||
|
@ -68,9 +68,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class OpenWeatherMapSensor(Entity):
|
class OpenWeatherMapSensor(Entity):
|
||||||
"""Implements an OpenWeatherMap sensor."""
|
"""Implementation of an OpenWeatherMap sensor."""
|
||||||
|
|
||||||
def __init__(self, weather_data, sensor_type, temp_unit):
|
def __init__(self, weather_data, sensor_type, temp_unit):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.client_name = 'Weather'
|
self.client_name = 'Weather'
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.owa_client = weather_data
|
self.owa_client = weather_data
|
||||||
|
@ -82,22 +83,22 @@ class OpenWeatherMapSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return '{} {}'.format(self.client_name, self._name)
|
return '{} {}'.format(self.client_name, self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from OWM and updates the states."""
|
"""Get the latest data from OWM and updates the states."""
|
||||||
self.owa_client.update()
|
self.owa_client.update()
|
||||||
data = self.owa_client.data
|
data = self.owa_client.data
|
||||||
fc_data = self.owa_client.fc_data
|
fc_data = self.owa_client.fc_data
|
||||||
|
@ -140,9 +141,10 @@ class OpenWeatherMapSensor(Entity):
|
||||||
|
|
||||||
|
|
||||||
class WeatherData(object):
|
class WeatherData(object):
|
||||||
"""Gets the latest data from OpenWeatherMap."""
|
"""Get the latest data from OpenWeatherMap."""
|
||||||
|
|
||||||
def __init__(self, owm, forecast, latitude, longitude):
|
def __init__(self, owm, forecast, latitude, longitude):
|
||||||
|
"""Initialize the data object."""
|
||||||
self.owm = owm
|
self.owm = owm
|
||||||
self.forecast = forecast
|
self.forecast = forecast
|
||||||
self.latitude = latitude
|
self.latitude = latitude
|
||||||
|
@ -152,7 +154,7 @@ class WeatherData(object):
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
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)
|
obs = self.owm.weather_at_coords(self.latitude, self.longitude)
|
||||||
if obs is None:
|
if obs is None:
|
||||||
_LOGGER.warning('Failed to fetch data from OWM')
|
_LOGGER.warning('Failed to fetch data from OWM')
|
||||||
|
|
|
@ -25,7 +25,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||||
|
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the REST sensor."""
|
"""Setup the REST sensor."""
|
||||||
resource = config.get('resource', None)
|
resource = config.get('resource', None)
|
||||||
method = config.get('method', DEFAULT_METHOD)
|
method = config.get('method', DEFAULT_METHOD)
|
||||||
payload = config.get('payload', None)
|
payload = config.get('payload', None)
|
||||||
|
@ -45,9 +45,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
class RestSensor(Entity):
|
class RestSensor(Entity):
|
||||||
"""Implements a REST sensor."""
|
"""Implementation of a REST sensor."""
|
||||||
|
|
||||||
def __init__(self, hass, rest, name, unit_of_measurement, value_template):
|
def __init__(self, hass, rest, name, unit_of_measurement, value_template):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self.rest = rest
|
self.rest = rest
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -58,21 +59,21 @@ class RestSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
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()
|
self.rest.update()
|
||||||
value = self.rest.data
|
value = self.rest.data
|
||||||
|
|
||||||
|
@ -90,13 +91,14 @@ class RestData(object):
|
||||||
"""Class for handling the data retrieval."""
|
"""Class for handling the data retrieval."""
|
||||||
|
|
||||||
def __init__(self, method, resource, data, verify_ssl):
|
def __init__(self, method, resource, data, verify_ssl):
|
||||||
|
"""Initialize the data object."""
|
||||||
self._request = requests.Request(method, resource, data=data).prepare()
|
self._request = requests.Request(method, resource, data=data).prepare()
|
||||||
self._verify_ssl = verify_ssl
|
self._verify_ssl = verify_ssl
|
||||||
self.data = None
|
self.data = None
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from REST service with GET method."""
|
"""Get the latest data from REST service with GET method."""
|
||||||
try:
|
try:
|
||||||
with requests.Session() as sess:
|
with requests.Session() as sess:
|
||||||
response = sess.send(self._request, timeout=10,
|
response = sess.send(self._request, timeout=10,
|
||||||
|
|
|
@ -73,9 +73,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class RfxtrxSensor(Entity):
|
class RfxtrxSensor(Entity):
|
||||||
"""Represents a RFXtrx sensor."""
|
"""Representation of a RFXtrx sensor."""
|
||||||
|
|
||||||
def __init__(self, event, name, data_type=None):
|
def __init__(self, event, name, data_type=None):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.event = event
|
self.event = event
|
||||||
self._unit_of_measurement = None
|
self._unit_of_measurement = None
|
||||||
self._data_type = None
|
self._data_type = None
|
||||||
|
@ -91,12 +92,12 @@ class RfxtrxSensor(Entity):
|
||||||
break
|
break
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Returns the name."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self._data_type:
|
if self._data_type:
|
||||||
return self.event.values[self._data_type]
|
return self.event.values[self._data_type]
|
||||||
return None
|
return None
|
||||||
|
@ -108,10 +109,10 @@ class RfxtrxSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Returns the state attributes."""
|
"""Return the state attributes."""
|
||||||
return self.event.values
|
return self.event.values
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit this state is expressed in."""
|
"""Return the unit this state is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
|
@ -29,7 +29,7 @@ _THROTTLED_REFRESH = None
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the SABnzbd sensors."""
|
"""Setup the SABnzbd sensors."""
|
||||||
from pysabnzbd import SabnzbdApi, SabnzbdApiException
|
from pysabnzbd import SabnzbdApi, SabnzbdApiException
|
||||||
|
|
||||||
api_key = config.get("api_key")
|
api_key = config.get("api_key")
|
||||||
|
@ -65,9 +65,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class SabnzbdSensor(Entity):
|
class SabnzbdSensor(Entity):
|
||||||
"""Represents an SABnzbd sensor."""
|
"""Representation of an SABnzbd sensor."""
|
||||||
|
|
||||||
def __init__(self, sensor_type, sabnzb_client, client_name):
|
def __init__(self, sensor_type, sabnzb_client, client_name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.sabnzb_client = sabnzb_client
|
self.sabnzb_client = sabnzb_client
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
|
@ -77,21 +78,21 @@ class SabnzbdSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self.client_name + ' ' + self._name
|
return self.client_name + ' ' + self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
def refresh_sabnzbd_data(self):
|
def refresh_sabnzbd_data(self):
|
||||||
"""Calls the throttled SABnzbd refresh method."""
|
"""Call the throttled SABnzbd refresh method."""
|
||||||
if _THROTTLED_REFRESH is not None:
|
if _THROTTLED_REFRESH is not None:
|
||||||
from pysabnzbd import SabnzbdApiException
|
from pysabnzbd import SabnzbdApiException
|
||||||
try:
|
try:
|
||||||
|
@ -102,7 +103,7 @@ class SabnzbdSensor(Entity):
|
||||||
)
|
)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data and updates the states."""
|
"""Get the latest data and updates the states."""
|
||||||
self.refresh_sabnzbd_data()
|
self.refresh_sabnzbd_data()
|
||||||
if self.sabnzb_client.queue:
|
if self.sabnzb_client.queue:
|
||||||
if self.type == 'current_status':
|
if self.type == 'current_status':
|
||||||
|
|
|
@ -39,7 +39,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Speedtest sensor."""
|
"""Setup the Speedtest sensor."""
|
||||||
|
|
||||||
data = SpeedtestData(hass, config)
|
data = SpeedtestData(hass, config)
|
||||||
dev = []
|
dev = []
|
||||||
for sensor in config[CONF_MONITORED_CONDITIONS]:
|
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
|
# pylint: disable=too-few-public-methods
|
||||||
class SpeedtestSensor(Entity):
|
class SpeedtestSensor(Entity):
|
||||||
"""Implements a speedtest.net sensor."""
|
"""Implementation of a speedtest.net sensor."""
|
||||||
|
|
||||||
def __init__(self, speedtest_data, sensor_type):
|
def __init__(self, speedtest_data, sensor_type):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.speedtest_client = speedtest_data
|
self.speedtest_client = speedtest_data
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
|
@ -72,21 +72,21 @@ class SpeedtestSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return '{} {}'.format('Speedtest', self._name)
|
return '{} {}'.format('Speedtest', self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data and updates the states."""
|
"""Get the latest data and update the states."""
|
||||||
data = self.speedtest_client.data
|
data = self.speedtest_client.data
|
||||||
if data is not None:
|
if data is not None:
|
||||||
if self.type == 'ping':
|
if self.type == 'ping':
|
||||||
|
@ -98,9 +98,10 @@ class SpeedtestSensor(Entity):
|
||||||
|
|
||||||
|
|
||||||
class SpeedtestData(object):
|
class SpeedtestData(object):
|
||||||
"""Gets the latest data from speedtest.net."""
|
"""Get the latest data from speedtest.net."""
|
||||||
|
|
||||||
def __init__(self, hass, config):
|
def __init__(self, hass, config):
|
||||||
|
"""Initialize the data object."""
|
||||||
self.data = None
|
self.data = None
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.path = hass.config.path
|
self.path = hass.config.path
|
||||||
|
@ -111,7 +112,7 @@ class SpeedtestData(object):
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self, now):
|
def update(self, now):
|
||||||
"""Gets the latest data from speedtest.net."""
|
"""Get the latest data from speedtest.net."""
|
||||||
_LOGGER.info('Executing speedtest')
|
_LOGGER.info('Executing speedtest')
|
||||||
re_output = _SPEEDTEST_REGEX.split(
|
re_output = _SPEEDTEST_REGEX.split(
|
||||||
check_output([sys.executable, self.path(
|
check_output([sys.executable, self.path(
|
||||||
|
|
|
@ -24,8 +24,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
class SteamSensor(Entity):
|
class SteamSensor(Entity):
|
||||||
"""A class for the Steam account."""
|
"""A class for the Steam account."""
|
||||||
|
|
||||||
# pylint: disable=abstract-method
|
# pylint: disable=abstract-method
|
||||||
def __init__(self, account, steamod):
|
def __init__(self, account, steamod):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._steamod = steamod
|
self._steamod = steamod
|
||||||
self._account = account
|
self._account = account
|
||||||
self.update()
|
self.update()
|
||||||
|
@ -64,7 +66,7 @@ class SteamSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Returns the state attributes."""
|
"""Return the state attributes."""
|
||||||
return {'Game': self._game}
|
return {'Game': self._game}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -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
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.swiss_public_transport/
|
https://home-assistant.io/components/sensor.swiss_public_transport/
|
||||||
|
@ -29,7 +29,6 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the Swiss public transport sensor."""
|
"""Get the Swiss public transport sensor."""
|
||||||
|
|
||||||
# journal contains [0] Station ID start, [1] Station ID destination
|
# journal contains [0] Station ID start, [1] Station ID destination
|
||||||
# [2] Station name start, and [3] Station name destination
|
# [2] Station name start, and [3] Station name destination
|
||||||
journey = [config.get('from'), config.get('to')]
|
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
|
# pylint: disable=too-few-public-methods
|
||||||
class SwissPublicTransportSensor(Entity):
|
class SwissPublicTransportSensor(Entity):
|
||||||
"""Implements an Swiss public transport sensor."""
|
"""Implementation of an Swiss public transport sensor."""
|
||||||
|
|
||||||
def __init__(self, data, journey):
|
def __init__(self, data, journey):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.data = data
|
self.data = data
|
||||||
self._name = 'Next Departure'
|
self._name = 'Next Departure'
|
||||||
self._from = journey[2]
|
self._from = journey[2]
|
||||||
|
@ -64,17 +64,17 @@ class SwissPublicTransportSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Returns the state attributes."""
|
"""Return the state attributes."""
|
||||||
if self._times is not None:
|
if self._times is not None:
|
||||||
return {
|
return {
|
||||||
ATTR_DEPARTURE_TIME1: self._times[0],
|
ATTR_DEPARTURE_TIME1: self._times[0],
|
||||||
|
@ -92,7 +92,7 @@ class SwissPublicTransportSensor(Entity):
|
||||||
|
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def update(self):
|
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.data.update()
|
||||||
self._times = self.data.times
|
self._times = self.data.times
|
||||||
try:
|
try:
|
||||||
|
@ -103,16 +103,17 @@ class SwissPublicTransportSensor(Entity):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class PublicTransportData(object):
|
class PublicTransportData(object):
|
||||||
"""Class for handling the data retrieval."""
|
"""The Class for handling the data retrieval."""
|
||||||
|
|
||||||
def __init__(self, journey):
|
def __init__(self, journey):
|
||||||
|
"""Initialize the data object."""
|
||||||
self.start = journey[0]
|
self.start = journey[0]
|
||||||
self.destination = journey[1]
|
self.destination = journey[1]
|
||||||
self.times = {}
|
self.times = {}
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from opendata.ch."""
|
"""Get the latest data from opendata.ch."""
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
_RESOURCE +
|
_RESOURCE +
|
||||||
'connections?' +
|
'connections?' +
|
||||||
|
|
|
@ -38,7 +38,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the sensors."""
|
"""Setup the sensors."""
|
||||||
dev = []
|
dev = []
|
||||||
for resource in config['resources']:
|
for resource in config['resources']:
|
||||||
if 'arg' not in resource:
|
if 'arg' not in resource:
|
||||||
|
@ -52,8 +52,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class SystemMonitorSensor(Entity):
|
class SystemMonitorSensor(Entity):
|
||||||
"""A system monitor sensor."""
|
"""Implementation of a system monitor sensor."""
|
||||||
|
|
||||||
def __init__(self, sensor_type, argument=''):
|
def __init__(self, sensor_type, argument=''):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = SENSOR_TYPES[sensor_type][0] + ' ' + argument
|
self._name = SENSOR_TYPES[sensor_type][0] + ' ' + argument
|
||||||
self.argument = argument
|
self.argument = argument
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
|
@ -63,7 +65,7 @@ class SystemMonitorSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name.rstrip()
|
return self._name.rstrip()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -73,12 +75,12 @@ class SystemMonitorSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
|
|
|
@ -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
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.tcp/
|
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):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Create the TCP Sensor."""
|
"""Setup the TCP Sensor."""
|
||||||
if not Sensor.validate_config(config):
|
if not Sensor.validate_config(config):
|
||||||
return False
|
return False
|
||||||
add_entities((Sensor(hass, config),))
|
add_entities((Sensor(hass, config),))
|
||||||
|
|
||||||
|
|
||||||
class Sensor(Entity):
|
class Sensor(Entity):
|
||||||
"""Sensor entity which gets its value from a TCP socket."""
|
"""Implementation of a TCP socket based sensor."""
|
||||||
|
|
||||||
required = tuple()
|
required = tuple()
|
||||||
|
|
||||||
def __init__(self, hass, config):
|
def __init__(self, hass, config):
|
||||||
|
@ -71,7 +72,7 @@ class Sensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of this sensor."""
|
"""Return the name of this sensor."""
|
||||||
name = self._config[CONF_NAME]
|
name = self._config[CONF_NAME]
|
||||||
if name is not None:
|
if name is not None:
|
||||||
return name
|
return name
|
||||||
|
@ -84,7 +85,7 @@ class Sensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit of measurement of this entity."""
|
"""Return the unit of measurement of this entity."""
|
||||||
return self._config[CONF_UNIT]
|
return self._config[CONF_UNIT]
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
@ -39,16 +39,17 @@ SENSOR_TYPES = {
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up Tellstick sensors."""
|
"""Setup Tellstick sensors."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
add_devices(TelldusLiveSensor(sensor) for sensor in discovery_info)
|
add_devices(TelldusLiveSensor(sensor) for sensor in discovery_info)
|
||||||
|
|
||||||
|
|
||||||
class TelldusLiveSensor(Entity):
|
class TelldusLiveSensor(Entity):
|
||||||
""" Represents a Telldus Live sensor."""
|
"""Representation of a Telldus Live sensor."""
|
||||||
|
|
||||||
def __init__(self, sensor_id):
|
def __init__(self, sensor_id):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._id = sensor_id
|
self._id = sensor_id
|
||||||
self.update()
|
self.update()
|
||||||
_LOGGER.debug("created sensor %s", self)
|
_LOGGER.debug("created sensor %s", self)
|
||||||
|
@ -60,57 +61,57 @@ class TelldusLiveSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _sensor_name(self):
|
def _sensor_name(self):
|
||||||
|
"""Return the name of the sensor."""
|
||||||
return self._sensor["name"]
|
return self._sensor["name"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _sensor_value(self):
|
def _sensor_value(self):
|
||||||
|
"""Return the value the sensor."""
|
||||||
return self._sensor["data"]["value"]
|
return self._sensor["data"]["value"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _sensor_type(self):
|
def _sensor_type(self):
|
||||||
|
"""Return the type of the sensor."""
|
||||||
return self._sensor["data"]["name"]
|
return self._sensor["data"]["name"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _battery_level(self):
|
def _battery_level(self):
|
||||||
|
"""Return the battery level of a sensor."""
|
||||||
sensor_battery_level = self._sensor.get("battery")
|
sensor_battery_level = self._sensor.get("battery")
|
||||||
return round(sensor_battery_level * 100 / 255) \
|
return round(sensor_battery_level * 100 / 255) \
|
||||||
if sensor_battery_level else None
|
if sensor_battery_level else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _last_updated(self):
|
def _last_updated(self):
|
||||||
|
"""Return the last update."""
|
||||||
sensor_last_updated = self._sensor.get("lastUpdated")
|
sensor_last_updated = self._sensor.get("lastUpdated")
|
||||||
return str(datetime.fromtimestamp(sensor_last_updated)) \
|
return str(datetime.fromtimestamp(sensor_last_updated)) \
|
||||||
if sensor_last_updated else None
|
if sensor_last_updated else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _value_as_temperature(self):
|
def _value_as_temperature(self):
|
||||||
|
"""Return the value as temperature."""
|
||||||
return round(float(self._sensor_value), 1)
|
return round(float(self._sensor_value), 1)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _value_as_humidity(self):
|
def _value_as_humidity(self):
|
||||||
|
"""Return the value as humidity."""
|
||||||
return int(round(float(self._sensor_value)))
|
return int(round(float(self._sensor_value)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return "{} {}".format(self._sensor_name or DEVICE_DEFAULT_NAME,
|
return "{} {}".format(self._sensor_name or DEVICE_DEFAULT_NAME,
|
||||||
self.quantity_name)
|
self.quantity_name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
|
"""Return true if the sensor is available."""
|
||||||
return not self._sensor.get("offline", False)
|
return not self._sensor.get("offline", False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self._sensor_type == SENSOR_TYPE_TEMP:
|
if self._sensor_type == SENSOR_TYPE_TEMP:
|
||||||
return self._value_as_temperature
|
return self._value_as_temperature
|
||||||
elif self._sensor_type == SENSOR_TYPE_HUMIDITY:
|
elif self._sensor_type == SENSOR_TYPE_HUMIDITY:
|
||||||
|
@ -118,7 +119,7 @@ class TelldusLiveSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Returns the state attributes."""
|
"""Return the state attributes."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
if self._battery_level is not None:
|
if self._battery_level is not None:
|
||||||
attrs[ATTR_BATTERY_LEVEL] = self._battery_level
|
attrs[ATTR_BATTERY_LEVEL] = self._battery_level
|
||||||
|
@ -133,10 +134,10 @@ class TelldusLiveSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
|
"""Return the unit of measurement."""
|
||||||
return SENSOR_TYPES[self._sensor_type][1]
|
return SENSOR_TYPES[self._sensor_type][1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
|
"""Return the icon."""
|
||||||
return SENSOR_TYPES[self._sensor_type][2]
|
return SENSOR_TYPES[self._sensor_type][2]
|
||||||
|
|
|
@ -18,7 +18,7 @@ REQUIREMENTS = ['tellcore-py==1.1.2']
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up Tellstick sensors."""
|
"""Setup Tellstick sensors."""
|
||||||
import tellcore.telldus as telldus
|
import tellcore.telldus as telldus
|
||||||
import tellcore.constants as tellcore_constants
|
import tellcore.constants as tellcore_constants
|
||||||
|
|
||||||
|
@ -77,9 +77,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class TellstickSensor(Entity):
|
class TellstickSensor(Entity):
|
||||||
"""Represents a Tellstick sensor."""
|
"""Representation of a Tellstick sensor."""
|
||||||
|
|
||||||
def __init__(self, name, sensor, datatype, sensor_info):
|
def __init__(self, name, sensor, datatype, sensor_info):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.datatype = datatype
|
self.datatype = datatype
|
||||||
self.sensor = sensor
|
self.sensor = sensor
|
||||||
self._unit_of_measurement = sensor_info.unit or None
|
self._unit_of_measurement = sensor_info.unit or None
|
||||||
|
@ -88,15 +89,15 @@ class TellstickSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.sensor.value(self.datatype).value
|
return self.sensor.value(self.datatype).value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit of measurement of this entity, if any."""
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
|
@ -18,7 +18,7 @@ REQUIREMENTS = ['https://github.com/rkabadi/temper-python/archive/'
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
"""Find and return Temper sensors."""
|
"""Setup the Temper sensors."""
|
||||||
from temperusb.temper import TemperHandler
|
from temperusb.temper import TemperHandler
|
||||||
|
|
||||||
temp_unit = hass.config.temperature_unit
|
temp_unit = hass.config.temperature_unit
|
||||||
|
@ -29,9 +29,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class TemperSensor(Entity):
|
class TemperSensor(Entity):
|
||||||
"""Represents an Temper temperature sensor."""
|
"""Representation of a Temper temperature sensor."""
|
||||||
|
|
||||||
def __init__(self, temper_device, temp_unit, name):
|
def __init__(self, temper_device, temp_unit, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.temper_device = temper_device
|
self.temper_device = temper_device
|
||||||
self.temp_unit = temp_unit
|
self.temp_unit = temp_unit
|
||||||
self.current_value = None
|
self.current_value = None
|
||||||
|
@ -39,17 +40,17 @@ class TemperSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the temperature sensor."""
|
"""Return the name of the temperature sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the entity."""
|
"""Return the state of the entity."""
|
||||||
return self.current_value
|
return self.current_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self.temp_unit
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Allows the creation of a sensor that breaks out state_attributes
|
Allows the creation of a sensor that breaks out state_attributes.
|
||||||
from other entities.
|
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.template/
|
https://home-assistant.io/components/sensor.template/
|
||||||
|
@ -25,15 +24,13 @@ STATE_ERROR = 'error'
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the sensors."""
|
"""Setup the template sensors."""
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
if config.get(CONF_SENSORS) is None:
|
if config.get(CONF_SENSORS) is None:
|
||||||
_LOGGER.error("Missing configuration data for sensor platform")
|
_LOGGER.error("Missing configuration data for sensor platform")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for device, device_config in config[CONF_SENSORS].items():
|
for device, device_config in config[CONF_SENSORS].items():
|
||||||
|
|
||||||
if device != slugify(device):
|
if device != slugify(device):
|
||||||
_LOGGER.error("Found invalid key for sensor.template: %s. "
|
_LOGGER.error("Found invalid key for sensor.template: %s. "
|
||||||
"Use %s instead", device, slugify(device))
|
"Use %s instead", device, slugify(device))
|
||||||
|
@ -67,19 +64,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class SensorTemplate(Entity):
|
class SensorTemplate(Entity):
|
||||||
"""Represents a Template Sensor."""
|
"""Representation of a Template Sensor."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self,
|
def __init__(self, hass, device_id, friendly_name, unit_of_measurement,
|
||||||
hass,
|
|
||||||
device_id,
|
|
||||||
friendly_name,
|
|
||||||
unit_of_measurement,
|
|
||||||
state_template):
|
state_template):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.entity_id = generate_entity_id(
|
self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, device_id,
|
||||||
ENTITY_ID_FORMAT, device_id,
|
hass=hass)
|
||||||
hass=hass)
|
|
||||||
|
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._name = friendly_name
|
self._name = friendly_name
|
||||||
|
@ -89,24 +81,24 @@ class SensorTemplate(Entity):
|
||||||
self.hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener)
|
self.hass.bus.listen(EVENT_STATE_CHANGED, self._event_listener)
|
||||||
|
|
||||||
def _event_listener(self, event):
|
def _event_listener(self, event):
|
||||||
""" Called when the target device changes state. """
|
"""Called when the target device changes state."""
|
||||||
if not hasattr(self, 'hass'):
|
if not hasattr(self, 'hass'):
|
||||||
return
|
return
|
||||||
self.update_ha_state(True)
|
self.update_ha_state(True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -115,7 +107,7 @@ class SensorTemplate(Entity):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data and updates the states."""
|
"""Get the latest data and update the states."""
|
||||||
try:
|
try:
|
||||||
self._state = template.render(self.hass, self._template)
|
self._state = template.render(self.hass, self._template)
|
||||||
except TemplateError as ex:
|
except TemplateError as ex:
|
||||||
|
|
|
@ -21,8 +21,7 @@ OPTION_TYPES = {
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
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:
|
if hass.config.time_zone is None:
|
||||||
_LOGGER.error("Timezone is not set in Home Assistant config")
|
_LOGGER.error("Timezone is not set in Home Assistant config")
|
||||||
return False
|
return False
|
||||||
|
@ -39,9 +38,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class TimeDateSensor(Entity):
|
class TimeDateSensor(Entity):
|
||||||
"""Implements a Time and Date sensor."""
|
"""Implementation of a Time and Date sensor."""
|
||||||
|
|
||||||
def __init__(self, option_type):
|
def __init__(self, option_type):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = OPTION_TYPES[option_type]
|
self._name = OPTION_TYPES[option_type]
|
||||||
self.type = option_type
|
self.type = option_type
|
||||||
self._state = None
|
self._state = None
|
||||||
|
@ -49,12 +49,12 @@ class TimeDateSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -68,7 +68,7 @@ class TimeDateSensor(Entity):
|
||||||
return "mdi:clock"
|
return "mdi:clock"
|
||||||
|
|
||||||
def update(self):
|
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_date = dt_util.utcnow()
|
||||||
time = dt_util.datetime_to_time_str(dt_util.as_local(time_date))
|
time = dt_util.datetime_to_time_str(dt_util.as_local(time_date))
|
||||||
time_utc = dt_util.datetime_to_time_str(time_date)
|
time_utc = dt_util.datetime_to_time_str(time_date)
|
||||||
|
|
|
@ -38,7 +38,7 @@ def convert_pid(value):
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up Torque platform."""
|
"""Setup Torque platform."""
|
||||||
vehicle = config.get('name', DEFAULT_NAME)
|
vehicle = config.get('name', DEFAULT_NAME)
|
||||||
email = config.get('email', None)
|
email = config.get('email', None)
|
||||||
sensors = {}
|
sensors = {}
|
||||||
|
@ -81,31 +81,32 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class TorqueSensor(Entity):
|
class TorqueSensor(Entity):
|
||||||
"""Represents a Torque sensor."""
|
"""Representation of a Torque sensor."""
|
||||||
|
|
||||||
def __init__(self, name, unit):
|
def __init__(self, name, unit):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._unit = unit
|
self._unit = unit
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Returns the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return self._unit
|
return self._unit
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""State of the sensor."""
|
"""return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Sensor default icon."""
|
"""Return the default icon of the sensor."""
|
||||||
return 'mdi:car'
|
return 'mdi:car'
|
||||||
|
|
||||||
def on_update(self, value):
|
def on_update(self, value):
|
||||||
|
|
|
@ -25,7 +25,7 @@ _THROTTLED_REFRESH = None
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the Transmission sensors."""
|
"""Setup the Transmission sensors."""
|
||||||
import transmissionrpc
|
import transmissionrpc
|
||||||
from transmissionrpc.error import TransmissionError
|
from transmissionrpc.error import TransmissionError
|
||||||
|
|
||||||
|
@ -64,9 +64,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class TransmissionSensor(Entity):
|
class TransmissionSensor(Entity):
|
||||||
"""A Transmission sensor."""
|
"""representation of a Transmission sensor."""
|
||||||
|
|
||||||
def __init__(self, sensor_type, transmission_client, client_name):
|
def __init__(self, sensor_type, transmission_client, client_name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.transmission_client = transmission_client
|
self.transmission_client = transmission_client
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
|
@ -76,21 +77,21 @@ class TransmissionSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self.client_name + ' ' + self._name
|
return self.client_name + ' ' + self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
def refresh_transmission_data(self):
|
def refresh_transmission_data(self):
|
||||||
""" Calls the throttled Transmission refresh method. """
|
"""Call the throttled Transmission refresh method."""
|
||||||
from transmissionrpc.error import TransmissionError
|
from transmissionrpc.error import TransmissionError
|
||||||
|
|
||||||
if _THROTTLED_REFRESH is not None:
|
if _THROTTLED_REFRESH is not None:
|
||||||
|
@ -102,7 +103,7 @@ class TransmissionSensor(Entity):
|
||||||
)
|
)
|
||||||
|
|
||||||
def update(self):
|
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()
|
self.refresh_transmission_data()
|
||||||
if self.type == 'current_status':
|
if self.type == 'current_status':
|
||||||
if self.transmission_client.session:
|
if self.transmission_client.session:
|
||||||
|
|
|
@ -18,16 +18,17 @@ DOMAIN = 'twitch'
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the Twitch platform."""
|
"""Setup the Twitch platform."""
|
||||||
add_devices(
|
add_devices(
|
||||||
[TwitchSensor(channel) for channel in config.get('channels', [])])
|
[TwitchSensor(channel) for channel in config.get('channels', [])])
|
||||||
|
|
||||||
|
|
||||||
class TwitchSensor(Entity):
|
class TwitchSensor(Entity):
|
||||||
"""Represents an Twitch channel."""
|
"""Representation of an Twitch channel."""
|
||||||
|
|
||||||
# pylint: disable=abstract-method
|
# pylint: disable=abstract-method
|
||||||
def __init__(self, channel):
|
def __init__(self, channel):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._channel = channel
|
self._channel = channel
|
||||||
self._state = STATE_OFFLINE
|
self._state = STATE_OFFLINE
|
||||||
self._preview = None
|
self._preview = None
|
||||||
|
@ -42,17 +43,17 @@ class TwitchSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._channel
|
return self._channel
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""State of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entity_picture(self):
|
def entity_picture(self):
|
||||||
"""Preview of current game."""
|
"""Return preview of current game."""
|
||||||
return self._preview
|
return self._preview
|
||||||
|
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
|
@ -71,7 +72,7 @@ class TwitchSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Returns the state attributes."""
|
"""Return the state attributes."""
|
||||||
if self._state == STATE_STREAMING:
|
if self._state == STATE_STREAMING:
|
||||||
return {
|
return {
|
||||||
ATTR_GAME: self._game,
|
ATTR_GAME: self._game,
|
||||||
|
|
|
@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def get_devices(hass, config):
|
def get_devices(hass, config):
|
||||||
"""Find and return Vera Sensors."""
|
"""Setup the Vera Sensors."""
|
||||||
import pyvera as veraApi
|
import pyvera as veraApi
|
||||||
|
|
||||||
base_url = config.get('vera_controller_url')
|
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):
|
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))
|
add_devices(get_devices(hass, config))
|
||||||
|
|
||||||
|
|
||||||
class VeraSensor(Entity):
|
class VeraSensor(Entity):
|
||||||
"""Represents a Vera Sensor."""
|
"""Representation of a Vera Sensor."""
|
||||||
|
|
||||||
def __init__(self, vera_device, controller, extra_data=None):
|
def __init__(self, vera_device, controller, extra_data=None):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.vera_device = vera_device
|
self.vera_device = vera_device
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.extra_data = extra_data
|
self.extra_data = extra_data
|
||||||
|
@ -99,17 +100,17 @@ class VeraSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self.current_value
|
return self.current_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Get the mame of the sensor."""
|
"""Return the mame of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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":
|
if self.vera_device.category == "Temperature Sensor":
|
||||||
return self._temperature_units
|
return self._temperature_units
|
||||||
elif self.vera_device.category == "Light Sensor":
|
elif self.vera_device.category == "Light Sensor":
|
||||||
|
@ -119,7 +120,7 @@ class VeraSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Returns the sensor's attributes."""
|
"""Return the state attributes."""
|
||||||
attr = {}
|
attr = {}
|
||||||
if self.vera_device.has_battery:
|
if self.vera_device.has_battery:
|
||||||
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
|
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
|
||||||
|
@ -148,7 +149,7 @@ class VeraSensor(Entity):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Updates the state."""
|
"""Update the state."""
|
||||||
if self.vera_device.category == "Temperature Sensor":
|
if self.vera_device.category == "Temperature Sensor":
|
||||||
current_temp = self.vera_device.temperature
|
current_temp = self.vera_device.temperature
|
||||||
vera_temp_units = (
|
vera_temp_units = (
|
||||||
|
|
|
@ -14,8 +14,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the Verisure platform."""
|
"""Setup the Verisure platform."""
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
|
|
||||||
if int(hub.config.get('temperature', '1')):
|
if int(hub.config.get('temperature', '1')):
|
||||||
|
@ -47,28 +46,29 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class VerisureThermometer(Entity):
|
class VerisureThermometer(Entity):
|
||||||
"""Represents a Verisure thermometer."""
|
"""Representation of a Verisure thermometer."""
|
||||||
|
|
||||||
def __init__(self, device_id):
|
def __init__(self, device_id):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._id = device_id
|
self._id = device_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the device."""
|
"""Return the name of the device."""
|
||||||
return '{} {}'.format(
|
return '{} {}'.format(
|
||||||
hub.climate_status[self._id].location,
|
hub.climate_status[self._id].location,
|
||||||
"Temperature")
|
"Temperature")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
# remove ° character
|
# Remove ° character
|
||||||
return hub.climate_status[self._id].temperature[:-1]
|
return hub.climate_status[self._id].temperature[:-1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit of measurement of this entity."""
|
"""Return the unit of measurement of this entity."""
|
||||||
return TEMP_CELCIUS # can verisure report in fahrenheit?
|
return TEMP_CELCIUS
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
|
@ -76,27 +76,28 @@ class VerisureThermometer(Entity):
|
||||||
|
|
||||||
|
|
||||||
class VerisureHygrometer(Entity):
|
class VerisureHygrometer(Entity):
|
||||||
"""Represents a Verisure hygrometer."""
|
"""Representation of a Verisure hygrometer."""
|
||||||
|
|
||||||
def __init__(self, device_id):
|
def __init__(self, device_id):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._id = device_id
|
self._id = device_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return '{} {}'.format(
|
return '{} {}'.format(
|
||||||
hub.climate_status[self._id].location,
|
hub.climate_status[self._id].location,
|
||||||
"Humidity")
|
"Humidity")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
# remove % character
|
# remove % character
|
||||||
return hub.climate_status[self._id].humidity[:-1]
|
return hub.climate_status[self._id].humidity[:-1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit of measurement of this sensor."""
|
"""Return the unit of measurement of this sensor."""
|
||||||
return "%"
|
return "%"
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
@ -105,26 +106,27 @@ class VerisureHygrometer(Entity):
|
||||||
|
|
||||||
|
|
||||||
class VerisureMouseDetection(Entity):
|
class VerisureMouseDetection(Entity):
|
||||||
""" Represents a Verisure mouse detector."""
|
"""Representation of a Verisure mouse detector."""
|
||||||
|
|
||||||
def __init__(self, device_id):
|
def __init__(self, device_id):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._id = device_id
|
self._id = device_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return '{} {}'.format(
|
return '{} {}'.format(
|
||||||
hub.mouse_status[self._id].location,
|
hub.mouse_status[self._id].location,
|
||||||
"Mouse")
|
"Mouse")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return hub.mouse_status[self._id].count
|
return hub.mouse_status[self._id].count
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit of measurement of this sensor."""
|
"""Return the unit of measurement of this sensor."""
|
||||||
return "Mice"
|
return "Mice"
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
@ -16,7 +16,7 @@ SENSOR_TYPES = ['temperature', 'humidity']
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the Wink platform."""
|
"""Setup the Wink platform."""
|
||||||
import pywink
|
import pywink
|
||||||
|
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
|
@ -38,9 +38,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class WinkSensorDevice(Entity):
|
class WinkSensorDevice(Entity):
|
||||||
"""Represents a Wink sensor."""
|
"""Representation of a Wink sensor."""
|
||||||
|
|
||||||
def __init__(self, wink):
|
def __init__(self, wink):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.wink = wink
|
self.wink = wink
|
||||||
self.capability = self.wink.capability()
|
self.capability = self.wink.capability()
|
||||||
if self.wink.UNIT == "°":
|
if self.wink.UNIT == "°":
|
||||||
|
@ -50,7 +51,7 @@ class WinkSensorDevice(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state."""
|
"""Return the state."""
|
||||||
if self.capability == "humidity":
|
if self.capability == "humidity":
|
||||||
return self.wink.humidity_percentage()
|
return self.wink.humidity_percentage()
|
||||||
elif self.capability == "temperature":
|
elif self.capability == "temperature":
|
||||||
|
@ -60,17 +61,17 @@ class WinkSensorDevice(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
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())
|
return "{}.{}".format(self.__class__, self.wink.device_id())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the sensor if any."""
|
"""Return the name of the sensor if any."""
|
||||||
return self.wink.name()
|
return self.wink.name()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
@ -79,29 +80,30 @@ class WinkSensorDevice(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_open(self):
|
def is_open(self):
|
||||||
"""True if door is open."""
|
"""Return true if door is open."""
|
||||||
return self.wink.state()
|
return self.wink.state()
|
||||||
|
|
||||||
|
|
||||||
class WinkEggMinder(Entity):
|
class WinkEggMinder(Entity):
|
||||||
"""Represents a Wink Egg Minder."""
|
"""Representation of a Wink Egg Minder."""
|
||||||
|
|
||||||
def __init__(self, wink):
|
def __init__(self, wink):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.wink = wink
|
self.wink = wink
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state."""
|
"""Return the state."""
|
||||||
return self.wink.state()
|
return self.wink.state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
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())
|
return "{}.{}".format(self.__class__, self.wink.device_id())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
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()
|
return self.wink.name()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
@ -15,7 +15,7 @@ ICON = 'mdi:clock'
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the Worldclock sensor."""
|
"""Setup the Worldclock sensor."""
|
||||||
try:
|
try:
|
||||||
time_zone = dt_util.get_time_zone(config.get('time_zone'))
|
time_zone = dt_util.get_time_zone(config.get('time_zone'))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -33,9 +33,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class WorldClockSensor(Entity):
|
class WorldClockSensor(Entity):
|
||||||
"""Implements a Worldclock sensor."""
|
"""Represenatation of a Worldclock sensor."""
|
||||||
|
|
||||||
def __init__(self, time_zone, name):
|
def __init__(self, time_zone, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._time_zone = time_zone
|
self._time_zone = time_zone
|
||||||
self._state = None
|
self._state = None
|
||||||
|
@ -43,12 +44,12 @@ class WorldClockSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Returns the name of the device."""
|
"""Return the name of the device."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -57,6 +58,6 @@ class WorldClockSensor(Entity):
|
||||||
return ICON
|
return ICON
|
||||||
|
|
||||||
def update(self):
|
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(
|
self._state = dt_util.datetime_to_time_str(
|
||||||
dt_util.now(time_zone=self._time_zone))
|
dt_util.now(time_zone=self._time_zone))
|
||||||
|
|
|
@ -38,7 +38,7 @@ SENSOR_TYPES = {
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the Yr.no sensor."""
|
"""Setup the Yr.no sensor."""
|
||||||
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
|
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
|
||||||
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
|
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
|
||||||
elevation = config.get('elevation')
|
elevation = config.get('elevation')
|
||||||
|
@ -73,9 +73,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
class YrSensor(Entity):
|
class YrSensor(Entity):
|
||||||
"""Implements an Yr.no sensor."""
|
"""Representation of an Yr.no sensor."""
|
||||||
|
|
||||||
def __init__(self, sensor_type, weather):
|
def __init__(self, sensor_type, weather):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self.client_name = 'yr'
|
self.client_name = 'yr'
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
|
@ -88,12 +89,12 @@ class YrSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return '{} {}'.format(self.client_name, self._name)
|
return '{} {}'.format(self.client_name, self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -106,7 +107,7 @@ class YrSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Returns state attributes. """
|
"""Return the state attributes."""
|
||||||
return {
|
return {
|
||||||
'about': "Weather forecast from yr.no, delivered by the"
|
'about': "Weather forecast from yr.no, delivered by the"
|
||||||
" Norwegian Meteorological Institute and the NRK"
|
" Norwegian Meteorological Institute and the NRK"
|
||||||
|
@ -114,11 +115,11 @@ class YrSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._unit_of_measurement
|
||||||
|
|
||||||
def update(self):
|
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()
|
now = dt_util.utcnow()
|
||||||
# Check if data should be updated
|
# Check if data should be updated
|
||||||
if self._update is not None and now <= self._update:
|
if self._update is not None and now <= self._update:
|
||||||
|
@ -164,9 +165,10 @@ class YrSensor(Entity):
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class YrData(object):
|
class YrData(object):
|
||||||
"""Gets the latest data and updates the states."""
|
"""Get the latest data and updates the states."""
|
||||||
|
|
||||||
def __init__(self, coordinates):
|
def __init__(self, coordinates):
|
||||||
|
"""Initialize the data object."""
|
||||||
self._url = 'http://api.yr.no/weatherapi/locationforecast/1.9/?' \
|
self._url = 'http://api.yr.no/weatherapi/locationforecast/1.9/?' \
|
||||||
'lat={lat};lon={lon};msl={msl}'.format(**coordinates)
|
'lat={lat};lon={lon};msl={msl}'.format(**coordinates)
|
||||||
|
|
||||||
|
@ -175,7 +177,7 @@ class YrData(object):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from yr.no."""
|
"""Get the latest data from yr.no."""
|
||||||
# Check if new will be available
|
# Check if new will be available
|
||||||
if self._nextrun is not None and dt_util.utcnow() <= self._nextrun:
|
if self._nextrun is not None and dt_util.utcnow() <= self._nextrun:
|
||||||
return
|
return
|
||||||
|
|
|
@ -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
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.zigbee/
|
https://home-assistant.io/components/sensor.zigbee/
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
@ -18,7 +17,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
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
|
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.
|
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):
|
class ZigBeeTemperatureSensor(Entity):
|
||||||
"""Allows usage of an XBee Pro as a temperature sensor."""
|
"""Representation of XBee Pro temperature sensor."""
|
||||||
|
|
||||||
def __init__(self, hass, config):
|
def __init__(self, hass, config):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._config = config
|
self._config = config
|
||||||
self._temp = None
|
self._temp = None
|
||||||
# Get initial state
|
# Get initial state
|
||||||
|
@ -46,12 +48,12 @@ class ZigBeeTemperatureSensor(Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._config.name
|
return self._config.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._temp
|
return self._temp
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -60,7 +62,7 @@ class ZigBeeTemperatureSensor(Entity):
|
||||||
return TEMP_CELCIUS
|
return TEMP_CELCIUS
|
||||||
|
|
||||||
def update(self, *args):
|
def update(self, *args):
|
||||||
"""Gets the latest data."""
|
"""Get the latest data."""
|
||||||
try:
|
try:
|
||||||
self._temp = zigbee.DEVICE.get_temperature(self._config.address)
|
self._temp = zigbee.DEVICE.get_temperature(self._config.address)
|
||||||
except zigbee.ZIGBEE_TX_FAILURE:
|
except zigbee.ZIGBEE_TX_FAILURE:
|
||||||
|
|
|
@ -30,8 +30,7 @@ DEVICE_MAPPINGS = {
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
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:
|
# Return on empty `discovery_info`. Given you configure HA with:
|
||||||
#
|
#
|
||||||
# sensor:
|
# sensor:
|
||||||
|
@ -75,9 +74,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class ZWaveSensor(ZWaveDeviceEntity, Entity):
|
class ZWaveSensor(ZWaveDeviceEntity, Entity):
|
||||||
"""Represents a Z-Wave sensor."""
|
"""Representation of a Z-Wave sensor."""
|
||||||
|
|
||||||
def __init__(self, sensor_value):
|
def __init__(self, sensor_value):
|
||||||
|
"""Initialize the sensor."""
|
||||||
from openzwave.network import ZWaveNetwork
|
from openzwave.network import ZWaveNetwork
|
||||||
from pydispatch import dispatcher
|
from pydispatch import dispatcher
|
||||||
|
|
||||||
|
@ -88,12 +88,12 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._value.data
|
return self._value.data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
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
|
return self._value.units
|
||||||
|
|
||||||
def value_changed(self, value):
|
def value_changed(self, value):
|
||||||
|
@ -103,10 +103,11 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
|
||||||
|
|
||||||
|
|
||||||
class ZWaveMultilevelSensor(ZWaveSensor):
|
class ZWaveMultilevelSensor(ZWaveSensor):
|
||||||
"""Represents a multi level sensor Z-Wave sensor."""
|
"""Representation of a multi level sensor Z-Wave sensor."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
value = self._value.data
|
value = self._value.data
|
||||||
|
|
||||||
if self._value.units in ('C', 'F'):
|
if self._value.units in ('C', 'F'):
|
||||||
|
@ -118,7 +119,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
unit = self._value.units
|
unit = self._value.units
|
||||||
|
|
||||||
if unit == 'C':
|
if unit == 'C':
|
||||||
|
@ -130,8 +131,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
|
||||||
|
|
||||||
|
|
||||||
class ZWaveAlarmSensor(ZWaveSensor):
|
class ZWaveAlarmSensor(ZWaveSensor):
|
||||||
"""
|
"""Representation of 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
|
Examples include certain Multisensors that have motion and vibration
|
||||||
capabilities. Z-Wave defines various alarm types such as Smoke, Flood,
|
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.
|
COMMAND_CLASS_ALARM is what we get here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Reference in a new issue