From cc202b886b28f9d9972824ec425c17cf4eaff74b Mon Sep 17 00:00:00 2001 From: Erik Eriksson Date: Thu, 28 Apr 2016 17:33:33 +0200 Subject: [PATCH] ELIQ Online platform cleanup (#1942) --- homeassistant/components/sensor/eliqonline.py | 42 ++++++++++++------- requirements_all.txt | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/sensor/eliqonline.py b/homeassistant/components/sensor/eliqonline.py index 9c2c8242b68..0a82f5d587c 100644 --- a/homeassistant/components/sensor/eliqonline.py +++ b/homeassistant/components/sensor/eliqonline.py @@ -1,5 +1,5 @@ """ -Monitors home energy use for the eliq online service. +Monitors home energy use for the ELIQ Online service. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.eliqonline/ @@ -12,17 +12,21 @@ from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['eliqonline==1.0.11'] -DEFAULT_NAME = "ELIQ Energy Usage" +REQUIREMENTS = ['eliqonline==1.0.12'] +DEFAULT_NAME = "ELIQ Online" +UNIT_OF_MEASUREMENT = "W" +ICON = "mdi:speedometer" +CONF_CHANNEL_ID = "channel_id" +SCAN_INTERVAL = 60 def setup_platform(hass, config, add_devices, discovery_info=None): - """Setup the Eliq sensor.""" + """Setup the ELIQ Online sensor.""" import eliqonline access_token = config.get(CONF_ACCESS_TOKEN) name = config.get(CONF_NAME, DEFAULT_NAME) - channel_id = config.get("channel_id") + channel_id = config.get(CONF_CHANNEL_ID) if access_token is None: _LOGGER.error( @@ -32,20 +36,27 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return False api = eliqonline.API(access_token) + + try: + _LOGGER.debug("Probing for access to ELIQ Online API") + api.get_data_now(channelid=channel_id) + except URLError: + _LOGGER.error("Could not access the ELIQ Online API. " + "Is the configuration valid?") + return False + add_devices([EliqSensor(api, channel_id, name)]) class EliqSensor(Entity): - """Implementation of an Eliq sensor.""" + """Implementation of an ELIQ Online sensor.""" def __init__(self, api, channel_id, name): """Initialize the sensor.""" self._name = name - self._unit_of_measurement = "W" self._state = STATE_UNKNOWN - - self.api = api - self.channel_id = channel_id + self._api = api + self._channel_id = channel_id self.update() @property @@ -56,12 +67,12 @@ class EliqSensor(Entity): @property def icon(self): """Return icon.""" - return "mdi:speedometer" + return ICON @property def unit_of_measurement(self): """Return the unit of measurement of this entity, if any.""" - return self._unit_of_measurement + return UNIT_OF_MEASUREMENT @property def state(self): @@ -71,7 +82,8 @@ class EliqSensor(Entity): def update(self): """Get the latest data.""" 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) - except (TypeError, URLError): - _LOGGER.error("Could not connect to the eliqonline servers") + _LOGGER.debug("Updated power from server %d W", self._state) + except URLError: + _LOGGER.error("Could not connect to the ELIQ Online API") diff --git a/requirements_all.txt b/requirements_all.txt index 54f1dd93c4b..d5948cd28aa 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -44,7 +44,7 @@ dnspython3==1.12.0 dweepy==0.2.0 # homeassistant.components.sensor.eliqonline -eliqonline==1.0.11 +eliqonline==1.0.12 # homeassistant.components.thermostat.honeywell evohomeclient==0.2.5