From ebe233cd3200e2f44a5701e34417a73bd122168f Mon Sep 17 00:00:00 2001 From: Keilin Date: Tue, 23 Oct 2018 15:08:54 -0400 Subject: [PATCH] Code cleanup --- homeassistant/components/binary_sensor/sense.py | 16 +++++----------- homeassistant/components/sense.py | 12 ++++++------ homeassistant/components/sensor/sense.py | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/binary_sensor/sense.py b/homeassistant/components/binary_sensor/sense.py index d46a2894026..55d685276da 100644 --- a/homeassistant/components/binary_sensor/sense.py +++ b/homeassistant/components/binary_sensor/sense.py @@ -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 diff --git a/homeassistant/components/sense.py b/homeassistant/components/sense.py index 230418a74b5..ac7de68bd3d 100644 --- a/homeassistant/components/sense.py +++ b/homeassistant/components/sense.py @@ -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 diff --git a/homeassistant/components/sensor/sense.py b/homeassistant/components/sensor/sense.py index 6b2507bbf73..bab56db7da9 100644 --- a/homeassistant/components/sensor/sense.py +++ b/homeassistant/components/sensor/sense.py @@ -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