Code cleanup

This commit is contained in:
Keilin
2018-10-23 15:08:54 -04:00
parent 704a66c6ac
commit ebe233cd32
3 changed files with 12 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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