Ejemplo n.º 1
0
    def run(self, appdaemon, hadashboard):

        loop = asyncio.get_event_loop()

        # Initialize AppDaemon

        self.AD = ad.AppDaemon(self.logger, self.error, self.diag, loop,
                               **appdaemon)

        # Initialize Dashboard/API

        if hadashboard["dashboard"] is True:
            self.log(self.logger, "INFO", "Starting Dashboards")
            self.rundash = rundash.RunDash(self.AD, loop, self.logger,
                                           self.access, **hadashboard)
            self.AD.register_dashboard(self.rundash)
        else:
            self.log(self.logger, "INFO", "Dashboards are disabled")

        if "api_port" in appdaemon:
            self.log(self.logger, "INFO", "Starting API")
            self.api = api.ADAPI(self.AD, loop, self.logger, self.access,
                                 **appdaemon)
        else:
            self.log(self.logger, "INFO", "API is disabled")

        self.log(self.logger, "DEBUG", "Start Loop")

        pending = asyncio.Task.all_tasks()
        loop.run_until_complete(asyncio.gather(*pending))

        self.log(self.logger, "DEBUG", "End Loop")

        self.log(self.logger, "INFO", "AppDeamon Exited")
Ejemplo n.º 2
0
    def run(self, appdaemon, hadashboard, admin, api, http):
        """ Start AppDaemon up after initial argument parsing.

        Args:
            appdaemon: Config for AppDaemon Object.
            hadashboard: Config for HADashboard Object.
            admin: Config for admin Object.
            api: Config for API Object
            http: Config for HTTP Object

        Returns:
            None.

        """

        try:
            loop = asyncio.get_event_loop()

            # Initialize AppDaemon

            self.AD = ad.AppDaemon(self.logging, loop, **appdaemon)

            # Initialize Dashboard/API/admin

            if http is not None and (hadashboard is not None or admin is not None or api is not False):
                self.logger.info("Initializing HTTP")
                self.http_object = adhttp.HTTP(self.AD, loop, self.logging, appdaemon, hadashboard, admin, api,
                                               http)
                self.AD.register_http(self.http_object)
            else:
                if http is not None:
                    self.logger.info("HTTP configured but no consumers are configured - disabling")
                else:
                    self.logger.info("HTTP is disabled")

            self.logger.debug("Start Main Loop")

            pending = asyncio.Task.all_tasks()
            loop.run_until_complete(asyncio.gather(*pending))

            #
            # Now we are shutting down - perform any necessary cleanup
            #

            self.AD.terminate()

            self.logger.info("AppDaemon is stopped.")

        except:
            self.logger.warning('-' * 60)
            self.logger.warning("Unexpected error during run()")
            self.logger.warning('-' * 60, exc_info=True)
            self.logger.warning('-' * 60)

            self.logger.debug("End Loop")

            self.logger.info("AppDaemon Exited")
Ejemplo n.º 3
0
    def run(self, appdaemon, hadashboard):

        try:
            loop = asyncio.get_event_loop()

            # Initialize AppDaemon

            self.AD = ad.AppDaemon(self.logger, self.error, self.diag, loop,
                                   **appdaemon)

            # Initialize Dashboard/API

            if hadashboard["dashboard"] is True:
                self.log(self.logger, "INFO", "Starting Dashboards")
                self.rundash = rundash.RunDash(self.AD, loop, self.logger,
                                               self.access, **hadashboard)
                self.AD.register_dashboard(self.rundash)
            else:
                self.log(self.logger, "INFO", "Dashboards are disabled")

            if "api_port" in appdaemon:
                self.log(self.logger, "INFO", "Starting API")
                self.api = api.ADAPI(self.AD, loop, self.logger, self.access,
                                     **appdaemon)
            else:
                self.log(self.logger, "INFO", "API is disabled")

            # Lets hide the admin interface for now

            #if "admin_port" in appdaemon:
            #    self.log(self.logger, "INFO", "Starting Admin Interface")
            #    self.runadmin = runadmin.RunAdmin(self.AD, loop, self.logger, self.access, **appdaemon)
            #else:
            #    self.log(self.logger, "INFO", "Admin Interface is disabled")

            self.log(self.logger, "DEBUG", "Start Loop")

            pending = asyncio.Task.all_tasks()
            loop.run_until_complete(asyncio.gather(*pending))
        except:
            self.log(self.logger, "WARNING", '-' * 60)
            self.log(self.logger, "WARNING", "Unexpected error during run()")
            self.log(self.logger, "WARNING", '-' * 60)
            self.log(self.logger, "WARNING", traceback.format_exc())
            self.log(self.logger, "WARNING", '-' * 60)

        self.log(self.logger, "DEBUG", "End Loop")

        self.log(self.logger, "INFO", "AppDeamon Exited")