コード例 #1
0
    async def async_step_user(self, user_input=None):
        """Handle the start of the config flow.

        Called after wiffi integration has been selected in the 'add integration
        UI'. The user_input is set to None in this case. We will open a config
        flow form then.
        This function is also called if the form has been submitted. user_input
        contains a dict with the user entered values then.
        """
        if user_input is None:
            return self._async_show_form()

        # received input from form or configuration.yaml
        self._async_abort_entries_match(user_input)

        try:
            # try to start server to check whether port is in use
            server = WiffiTcpServer(user_input[CONF_PORT])
            await server.start_server()
            await server.close_server()
            return self.async_create_entry(
                title=f"Port {user_input[CONF_PORT]}", data=user_input)
        except OSError as exc:
            if exc.errno == errno.EADDRINUSE:
                return self.async_abort(reason="addr_in_use")
            return self.async_abort(reason="start_server_failed")
コード例 #2
0
 def async_setup(self, config_entry):
     """Set up api instance."""
     self._server = WiffiTcpServer(config_entry.data[CONF_PORT], self)
     self._periodic_callback = async_track_time_interval(
         self._hass, self._periodic_tick, timedelta(seconds=10))