Ejemplo n.º 1
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """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(CONF_CHANNEL_ID)

    if access_token is None:
        _LOGGER.error(
            "Configuration Error: "
            "Please make sure you have configured your access token "
            "that can be aquired from https://my.eliq.se/user/settings/api")
        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)])
Ejemplo n.º 2
0
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the ELIQ Online sensor."""
    access_token = config.get(CONF_ACCESS_TOKEN)
    name = config.get(CONF_NAME, DEFAULT_NAME)
    channel_id = config.get(CONF_CHANNEL_ID)
    session = async_get_clientsession(hass)

    api = eliqonline.API(session=session, access_token=access_token)

    try:
        _LOGGER.debug("Probing for access to ELIQ Online API")
        await api.get_data_now(channelid=channel_id)
    except OSError as error:
        _LOGGER.error("Could not access the ELIQ Online API: %s", error)
        return False

    async_add_entities([EliqSensor(api, channel_id, name)], True)
Ejemplo n.º 3
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the Eliq sensor."""
    import eliqonline

    access_token = config.get(CONF_ACCESS_TOKEN)
    name = config.get(CONF_NAME, DEFAULT_NAME)
    channel_id = config.get("channel_id")

    if access_token is None:
        _LOGGER.error(
            "Configuration Error: "
            "Please make sure you have configured your access token "
            "that can be aquired from https://my.eliq.se/user/settings/api")
        return False

    api = eliqonline.API(access_token)
    add_devices([EliqSensor(api, channel_id, name)])
Ejemplo n.º 4
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the ELIQ Online sensor."""
    import eliqonline

    access_token = config.get(CONF_ACCESS_TOKEN)
    name = config.get(CONF_NAME, DEFAULT_NAME)
    channel_id = config.get(CONF_CHANNEL_ID)

    api = eliqonline.API(access_token)

    try:
        _LOGGER.debug("Probing for access to ELIQ Online API")
        api.get_data_now(channelid=channel_id)
    except OSError as error:
        _LOGGER.error("Could not access the ELIQ Online API: %s", error)
        return False

    add_devices([EliqSensor(api, channel_id, name)], True)
Ejemplo n.º 5
0
 def __requestNewValue(self):
     accessToken = self.config('accessToken')
     if accessToken == '':
         return
     try:
         eliq = eliqonline.API(accessToken)
         data_now = eliq.get_data_now()
     except HTTPError as e:
         # Something wrong with our request apparantly
         logging.error('Could not request Eliq value %s', e)
         return
     except Exception as e:
         # Something wrong with our request apparantly
         logging.error('Could not request Eliq value %s', e)
         return
     if self.sensor is None:
         self.sensor = EliqSensor(data_now.channelid)
         self.sensor.setSensorValue(Sensor.WATT, data_now.power,
                                    Sensor.SCALE_POWER_WATT)
         self.deviceManager.addDevice(self.sensor)
         self.deviceManager.finishedLoading('eliq')
     else:
         self.sensor.setSensorValue(Sensor.WATT, data_now.power,
                                    Sensor.SCALE_POWER_WATT)