예제 #1
0
    async def async_step_node_pro(self, user_input=None):
        """Handle the initialization of the integration with a Node/Pro."""
        if not user_input:
            return self.async_show_form(step_id="node_pro",
                                        data_schema=NODE_PRO_SCHEMA)

        await self._async_set_unique_id(user_input[CONF_IP_ADDRESS])

        node = NodeSamba(user_input[CONF_IP_ADDRESS],
                         user_input[CONF_PASSWORD])

        try:
            await node.async_connect()
        except NodeProError as err:
            LOGGER.error("Error connecting to Node/Pro unit: %s", err)
            return self.async_show_form(
                step_id="node_pro",
                data_schema=NODE_PRO_SCHEMA,
                errors={CONF_IP_ADDRESS: "cannot_connect"},
            )

        await node.async_disconnect()

        return self.async_create_entry(
            title=f"Node/Pro ({user_input[CONF_IP_ADDRESS]})",
            data={
                **user_input, CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_NODE_PRO
            },
        )
예제 #2
0
파일: __init__.py 프로젝트: jbouwh/core
 async def async_update_data() -> dict[str, Any]:
     """Get new data from the API."""
     try:
         async with NodeSamba(entry.data[CONF_IP_ADDRESS],
                              entry.data[CONF_PASSWORD]) as node:
             return await node.async_get_latest_measurements()
     except NodeProError as err:
         raise UpdateFailed(
             f"Error while retrieving data: {err}") from err
예제 #3
0
async def main() -> None:
    """Create the aiohttp session and run the example."""
    logging.basicConfig(level=logging.INFO)

    try:
        async with NodeSamba(NODE_PRO_IP_ADDRESS, NODE_PRO_PASSWORD) as node:
            _LOGGER.info(await node.async_get_latest_measurements())
            _LOGGER.info(await node.async_get_history())
    except NodeProError as err:
        _LOGGER.error(err)