ELIQ Online platform cleanup (#1942)

This commit is contained in:
Erik Eriksson 2016-04-28 17:33:33 +02:00 committed by Paulus Schoutsen
parent 588a0cc947
commit cc202b886b
2 changed files with 28 additions and 16 deletions

View file

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

View file

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