ELIQ Online platform cleanup (#1942)
This commit is contained in:
parent
588a0cc947
commit
cc202b886b
2 changed files with 28 additions and 16 deletions
|
@ -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
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.eliqonline/
|
https://home-assistant.io/components/sensor.eliqonline/
|
||||||
|
@ -12,17 +12,21 @@ from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQUIREMENTS = ['eliqonline==1.0.11']
|
REQUIREMENTS = ['eliqonline==1.0.12']
|
||||||
DEFAULT_NAME = "ELIQ Energy Usage"
|
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):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Eliq sensor."""
|
"""Setup the ELIQ Online sensor."""
|
||||||
import eliqonline
|
import eliqonline
|
||||||
|
|
||||||
access_token = config.get(CONF_ACCESS_TOKEN)
|
access_token = config.get(CONF_ACCESS_TOKEN)
|
||||||
name = config.get(CONF_NAME, DEFAULT_NAME)
|
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:
|
if access_token is None:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
@ -32,20 +36,27 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
api = eliqonline.API(access_token)
|
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)])
|
add_devices([EliqSensor(api, channel_id, name)])
|
||||||
|
|
||||||
|
|
||||||
class EliqSensor(Entity):
|
class EliqSensor(Entity):
|
||||||
"""Implementation of an Eliq sensor."""
|
"""Implementation of an ELIQ Online sensor."""
|
||||||
|
|
||||||
def __init__(self, api, channel_id, name):
|
def __init__(self, api, channel_id, name):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._unit_of_measurement = "W"
|
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
|
self._api = api
|
||||||
self.api = api
|
self._channel_id = channel_id
|
||||||
self.channel_id = channel_id
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -56,12 +67,12 @@ class EliqSensor(Entity):
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Return icon."""
|
"""Return icon."""
|
||||||
return "mdi:speedometer"
|
return ICON
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
return self._unit_of_measurement
|
return UNIT_OF_MEASUREMENT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
@ -71,7 +82,8 @@ class EliqSensor(Entity):
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data."""
|
"""Get the latest data."""
|
||||||
try:
|
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)
|
self._state = int(response.power)
|
||||||
except (TypeError, URLError):
|
_LOGGER.debug("Updated power from server %d W", self._state)
|
||||||
_LOGGER.error("Could not connect to the eliqonline servers")
|
except URLError:
|
||||||
|
_LOGGER.error("Could not connect to the ELIQ Online API")
|
||||||
|
|
|
@ -44,7 +44,7 @@ dnspython3==1.12.0
|
||||||
dweepy==0.2.0
|
dweepy==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.sensor.eliqonline
|
# homeassistant.components.sensor.eliqonline
|
||||||
eliqonline==1.0.11
|
eliqonline==1.0.12
|
||||||
|
|
||||||
# homeassistant.components.thermostat.honeywell
|
# homeassistant.components.thermostat.honeywell
|
||||||
evohomeclient==0.2.5
|
evohomeclient==0.2.5
|
||||||
|
|
Loading…
Add table
Reference in a new issue