Example #1
0
    def start(self):
        threading.currentThread().name = 'Main'

        #############################################################
        # Start Scheduler
        #############################################################
        self.scheduler = lib.scheduler.Scheduler(self)
        self.trigger = self.scheduler.trigger
        self.scheduler.start()

        #############################################################
        # Init Connections
        #############################################################
        self.connections = lib.connection.Connections()

        #############################################################
        # Init Plugins
        #############################################################
        self.logger.info("Init Plugins")
        self._plugins = lib.plugin.Plugins(
            self, configfile=self._plugin_conf_basename)

        #############################################################
        # Init Items
        #############################################################
        self.logger.info("Init Items")
        item_conf = None
        item_conf = lib.config.parse_itemsdir(self._env_dir, item_conf)
        item_conf = lib.config.parse_itemsdir(self._items_dir, item_conf)
        for attr, value in item_conf.items():
            if isinstance(value, dict):
                child_path = attr
                try:
                    child = lib.item.Item(self, self, child_path, value)
                except Exception as e:
                    self.logger.error("Item {}: problem creating: ()".format(
                        child_path, e))
                else:
                    vars(self)[attr] = child
                    self.add_item(child_path, child)
                    self.__children.append(child)
        del (item_conf)  # clean up
        for item in self.return_items():
            item._init_prerun()
        for item in self.return_items():
            item._init_run()
        self.item_count = len(self.__items)
        self.logger.info("Items: {}".format(self.item_count))

        #############################################################
        # Init Logics
        #############################################################
        self._logics = lib.logic.Logics(self, self._logic_conf_basename,
                                        self._env_logic_conf_basename)

        #############################################################
        # Init Scenes
        #############################################################
        lib.scene.Scenes(self)

        #############################################################
        # Start Connections
        #############################################################
        self.scheduler.add('Connections',
                           self.connections.check,
                           cycle=10,
                           offset=0)

        #############################################################
        # Start Plugins
        #############################################################
        self._plugins.start()

        #############################################################
        # Execute Maintenance Method
        #############################################################
        self.scheduler.add('sh.gc',
                           self._maintenance,
                           prio=8,
                           cron=['init', '4 2 * *'],
                           offset=0)

        #############################################################
        # Main Loop
        #############################################################
        while self.alive:
            try:
                self.connections.poll()
            except Exception as e:
                self.logger.exception(
                    "Connection polling failed: {}".format(e))
Example #2
0
    def start(self):
        """
        This function starts the threads of the main smarthome object.

        The main thread that is beeing started is called ``Main``
        """

        threading.currentThread().name = 'Main'

        #############################################################
        # Start Scheduler
        #############################################################
        self.scheduler = lib.scheduler.Scheduler(self)
        self.trigger = self.scheduler.trigger
        self.scheduler.start()

        #############################################################
        # Init Connections
        #############################################################
        self.connections = lib.connection.Connections()

        #############################################################
        # Init and start loadable Modules
        #############################################################
        if not(lib.utils.Utils.to_bool(self._use_modules) == False):
            self._logger.info("Init loadable Modules")
            self._modules = lib.module.Modules(self, configfile=self._module_conf_basename)
            self._modules.start()
        else:
            self._logger.info("Loadable Modules are disabled")

        #############################################################
        # Init Plugins
        #############################################################
        self._logger.info("Init Plugins")
        self._plugins = lib.plugin.Plugins(self, configfile=self._plugin_conf_basename)
        self.plugin_load_complete = True

        #############################################################
        # Init Items
        #############################################################
        self._logger.info("Start initialization of items")
        item_conf = None
        item_conf = lib.config.parse_itemsdir(self._env_dir, item_conf)
        item_conf = lib.config.parse_itemsdir(self._items_dir, item_conf, addfilenames=True)
        for attr, value in item_conf.items():
            if isinstance(value, dict):
                child_path = attr
                try:
                    child = lib.item.Item(self, self, child_path, value)
                except Exception as e:
                    self._logger.error("Item {}: problem creating: ()".format(child_path, e))
                else:
                    vars(self)[attr] = child
                    self.add_item(child_path, child)
                    self.__children.append(child)
        del(item_conf)  # clean up
        for item in self.return_items():
            item._init_prerun()
        for item in self.return_items():
            item._init_run()
        self.item_count = len(self.__items)
        self._logger.info("Items initialization finished, {} items loaded".format(self.item_count))
        self.item_load_complete = True

        #############################################################
        # Init Logics
        #############################################################
        self._logics = lib.logic.Logics(self, self._logic_conf_basename, self._env_logic_conf_basename)

        #############################################################
        # Init Scenes
        #############################################################
        lib.scene.Scenes(self)

        #############################################################
        # Start Connections
        #############################################################
        self.scheduler.add('sh.connections', self.connections.check, cycle=10, offset=0)

        #############################################################
        # Start Plugins
        #############################################################
        self._plugins.start()
        self.plugin_start_complete = True

        #############################################################
        # Execute Maintenance Method
        #############################################################
        self.scheduler.add('sh.garbage_collection', self._maintenance, prio=8, cron=['init', '4 2 * *'], offset=0)

        #############################################################
        # Main Loop
        #############################################################
        while self.alive:
            try:
                self.connections.poll()
            except Exception as e:
                self._logger.exception("Connection polling failed: {}".format(e))
Example #3
0
    def start(self):
        threading.currentThread().name = 'Main'

        #############################################################
        # Start Scheduler
        #############################################################
        self.scheduler = lib.scheduler.Scheduler(self)
        self.trigger = self.scheduler.trigger
        self.scheduler.start()

        #############################################################
        # Init Connections
        #############################################################
        self.connections = lib.connection.Connections()

        #############################################################
        # Init Plugins
        #############################################################
        self.logger.info("Init Plugins")
        self._plugins = lib.plugin.Plugins(self, configfile=self._plugin_conf)

        #############################################################
        # Init Items
        #############################################################
        self.logger.info("Init Items")
        item_conf = None
        for item_file in sorted(os.listdir(self._env_dir)):
            if item_file.endswith('.conf'):
                try:
                    item_conf = lib.config.parse(self._env_dir + item_file, item_conf)
                except Exception as e:
                    self.logger.exception("Problem reading {0}: {1}".format(item_file, e))
        for item_file in sorted(os.listdir(self._items_dir)):
            if item_file.endswith('.conf'):
                try:
                    item_conf = lib.config.parse(self._items_dir + item_file, item_conf)
                except Exception as e:
                    self.logger.exception("Problem reading {0}: {1}".format(item_file, e))
                    continue
        for attr, value in item_conf.items():
            if isinstance(value, dict):
                child_path = attr
                try:
                    child = lib.item.Item(self, self, child_path, value)
                except Exception as e:
                    self.logger.error("Item {}: problem creating: ()".format(child_path, e))
                else:
                    vars(self)[attr] = child
                    self.add_item(child_path, child)
                    self.__children.append(child)
        del(item_conf)  # clean up
        for item in self.return_items():
            item._init_prerun()
        for item in self.return_items():
            item._init_run()
        self.item_count = len(self.__items)
        self.logger.info("Items: {}".format(self.item_count))

        #############################################################
        # Init Logics
        #############################################################
        self._logics = lib.logic.Logics(self, self._logic_conf, self._env_logic_conf)

        #############################################################
        # Init Scenes
        #############################################################
        lib.scene.Scenes(self)

        #############################################################
        # Start Connections
        #############################################################
        self.scheduler.add('Connections', self.connections.check, cycle=10, offset=0)

        #############################################################
        # Start Plugins
        #############################################################
        self._plugins.start()

        #############################################################
        # Execute Maintenance Method
        #############################################################
        self.scheduler.add('sh.gc', self._maintenance, prio=8, cron=['init', '4 2 * *'], offset=0)

        #############################################################
        # Main Loop
        #############################################################
        while self.alive:
            try:
                self.connections.poll()
            except Exception as e:
                self.logger.exception("Connection polling failed: {}".format(e))
Example #4
0
    def start(self):
        """
        This function starts the threads of the main smarthome object.

        The main thread that is beeing started is called ``Main``
        """

        threading.currentThread().name = 'Main'

        #############################################################
        # Start Scheduler
        #############################################################
        self.scheduler = lib.scheduler.Scheduler(self)
        self.trigger = self.scheduler.trigger
        self.scheduler.start()

        #############################################################
        # Init Connections
        #############################################################
        self.connections = lib.connection.Connections()

        #############################################################
        # Init and start loadable Modules
        #############################################################
        if not (lib.utils.Utils.to_bool(self._use_modules) == False):
            self._logger.info("Init loadable Modules")
            self._modules = lib.module.Modules(
                self, configfile=self._module_conf_basename)
            self._modules.start()
        else:
            self._logger.info("Loadable Modules are disabled")

        #############################################################
        # Init Plugins
        #############################################################
        self._logger.info("Init Plugins")
        self._plugins = lib.plugin.Plugins(
            self, configfile=self._plugin_conf_basename)
        self.plugin_load_complete = True

        #############################################################
        # Init Items
        #############################################################
        self._logger.info("Start initialization of items")
        item_conf = None
        item_conf = lib.config.parse_itemsdir(self._env_dir, item_conf)
        item_conf = lib.config.parse_itemsdir(self._items_dir,
                                              item_conf,
                                              addfilenames=True)
        for attr, value in item_conf.items():
            if isinstance(value, dict):
                child_path = attr
                try:
                    child = lib.item.Item(self, self, child_path, value)
                except Exception as e:
                    self._logger.error("Item {}: problem creating: ()".format(
                        child_path, e))
                else:
                    vars(self)[attr] = child
                    self.add_item(child_path, child)
                    self.__children.append(child)
        del (item_conf)  # clean up
        for item in self.return_items():
            item._init_prerun()
        for item in self.return_items():
            item._init_run()
        self.item_count = len(self.__items)
        self._logger.info(
            "Items initialization finished, {} items loaded".format(
                self.item_count))
        self.item_load_complete = True

        #############################################################
        # Init Logics
        #############################################################
        self._logics = lib.logic.Logics(self, self._logic_conf_basename,
                                        self._env_logic_conf_basename)

        #############################################################
        # Init Scenes
        #############################################################
        lib.scene.Scenes(self)

        #############################################################
        # Start Connections
        #############################################################
        self.scheduler.add('sh.connections',
                           self.connections.check,
                           cycle=10,
                           offset=0)

        #############################################################
        # Start Plugins
        #############################################################
        self._plugins.start()
        self.plugin_start_complete = True

        #############################################################
        # Execute Maintenance Method
        #############################################################
        self.scheduler.add('sh.garbage_collection',
                           self._maintenance,
                           prio=8,
                           cron=['init', '4 2 * *'],
                           offset=0)

        #############################################################
        # Main Loop
        #############################################################
        while self.alive:
            try:
                self.connections.poll()
            except Exception as e:
                self._logger.exception(
                    "Connection polling failed: {}".format(e))