mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 13:45:12 +02:00
Code cleanup
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""
|
||||
Support for monitoring a Sense energy sensor.
|
||||
Support for monitoring a Sense energy sensor device.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.sense/
|
||||
https://home-assistant.io/components/binary_sensor.sense/
|
||||
"""
|
||||
import logging
|
||||
import voluptuous as vol
|
||||
@@ -26,14 +26,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Sense sensor."""
|
||||
data = hass.data[SENSE_DATA]
|
||||
|
||||
def update_active():
|
||||
"""Update the active power usage."""
|
||||
data.get_realtime()
|
||||
|
||||
devices = []
|
||||
|
||||
device = config.get(CONF_NAME)
|
||||
devices.append(SenseDevice(data, device, update_active))
|
||||
devices.append(SenseDevice(data, device))
|
||||
|
||||
add_entities(devices)
|
||||
|
||||
@@ -41,11 +36,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
class SenseDevice(BinarySensorDevice):
|
||||
"""Implementation of a Sense energy device binary sensor."""
|
||||
|
||||
def __init__(self, data, name, update_call):
|
||||
def __init__(self, data, name):
|
||||
"""Initialize the sensor."""
|
||||
self._name = name
|
||||
self._data = data
|
||||
self.update_sensor = update_call
|
||||
self._state = False
|
||||
|
||||
@property
|
||||
@@ -67,7 +61,7 @@ class SenseDevice(BinarySensorDevice):
|
||||
"""Retrieve latest state."""
|
||||
from sense_energy import SenseAPITimeoutException
|
||||
try:
|
||||
self.update_sensor()
|
||||
self._data.get_realtime()
|
||||
except SenseAPITimeoutException:
|
||||
_LOGGER.error("Timeout retrieving data")
|
||||
return
|
||||
|
@@ -2,7 +2,7 @@
|
||||
Support for monitoring a Sense energy sensor.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.sense/
|
||||
https://home-assistant.io/components/sense/
|
||||
"""
|
||||
import logging
|
||||
import voluptuous as vol
|
||||
@@ -18,17 +18,17 @@ SENSE_DATA = 'sense_data'
|
||||
|
||||
DOMAIN = 'sense'
|
||||
|
||||
ACTIVE_UPDATE_RATE = 30
|
||||
DEFAULT_TIMEOUT = 5
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_EMAIL): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_TIMEOUT): cv.positive_int,
|
||||
vol.Optional(CONF_TIMEOUT, DEFAULT_TIMEOUT): cv.positive_int,
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
ACTIVE_UPDATE_RATE = 30
|
||||
DEFAULT_TIMEOUT = 5
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Sense sensor."""
|
||||
@@ -37,7 +37,7 @@ def setup(hass, config):
|
||||
username = config[DOMAIN].get(CONF_EMAIL)
|
||||
password = config[DOMAIN].get(CONF_PASSWORD)
|
||||
|
||||
timeout = config[DOMAIN].get(CONF_TIMEOUT, DEFAULT_TIMEOUT)
|
||||
timeout = config[DOMAIN].get(CONF_TIMEOUT)
|
||||
hass.data[SENSE_DATA] = Senseable(api_timeout=timeout, wss_timeout=timeout)
|
||||
hass.data[SENSE_DATA].authenticate(username, password)
|
||||
hass.data[SENSE_DATA].rate_limit = ACTIVE_UPDATE_RATE
|
||||
|
@@ -73,7 +73,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
data.get_realtime()
|
||||
|
||||
devices = []
|
||||
for sensor in config.get(CONF_MONITORED_CONDITIONS, []):
|
||||
for sensor in config.get(CONF_MONITORED_CONDITIONS):
|
||||
config_name, prod = sensor.rsplit('_', 1)
|
||||
name = SENSOR_TYPES[config_name].name
|
||||
sensor_type = SENSOR_TYPES[config_name].sensor_type
|
||||
|
Reference in New Issue
Block a user