def update_linky_data(self, event_time=None):
     """Fetch new state data for the sensor."""
     client = LinkyClient(self._username, self._password, None, self._timeout)
     try:
         client.login()
         client.fetch_data()
         self._data = client.get_data()
         _LOGGER.debug(json.dumps(self._data, indent=2))
     except PyLinkyException as exp:
         _LOGGER.error(exp)
     finally:
         client.close_session()
Exemple #2
0
    async def async_step_user(self, user_input=None):
        """Handle a flow initiated by the user."""
        errors = {}

        if user_input is None:
            return self._show_setup_form(user_input, None)

        username = user_input[CONF_USERNAME]
        password = user_input[CONF_PASSWORD]
        timeout = user_input.get(CONF_TIMEOUT, DEFAULT_TIMEOUT)

        # Check if already configured
        if self.unique_id is None:
            await self.async_set_unique_id(username)
            self._abort_if_unique_id_configured()

        client = LinkyClient(username, password, None, timeout)
        try:
            await self.hass.async_add_executor_job(client.login)
            await self.hass.async_add_executor_job(client.fetch_data)
        except PyLinkyAccessException as exp:
            _LOGGER.error(exp)
            errors["base"] = "access"
            return self._show_setup_form(user_input, errors)
        except PyLinkyEnedisException as exp:
            _LOGGER.error(exp)
            errors["base"] = "enedis"
            return self._show_setup_form(user_input, errors)
        except PyLinkyWrongLoginException as exp:
            _LOGGER.error(exp)
            errors["base"] = "wrong_login"
            return self._show_setup_form(user_input, errors)
        except PyLinkyException as exp:
            _LOGGER.error(exp)
            errors["base"] = "unknown"
            return self._show_setup_form(user_input, errors)
        finally:
            client.close_session()

        return self.async_create_entry(
            title=username,
            data={
                CONF_USERNAME: username,
                CONF_PASSWORD: password,
                CONF_TIMEOUT: timeout,
            },
        )
Exemple #3
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Configure the platform and add the Linky sensor."""
    username = config[CONF_USERNAME]
    password = config[CONF_PASSWORD]
    timeout = config[CONF_TIMEOUT]

    from pylinky.client import LinkyClient, PyLinkyError
    client = LinkyClient(username, password, None, timeout)

    try:
        client.fetch_data()
    except PyLinkyError as exp:
        _LOGGER.error(exp)
        return

    devices = [LinkySensor('Linky', client)]
    add_entities(devices, True)
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Configure the platform and add the Linky sensor."""
    username = config[CONF_USERNAME]
    password = config[CONF_PASSWORD]
    timeout = config[CONF_TIMEOUT]
    prix = config[CONF_PRIX]
    _LOGGER.debug("prix : " + str(prix))
    from pylinky.client import LinkyClient, PyLinkyError
    client = LinkyClient(username, password, None, timeout)
    try:
        client.login()
        client.fetch_data()
    except PyLinkyError as exp:
        _LOGGER.error(exp)
        client.close_session()
        return

    devices = [LinkySensor('Linky / hier', client, 'daily', 'compteur', None)]
    add_entities(devices, True)

    devices = [
        LinkySensor('Linky / Mois Current', client, "monthly", 'compteur',
                    None)
    ]
    add_entities(devices, True)

    devices = [
        LinkySensor('Linky / Année Current', client, "yearly", 'compteur',
                    None)
    ]
    add_entities(devices, True)

    devices = [LinkySensor('Prix / hier', client, 'daily', 'prix', prix)]
    add_entities(devices, True)

    devices = [
        LinkySensor('Prix / Mois Current', client, "monthly", 'prix', prix)
    ]
    add_entities(devices, True)

    devices = [
        LinkySensor('prix / Année Current', client, "yearly", 'prix', prix)
    ]
    add_entities(devices, True)