Don't use len(SEQUENCE) as condition value (#7249)
* Don't use len(SEQUENCE) as condition value * Update volvooncall.py
This commit is contained in:
1 parent
15b2473224
commit
cfc023e128
43 files changed
+319
-355
No files matched your search
@@ -1,4 +1,3 @@
|
||||
|
||||
"""
|
||||
Support for the Broadlink RM2 Pro (only temperature) and A1 devices.
|
||||
|
||||
@@ -9,12 +8,13 @@ from datetime import timedelta
|
||||
import binascii
|
||||
import logging
|
||||
import socket
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (CONF_HOST, CONF_MAC,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME, TEMP_CELSIUS, CONF_TIMEOUT)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_MAC, CONF_MONITORED_CONDITIONS, CONF_NAME, TEMP_CELSIUS,
|
||||
CONF_TIMEOUT)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@@ -71,7 +71,7 @@ class BroadlinkSensor(Entity):
|
||||
|
||||
def __init__(self, name, broadlink_data, sensor_type):
|
||||
"""Initialize the sensor."""
|
||||
self._name = "%s %s" % (name, SENSOR_TYPES[sensor_type][0])
|
||||
self._name = '{} {}'.format(name, SENSOR_TYPES[sensor_type][0])
|
||||
self._state = None
|
||||
self._type = sensor_type
|
||||
self._broadlink_data = broadlink_data
|
||||
@@ -119,7 +119,7 @@ class BroadlinkData(object):
|
||||
})
|
||||
self.update = Throttle(interval)(self._update)
|
||||
if not self._auth():
|
||||
_LOGGER.warning("Failed to connect to device.")
|
||||
_LOGGER.warning("Failed to connect to device")
|
||||
|
||||
def _update(self, retry=3):
|
||||
try:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""Support for Dublin RTPI information from data.dublinked.ie.
|
||||
"""
|
||||
Support for Dublin RTPI information from data.dublinked.ie.
|
||||
|
||||
For more info on the API see :
|
||||
https://data.gov.ie/dataset/real-time-passenger-information-rtpi-for-dublin-bus-bus-eireann-luas-and-irish-rail/resource/4b9f2c4f-6bf5-4958-a43a-f12dab04cf61
|
||||
@@ -22,11 +23,11 @@ import homeassistant.helpers.config_validation as cv
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_RESOURCE = 'https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation'
|
||||
|
||||
ATTR_STOP_ID = "Stop ID"
|
||||
ATTR_ROUTE = "Route"
|
||||
ATTR_DUE_IN = "Due in"
|
||||
ATTR_DUE_AT = "Due at"
|
||||
ATTR_NEXT_UP = "Later Bus"
|
||||
ATTR_STOP_ID = 'Stop ID'
|
||||
ATTR_ROUTE = 'Route'
|
||||
ATTR_DUE_IN = 'Due in'
|
||||
ATTR_DUE_AT = 'Due at'
|
||||
ATTR_NEXT_UP = 'Later Bus'
|
||||
|
||||
CONF_ATTRIBUTION = "Data provided by data.dublinked.ie"
|
||||
CONF_STOP_ID = 'stopid'
|
||||
@@ -36,7 +37,7 @@ DEFAULT_NAME = 'Next Bus'
|
||||
ICON = 'mdi:bus'
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||
TIME_STR_FORMAT = "%H:%M"
|
||||
TIME_STR_FORMAT = '%H:%M'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_STOP_ID): cv.string,
|
||||
@@ -92,7 +93,7 @@ class DublinPublicTransportSensor(Entity):
|
||||
"""Return the state attributes."""
|
||||
if self._times is not None:
|
||||
next_up = "None"
|
||||
if len(self._times) > 1:
|
||||
if self._times:
|
||||
next_up = self._times[1][ATTR_ROUTE] + " in "
|
||||
next_up += self._times[1][ATTR_DUE_IN]
|
||||
|
||||
@@ -108,7 +109,7 @@ class DublinPublicTransportSensor(Entity):
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return "min"
|
||||
return 'min'
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@@ -178,7 +179,7 @@ class PublicTransportData(object):
|
||||
due_in_minutes(due_at)}
|
||||
self.info.append(bus_data)
|
||||
|
||||
if len(self.info) == 0:
|
||||
if not self.info:
|
||||
self.info = [{ATTR_DUE_AT: 'n/a',
|
||||
ATTR_ROUTE: self.route,
|
||||
ATTR_DUE_IN: 'n/a'}]
|
||||
@@ -1,13 +1,11 @@
|
||||
"""Read temperature information from Eddystone beacons.
|
||||
"""
|
||||
Read temperature information from Eddystone beacons.
|
||||
|
||||
Your beacons must be configured to transmit UID (for identification) and TLM
|
||||
(for temperature) frames.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.eddystone_temperature/
|
||||
|
||||
Original version of this code (for Skybeacons) by anpetrov.
|
||||
https://github.com/anpetrov/skybeacon
|
||||
"""
|
||||
import logging
|
||||
|
||||
@@ -24,7 +22,6 @@ REQUIREMENTS = ['beacontools[scan]==1.0.1']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# constants
|
||||
CONF_BEACONS = 'beacons'
|
||||
CONF_BT_DEVICE_ID = 'bt_device_id'
|
||||
CONF_INSTANCE = 'instance'
|
||||
@@ -45,8 +42,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Validate configuration, create devices and start monitoring thread."""
|
||||
_LOGGER.debug("Setting up...")
|
||||
|
||||
bt_device_id = config.get("bt_device_id")
|
||||
|
||||
beacons = config.get("beacons")
|
||||
@@ -63,17 +58,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
else:
|
||||
devices.append(EddystoneTemp(name, namespace, instance))
|
||||
|
||||
if len(devices) > 0:
|
||||
if devices:
|
||||
mon = Monitor(hass, devices, bt_device_id)
|
||||
|
||||
def monitor_stop(_service_or_event):
|
||||
"""Stop the monitor thread."""
|
||||
_LOGGER.info("Stopping scanner for eddystone beacons")
|
||||
_LOGGER.info("Stopping scanner for Eddystone beacons")
|
||||
mon.stop()
|
||||
|
||||
def monitor_start(_service_or_event):
|
||||
"""Start the monitor thread."""
|
||||
_LOGGER.info("Starting scanner for eddystone beacons")
|
||||
_LOGGER.info("Starting scanner for Eddystone beacons")
|
||||
mon.start()
|
||||
|
||||
add_devices(devices)
|
||||
@@ -88,9 +83,8 @@ def get_from_conf(config, config_key, length):
|
||||
"""Retrieve value from config and validate length."""
|
||||
string = config.get(config_key)
|
||||
if len(string) != length:
|
||||
_LOGGER.error("Error in config parameter \"%s\": Must be exactly %d "
|
||||
"bytes. Device will not be added.",
|
||||
config_key, length/2)
|
||||
_LOGGER.error("Error in config parameter %s: Must be exactly %d "
|
||||
"bytes. Device will not be added", config_key, length/2)
|
||||
return None
|
||||
else:
|
||||
return string
|
||||
@@ -135,9 +129,9 @@ class Monitor(object):
|
||||
"""Construct interface object."""
|
||||
self.hass = hass
|
||||
|
||||
# list of beacons to monitor
|
||||
# List of beacons to monitor
|
||||
self.devices = devices
|
||||
# number of the bt device (hciX)
|
||||
# Number of the bt device (hciX)
|
||||
self.bt_device_id = bt_device_id
|
||||
|
||||
def callback(bt_addr, _, packet, additional_info):
|
||||
@@ -147,14 +141,13 @@ class Monitor(object):
|
||||
packet.temperature)
|
||||
|
||||
# pylint: disable=import-error
|
||||
from beacontools import (BeaconScanner, EddystoneFilter,
|
||||
EddystoneTLMFrame)
|
||||
# Create a device filter for each device
|
||||
from beacontools import (
|
||||
BeaconScanner, EddystoneFilter, EddystoneTLMFrame)
|
||||
device_filters = [EddystoneFilter(d.namespace, d.instance)
|
||||
for d in devices]
|
||||
|
||||
self.scanner = BeaconScanner(callback, bt_device_id, device_filters,
|
||||
EddystoneTLMFrame)
|
||||
self.scanner = BeaconScanner(
|
||||
callback, bt_device_id, device_filters, EddystoneTLMFrame)
|
||||
self.scanning = False
|
||||
|
||||
def start(self):
|
||||
@@ -163,8 +156,8 @@ class Monitor(object):
|
||||
self.scanner.start()
|
||||
self.scanning = True
|
||||
else:
|
||||
_LOGGER.debug("Warning: start() called, but scanner is already"
|
||||
" running")
|
||||
_LOGGER.debug(
|
||||
"Warning: start() called, but scanner is already running")
|
||||
|
||||
def process_packet(self, namespace, instance, temperature):
|
||||
"""Assign temperature to hass device."""
|
||||
@@ -185,5 +178,5 @@ class Monitor(object):
|
||||
_LOGGER.debug("Stopped")
|
||||
self.scanning = False
|
||||
else:
|
||||
_LOGGER.debug("Warning: stop() called but scanner was not"
|
||||
" running.")
|
||||
_LOGGER.debug(
|
||||
"Warning: stop() called but scanner was not running")
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
EMail sensor support.
|
||||
Email sensor support.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.email/
|
||||
@@ -7,24 +7,26 @@ https://home-assistant.io/components/sensor.email/
|
||||
import logging
|
||||
import datetime
|
||||
import email
|
||||
|
||||
from collections import deque
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_NAME, CONF_PORT, CONF_USERNAME, CONF_PASSWORD, CONF_VALUE_TEMPLATE)
|
||||
CONF_NAME, CONF_PORT, CONF_USERNAME, CONF_PASSWORD, CONF_VALUE_TEMPLATE,
|
||||
CONTENT_TYPE_TEXT_PLAIN)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_SERVER = "server"
|
||||
CONF_SENDERS = "senders"
|
||||
CONF_SERVER = 'server'
|
||||
CONF_SENDERS = 'senders'
|
||||
|
||||
ATTR_FROM = "from"
|
||||
ATTR_BODY = "body"
|
||||
ATTR_DATE = "date"
|
||||
ATTR_SUBJECT = "subject"
|
||||
ATTR_FROM = 'from'
|
||||
ATTR_BODY = 'body'
|
||||
ATTR_DATE = 'date'
|
||||
ATTR_SUBJECT = 'subject'
|
||||
|
||||
DEFAULT_PORT = 993
|
||||
|
||||
@@ -41,20 +43,15 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the EMail platform."""
|
||||
reader = EmailReader(
|
||||
config.get(CONF_USERNAME),
|
||||
config.get(CONF_PASSWORD),
|
||||
config.get(CONF_SERVER),
|
||||
config.get(CONF_PORT))
|
||||
config.get(CONF_USERNAME), config.get(CONF_PASSWORD),
|
||||
config.get(CONF_SERVER), config.get(CONF_PORT))
|
||||
|
||||
value_template = config.get(CONF_VALUE_TEMPLATE)
|
||||
if value_template is not None:
|
||||
value_template.hass = hass
|
||||
sensor = EmailContentSensor(
|
||||
hass,
|
||||
reader,
|
||||
config.get(CONF_NAME, None) or config.get(CONF_USERNAME),
|
||||
config.get(CONF_SENDERS),
|
||||
value_template)
|
||||
hass, reader, config.get(CONF_NAME) or config.get(CONF_USERNAME),
|
||||
config.get(CONF_SENDERS), value_template)
|
||||
|
||||
if sensor.connected:
|
||||
add_devices([sensor])
|
||||
@@ -83,15 +80,13 @@ class EmailReader:
|
||||
self.connection.login(self._user, self._password)
|
||||
return True
|
||||
except imaplib.IMAP4.error:
|
||||
_LOGGER.error("Failed to login to %s.", self._server)
|
||||
_LOGGER.error("Failed to login to %s", self._server)
|
||||
return False
|
||||
|
||||
def _fetch_message(self, message_uid):
|
||||
"""Get an email message from a message id."""
|
||||
_, message_data = self.connection.uid(
|
||||
'fetch',
|
||||
message_uid,
|
||||
'(RFC822)')
|
||||
'fetch', message_uid, '(RFC822)')
|
||||
|
||||
raw_email = message_data[0][1]
|
||||
email_message = email.message_from_bytes(raw_email)
|
||||
@@ -103,7 +98,7 @@ class EmailReader:
|
||||
try:
|
||||
self.connection.select()
|
||||
|
||||
if len(self._unread_ids) == 0:
|
||||
if not self._unread_ids:
|
||||
search = "SINCE {0:%d-%b-%Y}".format(datetime.date.today())
|
||||
if self._last_id is not None:
|
||||
search = "UID {}:*".format(self._last_id)
|
||||
@@ -111,7 +106,7 @@ class EmailReader:
|
||||
_, data = self.connection.uid("search", None, search)
|
||||
self._unread_ids = deque(data[0].split())
|
||||
|
||||
while len(self._unread_ids) > 0:
|
||||
while self._unread_ids:
|
||||
message_uid = self._unread_ids.popleft()
|
||||
if self._last_id is None or int(message_uid) > self._last_id:
|
||||
self._last_id = int(message_uid)
|
||||
@@ -119,29 +114,23 @@ class EmailReader:
|
||||
|
||||
except imaplib.IMAP4.error:
|
||||
_LOGGER.info(
|
||||
"Connection to %s lost, attempting to reconnect",
|
||||
self._server)
|
||||
"Connection to %s lost, attempting to reconnect", self._server)
|
||||
try:
|
||||
self.connect()
|
||||
except imaplib.IMAP4.error:
|
||||
_LOGGER.error("Failed to reconnect.")
|
||||
_LOGGER.error("Failed to reconnect")
|
||||
|
||||
|
||||
class EmailContentSensor(Entity):
|
||||
"""Representation of an EMail sensor."""
|
||||
|
||||
def __init__(self,
|
||||
hass,
|
||||
email_reader,
|
||||
name,
|
||||
allowed_senders,
|
||||
def __init__(self, hass, email_reader, name, allowed_senders,
|
||||
value_template):
|
||||
"""Initialize the sensor."""
|
||||
self.hass = hass
|
||||
self._email_reader = email_reader
|
||||
self._name = name
|
||||
self._allowed_senders = \
|
||||
[sender.upper() for sender in allowed_senders]
|
||||
self._allowed_senders = [sender.upper() for sender in allowed_senders]
|
||||
self._value_template = value_template
|
||||
self._last_id = None
|
||||
self._message = None
|
||||
@@ -202,7 +191,7 @@ class EmailContentSensor(Entity):
|
||||
message_untyped_text = None
|
||||
|
||||
for part in email_message.walk():
|
||||
if part.get_content_type() == 'text/plain':
|
||||
if part.get_content_type() == CONTENT_TYPE_TEXT_PLAIN:
|
||||
if message_text is None:
|
||||
message_text = part.get_payload()
|
||||
elif part.get_content_type() == 'text/html':
|
||||
|
||||
@@ -168,15 +168,15 @@ class InfluxSensorData(object):
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
"""Get the latest data with a shell command."""
|
||||
_LOGGER.info('Running query: %s', self.query)
|
||||
_LOGGER.info("Running query: %s", self.query)
|
||||
|
||||
points = list(self.influx.query(self.query).get_points())
|
||||
if len(points) == 0:
|
||||
_LOGGER.warning('Query returned no points, sensor state set'
|
||||
' to UNKNOWN : %s', self.query)
|
||||
if not points:
|
||||
_LOGGER.warning("Query returned no points, sensor state set"
|
||||
" to UNKNOWN : %s", self.query)
|
||||
self.value = None
|
||||
else:
|
||||
if len(points) > 1:
|
||||
_LOGGER.warning('Query returned multiple points, only first'
|
||||
' one shown : %s', self.query)
|
||||
if points:
|
||||
_LOGGER.warning("Query returned multiple points, only first"
|
||||
" one shown : %s", self.query)
|
||||
self.value = points[0].get('value')
|
||||
@@ -1,15 +1,15 @@
|
||||
"""
|
||||
Support for ISY994 binary sensors.
|
||||
Support for ISY994 sensors.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/binary_sensor.isy994/
|
||||
https://home-assistant.io/components/sensor.isy994/
|
||||
"""
|
||||
import logging
|
||||
from typing import Callable # noqa
|
||||
|
||||
import homeassistant.components.isy994 as isy
|
||||
from homeassistant.const import (TEMP_CELSIUS, TEMP_FAHRENHEIT, STATE_OFF,
|
||||
STATE_ON)
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS, TEMP_FAHRENHEIT, STATE_OFF, STATE_ON)
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -238,17 +238,17 @@ BINARY_UOM = ['2', '78']
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config: ConfigType,
|
||||
add_devices: Callable[[list], None], discovery_info=None):
|
||||
"""Setup the ISY994 sensor platform."""
|
||||
"""Set up the ISY994 sensor platform."""
|
||||
if isy.ISY is None or not isy.ISY.connected:
|
||||
_LOGGER.error('A connection has not been made to the ISY controller.')
|
||||
_LOGGER.error("A connection has not been made to the ISY controller")
|
||||
return False
|
||||
|
||||
devices = []
|
||||
|
||||
for node in isy.SENSOR_NODES:
|
||||
if (len(node.uom) == 0 or node.uom[0] not in BINARY_UOM) and \
|
||||
if (not node.uom or node.uom[0] not in BINARY_UOM) and \
|
||||
STATE_OFF not in node.uom and STATE_ON not in node.uom:
|
||||
_LOGGER.debug('LOADING %s', node.name)
|
||||
_LOGGER.debug("Loading %s", node.name)
|
||||
devices.append(ISYSensorDevice(node))
|
||||
|
||||
for node in isy.WEATHER_NODES:
|
||||
|
||||
@@ -58,7 +58,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the MiFlora sensor."""
|
||||
"""Set up the MiFlora sensor."""
|
||||
from miflora import miflora_poller
|
||||
|
||||
cache = config.get(CONF_CACHE)
|
||||
@@ -77,7 +77,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
unit = SENSOR_TYPES[parameter][1]
|
||||
|
||||
prefix = config.get(CONF_NAME)
|
||||
if len(prefix) > 0:
|
||||
if prefix:
|
||||
name = "{} {}".format(prefix, name)
|
||||
|
||||
devs.append(MiFloraSensor(
|
||||
@@ -145,7 +145,7 @@ class MiFloraSensor(Entity):
|
||||
self.name)
|
||||
# Remove old data from median list or set sensor value to None
|
||||
# if no data is available anymore
|
||||
if len(self.data) > 0:
|
||||
if self.data:
|
||||
self.data = self.data[1:]
|
||||
else:
|
||||
self._state = None
|
||||
|
||||
@@ -5,6 +5,7 @@ For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.rfxtrx/
|
||||
"""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.components.rfxtrx as rfxtrx
|
||||
@@ -13,8 +14,8 @@ from homeassistant.const import CONF_PLATFORM
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import slugify
|
||||
from homeassistant.components.rfxtrx import (
|
||||
ATTR_AUTOMATIC_ADD, ATTR_NAME, ATTR_FIREEVENT,
|
||||
CONF_DEVICES, ATTR_DATA_TYPE, DATA_TYPES, ATTR_ENTITY_ID)
|
||||
ATTR_AUTOMATIC_ADD, ATTR_NAME, ATTR_FIREEVENT, CONF_DEVICES, DATA_TYPES,
|
||||
ATTR_DATA_TYPE, ATTR_ENTITY_ID)
|
||||
|
||||
DEPENDENCIES = ['rfxtrx']
|
||||
|
||||
@@ -28,7 +29,7 @@ PLATFORM_SCHEMA = vol.Schema({
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
"""Setup the RFXtrx platform."""
|
||||
"""Set up the RFXtrx platform."""
|
||||
from RFXtrx import SensorEvent
|
||||
sensors = []
|
||||
for packet_id, entity_info in config[CONF_DEVICES].items():
|
||||
@@ -40,7 +41,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
sub_sensors = {}
|
||||
data_types = entity_info[ATTR_DATA_TYPE]
|
||||
if len(data_types) == 0:
|
||||
if not data_types:
|
||||
data_types = ['']
|
||||
for data_type in DATA_TYPES:
|
||||
if data_type in event.values:
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
"""tado component to create some sensors for each zone."""
|
||||
"""
|
||||
Tado component to create some sensors for each zone.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.tado/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.components.tado import (
|
||||
DATA_TADO)
|
||||
from homeassistant.components.tado import (DATA_TADO)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_DATA_ID = 'data_id'
|
||||
ATTR_DEVICE = 'device'
|
||||
ATTR_ID = 'id'
|
||||
ATTR_NAME = 'name'
|
||||
ATTR_ZONE = 'zone'
|
||||
|
||||
SENSOR_TYPES = ['temperature', 'humidity', 'power',
|
||||
'link', 'heating', 'tado mode', 'overlay']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the sensor platform."""
|
||||
# get the PyTado object from the hub component
|
||||
"""Set up the sensor platform."""
|
||||
tado = hass.data[DATA_TADO]
|
||||
|
||||
try:
|
||||
@@ -36,7 +45,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
tado, me_data, me_data['homes'][0]['name'],
|
||||
me_data['homes'][0]['id'], "tado bridge status"))
|
||||
|
||||
if len(sensor_items) > 0:
|
||||
if sensor_items:
|
||||
add_devices(sensor_items, True)
|
||||
return True
|
||||
else:
|
||||
@@ -48,10 +57,10 @@ def create_zone_sensor(tado, zone, name, zone_id, variable):
|
||||
data_id = 'zone {} {}'.format(name, zone_id)
|
||||
|
||||
tado.add_sensor(data_id, {
|
||||
"zone": zone,
|
||||
"name": name,
|
||||
"id": zone_id,
|
||||
"data_id": data_id
|
||||
ATTR_ZONE: zone,
|
||||
ATTR_NAME: name,
|
||||
ATTR_ID: zone_id,
|
||||
ATTR_DATA_ID: data_id
|
||||
})
|
||||
|
||||
return TadoSensor(tado, name, zone_id, variable, data_id)
|
||||
@@ -62,10 +71,10 @@ def create_device_sensor(tado, device, name, device_id, variable):
|
||||
data_id = 'device {} {}'.format(name, device_id)
|
||||
|
||||
tado.add_sensor(data_id, {
|
||||
"device": device,
|
||||
"name": name,
|
||||
"id": device_id,
|
||||
"data_id": data_id
|
||||
ATTR_DEVICE: device,
|
||||
ATTR_NAME: name,
|
||||
ATTR_ID: device_id,
|
||||
ATTR_DATA_ID: data_id
|
||||
})
|
||||
|
||||
return TadoSensor(tado, name, device_id, variable, data_id)
|
||||
@@ -133,8 +142,7 @@ class TadoSensor(Entity):
|
||||
data = self._store.get_data(self._data_id)
|
||||
|
||||
if data is None:
|
||||
_LOGGER.debug('Recieved no data for zone %s',
|
||||
self.zone_name)
|
||||
_LOGGER.debug("Recieved no data for zone %s", self.zone_name)
|
||||
return
|
||||
|
||||
unit = TEMP_CELSIUS
|
||||
|
||||
@@ -8,9 +8,9 @@ import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (CONF_API_KEY, STATE_UNKNOWN)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
REQUIREMENTS = ['xboxapi==0.1.1']
|
||||
@@ -39,7 +39,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
if new_device.success_init:
|
||||
devices.append(new_device)
|
||||
|
||||
if len(devices) > 0:
|
||||
if devices:
|
||||
add_devices(devices)
|
||||
else:
|
||||
return False
|
||||
|
||||
Reference in new issue
Block a user