def __init__(self): # !! Cannot initialze self.logics here, because at startup logics are initialized after plugins !! self.logics = Logics.get_instance() self.logger.info("BackendLogics __init__ self.logics = {}".format(self.logics)) self.plugins = Plugins.get_instance() self.logger.info("BackendLogics __init__ self.plugins = {}".format(str(self.plugins))) self.scheduler = Scheduler.get_instance() self.logger.info("BackendLogics __init__ self.scheduler = {}".format(self.scheduler))
def __init__(self, smarthome, userlogicconf, envlogicconf): logger.info('Start Logics') self.shtime = Shtime.get_instance() self.items = Items.get_instance() self.plugins = Plugins.get_instance() self.scheduler = Scheduler.get_instance() self._sh = smarthome self._userlogicconf = userlogicconf self._env_dir = smarthome._env_dir self._envlogicconf = envlogicconf self._etc_dir = smarthome._etc_dir self._logic_dir = smarthome._logic_dir self._workers = [] self._logics = {} self._bytecode = {} self.alive = True global _logics_instance if _logics_instance is not None: import inspect curframe = inspect.currentframe() calframe = inspect.getouterframes(curframe, 4) logger.critical( "A second 'logics' object has been created. There should only be ONE instance of class 'Logics'!!! Called from: {} ({})" .format(calframe[1][1], calframe[1][3])) _logics_instance = self self.scheduler = Scheduler.get_instance() _config = {} self._systemlogics = self._read_logics(envlogicconf, self._env_dir) _config.update(self._systemlogics) self._userlogics = self._read_logics(userlogicconf, self._logic_dir) _config.update(self._userlogics) for name in _config: self._load_logic(name, _config)
def __init__(self, smarthome, userlogicconf, envlogicconf): logger.info('Start Logics') self.shtime = Shtime.get_instance() self.items = Items.get_instance() self.plugins = Plugins.get_instance() self.scheduler = Scheduler.get_instance() self._sh = smarthome self._userlogicconf = userlogicconf self._env_dir = smarthome._env_dir self._envlogicconf = envlogicconf self._etc_dir = smarthome._etc_dir self._logic_dir = smarthome._logic_dir self._workers = [] self._logics = {} self._bytecode = {} self.alive = True global _logics_instance if _logics_instance is not None: import inspect curframe = inspect.currentframe() calframe = inspect.getouterframes(curframe, 4) logger.critical("A second 'logics' object has been created. There should only be ONE instance of class 'Logics'!!! Called from: {} ({})".format(calframe[1][1], calframe[1][3])) _logics_instance = self self.scheduler = Scheduler.get_instance() _config = {} self._systemlogics = self._read_logics(envlogicconf, self._env_dir) _config.update(self._systemlogics) self._userlogics = self._read_logics(userlogicconf, self._logic_dir) _config.update(self._userlogics) for name in _config: self._load_logic(name, _config)
def __init__(self, smarthome, data_file, callers=None): self.logger = logging.getLogger(__name__) self.logger.info('Init Simulation release 1.5.0.6') self._sh = smarthome self.shtime = Shtime.get_instance() self._datafile = data_file self.lastday = '' self.items = Items.get_instance() self.scheduler = Scheduler.get_instance() self._callers = callers self._items = [] self.scheduler_add('midnight', self._midnight, cron='0 0 * *', prio=3) if not self.init_webinterface(): self._init_complete = False
def __init__(self, sh, *args, **kwargs): self.logger = logging.getLogger(__name__) self.logger.info('Init Simulation release %s' % self.PLUGIN_VERSION) self.shtime = Shtime.get_instance() self._datafile = self.get_parameter_value('data_file') self.lastday = '' self.items = Items.get_instance() self.scheduler = Scheduler.get_instance() if len(self.get_parameter_value('callers')) == 0: self._callers = None else: self._callers = self.get_parameter_value('callers') self._items = [] self.scheduler_add('midnight', self._midnight, cron='0 0 * *', prio=3) if not self.init_webinterface(): self._init_complete = False
def read(self, logicname=None): """ return an object with type info about all logics """ # create a list of dicts, where each dict contains the information for one logic self.logger.info("LogicsController.read()") if self.plugins is None: self.plugins = Plugins.get_instance() if self.scheduler is None: self.scheduler = Scheduler.get_instance() self.logics_initialize() if self.logics is None: # SmartHomeNG has not yet initialized the logics module (still starting up) raise cherrypy.NotFound if logicname is None: return self.get_logics_info() else: return self.get_logic_info(logicname)
def __init__(self, module): self._sh = module._sh self.module = module self.base_dir = self._sh.get_basedir() self.logger = logging.getLogger(__name__) self.etc_dir = self._sh._etc_dir self.logics_dir = os.path.join(self.base_dir, 'logics') self.logics = Logics.get_instance() self.logger.info("__init__ self.logics = {}".format(self.logics)) self.plugins = Plugins.get_instance() self.logger.info("__init__ self.plugins = {}".format(str( self.plugins))) self.scheduler = Scheduler.get_instance() self.logger.info("__init__ self.scheduler = {}".format(self.scheduler)) self.blockly_plugin_loaded = None self.logics_data = {} self.logics = Logics.get_instance() return
def update(self, logicname='', action='', filename=''): """ Handle PUT requests for logics API """ self.logger.info( "LogicsController.update(logicname='{}', action='{}')".format( logicname, action)) if self.plugins is None: self.plugins = Plugins.get_instance() if self.scheduler is None: self.scheduler = Scheduler.get_instance() self.logics_initialize() if self.logics is None: return json.dumps({ 'result': 'Error', 'description': "SmartHomeNG is still initializing" }) if (action == 'saveparameters') and (logicname != ''): return self.save_logic_parameters(logicname) elif not action in ['create', 'load', 'delete']: mylogic = self.logics.return_logic(logicname) if mylogic is None: return json.dumps({ 'result': 'Error', 'description': "No logic with name '" + logicname + "' found" }) if logicname != '': return self.set_logic_state(logicname, action, filename) return None
def __init__(self, smarthome, userlogicconf, envlogicconf): logger.info('Start Logics') self._sh = smarthome self._userlogicconf = userlogicconf self._env_dir = smarthome._env_dir self._envlogicconf = envlogicconf self._etc_dir = smarthome._etc_dir self._logic_dir = smarthome._logic_dir self._workers = [] self._logics = {} self._bytecode = {} self.alive = True global _logics_instance _logics_instance = self self.scheduler = Scheduler.get_instance() _config = {} self._systemlogics = self._read_logics(envlogicconf, self._env_dir) _config.update(self._systemlogics) self._userlogics = self._read_logics(userlogicconf, self._logic_dir) _config.update(self._userlogics) for name in _config: self._load_logic(name, _config)
def __init__(self, sh): """ Initialization Routine for the module """ # TO DO: Shortname anders setzen (oder warten bis der Modul Loader es beim Laden setzt) self._shortname = self.__class__.__name__ self._shortname = self._shortname.lower() self.logger = logging.getLogger(__name__) self._sh = sh self.shtime = Shtime.get_instance() self.logger.debug("Module '{}': Initializing".format(self._shortname)) # get the parameters for the plugin (as defined in metadata plugin.yaml): self.logger.debug("Module '{}': Parameters = '{}'".format( self._shortname, dict(self._parameters))) try: self.broker_hostname = self._parameters['broker_host'] self.broker_port = self._parameters['broker_port'] self.broker_monitoring = self._parameters['broker_monitoring'] self.qos = self._parameters['qos'] self.last_will_topic = self._parameters['last_will_topic'] self.last_will_payload = self._parameters['last_will_payload'] self.birth_topic = self._parameters['birth_topic'] self.birth_payload = self._parameters['birth_payload'] self.bool_values = self._parameters['bool_values'] # self.publish_items = self._parameters['publish_items'] # self.items_topic_prefix = self._parameters['items_topic_prefix'] self.username = self._parameters['user'] self.password = self._parameters['password'] # self.tls = self._parameters['tls'] # self.ca_certs = self._parameters['ca_certs'] # self.acl = self._parameters['acl'].lower() except KeyError as e: self.logger.critical( "Module '{}': Inconsistent module (invalid metadata definition: {} not defined)" .format(self._shortname, e)) self._init_complete = False return # resolve broker name, is no ip address is specified try: self.broker_ip = socket.gethostbyname(self.broker_hostname) except Exception as e: self.logger.error("Error resolving '{}': {}".format( self.broker_hostname, e)) self._init_complete = False return if self.broker_ip == self.broker_hostname: self.broker_hostname = '' # handle last_will and birth topic configuration if (self.last_will_topic != '') and (self.last_will_topic[-1] == '/'): self.last_will_topic = self.last_will_topic[:-1] if self.birth_topic == '': self.birth_topic = self.last_will_topic else: if self.birth_topic[-1] == '/': self.birth_topic = self.birth_topic[:-1] # if self.items_topic_prefix [-1] != '/': # self.items_topic_prefix = self.items_topic_prefix + '/' if self.password == '': self.password = None # tls ... # ca_certs ... # _subscribed_topics is a datastructure to keep track of subscribed topics # and the needed additional information # - who subscribed to the topic # - kind of subscriber (logic, plugin, ...) # - datatype of payload # # <topic1>: # <subscriber1_name>: # subsciber_type: 'logic' # callback: 'logic1name' # payload_type: 'str' # <subscriber2_name>: # subsciber_type: 'logic' # callback: 'logic2name' # payload_type: 'dict' # <topic2>: # <subscriber3_name>: # subsciber_type: 'plugin' # callback: obj_callback3 # payload_type: 'str' # <subscriber4_name>: # self._subscribed_topics_lock = threading.Lock() self._subscribed_topics = {} # subscribed topics self.logicpayloadtypes = { } # payload types for subscribed topics for triggering logics # ONLY used for multiinstance handling of plugins? # # needed because self.set_attr_value() can only set but not add attributes # self.at_instance_name = self.get_instance_name() # if self.at_instance_name != '': # self.at_instance_name = '@' + self.at_instance_name self.scheduler = Scheduler.get_instance() self._network_connected_to_broker = False self._connected = False self._connect_result = '' # tls ... # ca_certs ... if not self._connect_to_broker(): # self._init_complete = False # return pass
def __init__(self): self.scheduler = Scheduler.get_instance() self.logger.info( "BackendSchedulers __init__ self.scheduler = {}".format( self.scheduler))