def __init__(self, smarthome): if '.'.join(VERSION.split('.', 2)[:2]) <= '1.5': self.logger = logging.getLogger(__name__) try: self.shtime = Shtime.get_instance() try: self.dl = Http(timeout=self.get_parameter_value('timeout')) except: self.dl = Http('') self._items = [] self._icals = {} self._ical_aliases = {} self.sh = smarthome cycle = self.get_parameter_value('cycle') calendars = self.get_parameter_value('calendars') config_dir = self.get_parameter_value('directory') except Exception as err: self.logger.error('Problems initializing: {}'.format(err)) self._init_complete = False return try: self._directory = '{}/{}'.format(self.get_vardir(), config_dir) except Exception: self._directory = '{}/var/{}'.format(self.sh.get_basedir(), config_dir) try: os.makedirs(self._directory) self.logger.debug('Created {} subfolder in var'.format(config_dir)) except OSError as e: if e.errno != errno.EEXIST: self.logger.error( 'Problem creating {} folder in {}/var'.format( config_dir, self.sh.get_basedir())) self._init_complete = False return for calendar in calendars: if isinstance(calendar, dict): calendar = list("{!s}:{!s}".format(k, v) for (k, v) in calendar.items())[0] if ':' in calendar and 'http' != calendar[:4]: name, _, cal = calendar.partition(':') calendar = cal.strip() self.logger.info( 'Registering calendar {} with alias {}.'.format( calendar, name)) self._ical_aliases[name.strip()] = calendar else: self.logger.info( 'Registering calendar {} without alias.'.format(calendar)) calendar = calendar.strip() self._icals[calendar] = self._read_events(calendar) smarthome.scheduler.add('iCalUpdate', self._update_items, cron='* * * *', prio=5) smarthome.scheduler.add('iCalRefresh', self._update_calendars, cycle=int(cycle), prio=5)
def __init__(self, smarthome): self.host = self.get_parameter_value('host') self.port = self.get_parameter_value('port') from bin.smarthome import VERSION if '.'.join(VERSION.split('.', 2)[:2]) <= '1.5': self.logger = logging.getLogger(__name__) lib.connection.Client.__init__(self, self.host, self.port, monitor=True) self.logger.debug("init knx") self.shtime = Shtime.get_instance() busmonitor = self.get_parameter_value('busmonitor') self.gal = { } # group addresses to listen to {DPT: dpt, ITEMS: [item 1, item 2, ..., item n], LOGICS: [ logic 1, logic 2, ..., logic n]} self.gar = { } # group addresses to reply if requested from knx, {DPT: dpt, ITEM: item, LOGIC: None} self._init_ga = [] self._cache_ga = [ ] # group addresses which should be initalized by the knxd cache self._cache_ga_response_pending = [] self.time_ga = self.get_parameter_value('time_ga') self.date_ga = self.get_parameter_value('date_ga') send_time = self.get_parameter_value('send_time') self._bm_separatefile = False self._bm_format = "BM': {1} set {2} to {3}" # following needed for statistics self.enable_stats = self.get_parameter_value('enable_stats') self.stats_ga = {} # statistics for used group addresses on the BUS self.stats_pa = {} # statistics for used group addresses on the BUS self.stats_last_read = None # last read request from KNX self.stats_last_write = None # last write from KNX self.stats_last_response = None # last response from KNX self.stats_last_action = None # the newes if busmonitor.lower() in ['on', 'true']: self._busmonitor = self.logger.info elif busmonitor.lower() in ['off', 'false']: self._busmonitor = self.logger.debug elif busmonitor.lower() == 'logger': self._bm_separatefile = True self._bm_format = "{0};{1};{2};{3}" self._busmonitor = logging.getLogger("knx_busmonitor").info self.logger.warning( "Using busmonitor (L) = '{}'".format(busmonitor)) else: self.logger.warning( "Invalid value '{}' configured for parameter 'busmonitor', using 'false'" .format(busmonitor)) self._busmonitor = self.logger.debug if send_time: self._sh.scheduler.add('KNX[{0}] time'.format( self.get_instance_name()), self._send_time, prio=5, cycle=int(send_time)) self.readonly = self.get_parameter_value('readonly') if self.readonly: self.logger.warning("!!! KNX Plugin in READONLY mode !!! ") self.init_webinterface() return
def __init__(self, sh, *args, **kwargs): """ Initalizes the plugin. The parameters describe for this method are pulled from the entry in plugin.conf. :param sh: **Deprecated**: The instance of the smarthome object. For SmartHomeNG versions 1.4 and up: **Don't use it**! :param *args: **Deprecated**: Old way of passing parameter values. For SmartHomeNG versions 1.4 and up: **Don't use it**! :param **kwargs:**Deprecated**: Old way of passing parameter values. For SmartHomeNG versions 1.4 and up: **Don't use it**! If you need the sh object at all, use the method self.get_sh() to get it. There should be almost no need for a reference to the sh object any more. """ from bin.smarthome import VERSION if '.'.join(VERSION.split('.', 2)[:2]) <= '1.5': self.logger = logging.getLogger(__name__) # get the parameters for the plugin (as defined in metadata plugin.yaml): # self.param1 = self.get_parameter_value('param1') self.udp_ip = self.get_parameter_value('udp_ip') self.udp_port = self.get_parameter_value('udp_port') self.hue_calibrate = self.get_parameter_value('hue_calibrate') self.white_calibrate = self.get_parameter_value('white_calibrate') # old: True will change color and brightness --> 'HUE_AND_LUM' (default) # False will change only color --> 'HUE' self.bricontrol = False if self.get_parameter_value( 'bricontrol') == 'HUE' else True self.cutoff = self.get_parameter_value('cutoff') # Initialization code goes here self.color_map = { # for reference and future use 'violet': 0x00, 'royal_blue': 0x10, 'baby_blue': 0x20, 'aqua': 0x30, 'mint': 0x40, 'seafoam_green': 0x50, 'green': 0x60, 'lime_green': 0x70, 'yellow': 0x80, 'yellow_orange': 0x90, 'orange': 0xA0, 'red': 0xB0, 'pink': 0xC0, 'fusia': 0xD0, 'lilac': 0xE0, 'lavendar': 0xF0 } self.on_all = bytearray([0x42, 0x00, 0x55]) self.on_ch1 = bytearray([0x45, 0x00, 0x55]) self.on_ch2 = bytearray([0x47, 0x00, 0x55]) self.on_ch3 = bytearray([0x49, 0x00, 0x55]) self.on_ch4 = bytearray([0x4B, 0x00, 0x55]) self.off_all = bytearray([0x41, 0x00, 0x55]) self.off_ch1 = bytearray([0x46, 0x00, 0x55]) self.off_ch2 = bytearray([0x48, 0x00, 0x55]) self.off_ch3 = bytearray([0x4A, 0x00, 0x55]) self.off_ch4 = bytearray([0x4C, 0x00, 0x55]) self.white_ch1 = bytearray([0xC5, 0x00, 0x55]) self.white_ch2 = bytearray([0xC7, 0x00, 0x55]) self.white_ch3 = bytearray([0xC9, 0x00, 0x55]) self.white_ch4 = bytearray([0xCB, 0x00, 0x55]) self.brightness = bytearray([0x4E, 0x00, 0x55]) self.color = bytearray([0x40, 0x00, 0x55]) self.max_bright = bytearray([0x4E, 0x3B, 0x55]) self.discoon = bytearray([0x4D, 0x00, 0x55]) self.discoup = bytearray([0x44, 0x00, 0x55]) self.discodown = bytearray([0x43, 0x00, 0x55]) # if plugin should start even without web interface self.init_webinterface()
def __init__(self, sh, *args, **kwargs): """ Initializes the DLMS plugin The parameter are retrieved from get_parameter_value(parameter_name) """ from bin.smarthome import VERSION if '.'.join(VERSION.split('.', 2)[:2]) <= '1.5': self.logger = logging.getLogger(__name__) self.logger.debug(f"init {__name__}") self._init_complete = False # Exit if the required package(s) could not be imported if not REQUIRED_PACKAGE_IMPORTED: self.logger.error( f"{self.get_fullname()}: Unable to import Python package 'pyserial'" ) return self._instance = self.get_parameter_value( 'instance' ) # the instance of the plugin for questioning multiple smartmeter self._update_cycle = self.get_parameter_value( 'update_cycle' ) # the frequency in seconds how often the device should be accessed if self._update_cycle == 0: self._update_cycle = None self._update_crontab = self.get_parameter_value( 'update_crontab' ) # the more complex way to specify the device query frequency if self._update_crontab == '': self._update_crontab = None if not (self._update_cycle or self._update_crontab): self.logger.error( f"{self.get_fullname()}: no update cycle or crontab set. The smartmeter will not be queried automatically" ) self._sema = Semaphore( ) # implement a semaphore to avoid multiple calls of the query function self._min_cycle_time = 0 # we measure the time for the value query and add some security value of 10 seconds self.dlms_obis_code_items = [] # this is a list of items to be updated self.dlms_obis_codes = [ ] # this is a list of codes that are to be parsed self.dlms_obis_readout_items = [ ] # this is a list of items that receive the full readout self._last_readout = "" # dict especially for the interface # 'serialport', 'device', 'querycode', 'speed', 'baudrate_fix', 'timeout', 'onlylisten', 'use_checksum' self._config = {} self._config['serialport'] = self.get_parameter_value('serialport') if not self._config['serialport']: return # there is a possibility of using a named device # normally this will be empty since only one meter will be attached # to one serial interface but the standard allows for it and we honor that. self._config['device'] = self.get_parameter_value('device_address') self._config['querycode'] = self.get_parameter_value('querycode') self._config['timeout'] = self.get_parameter_value('timeout') self._config['baudrate'] = self.get_parameter_value('baudrate') self._config['baudrate_fix'] = self.get_parameter_value('baudrate_fix') self._config['use_checksum'] = self.get_parameter_value('use_checksum') self._config['onlylisten'] = self.get_parameter_value('only_listen') self._config['reset_baudrate'] = self.get_parameter_value( 'reset_baudrate') self._config['no_waiting'] = self.get_parameter_value('no_waiting') self.logger.debug( f"Instance {self._instance if self._instance else 0} of DLMS configured to use serialport '{self._config.get('serialport')}' with update cycle of {self._update_cycle} seconds" ) self.logger.debug(f"Config: {self._config}") self.init_webinterface() self.logger.debug("init done") self._init_complete = True
def __init__(self, sh, *args, **kwargs): """ Initalizes the plugin. The parameters descriptions for this method are pulled from the entry in plugin.yaml. :param sh: **Deprecated**: The instance of the smarthome object. For SmartHomeNG versions **beyond** 1.3: **Don't use it**! :param *args: **Deprecated**: Old way of passing parameter values. For SmartHomeNG versions **beyond** 1.3: **Don't use it**! :param **kwargs:**Deprecated**: Old way of passing parameter values. For SmartHomeNG versions **beyond** 1.3: **Don't use it**! If you need the sh object at all, use the method self.get_sh() to get it. There should be almost no need for a reference to the sh object any more. The parameters *args and **kwargs are the old way of passing parameters. They are deprecated. They are imlemented to support older plugins. Plugins for SmartHomeNG v1.4 and beyond should use the new way of getting parameter values: use the SmartPlugin method get_parameter_value(parameter_name) instead. Anywhere within the Plugin you can get the configured (and checked) value for a parameter by calling self.get_parameter_value(parameter_name). It returns the value in the datatype that is defined in the metadata. """ from bin.smarthome import VERSION if '.'.join(VERSION.split('.', 2)[:2]) <= '1.5': self.logger = logging.getLogger(__name__) # get the parameters for the plugin (as defined in metadata plugin.yaml): # self.param1 = self.get_parameter_value('param1') # Initialization code goes here self.username = self.get_parameter_value('username') self.password = self.get_parameter_value('password') self.host = self.get_parameter_value('host') # self.port = self.get_parameter_value('port') # self.port_hmip = self.get_parameter_value('port_hmip') self.port = 2001 self.port_hmip = 2010 # build dict identifier for the homematic ccu of this plugin instance self.hm_id = 'rf' if self.get_instance_name() != '': self.hm_id += '_' + self.get_instance_name() # create HomeMatic object try: self.hm = HMConnection( interface_id="myserver", autostart=False, eventcallback=self.eventcallback, systemcallback=self.systemcallback, remotes={self.hm_id: { "ip": self.host, "port": self.port }}) # remotes={self.hm_id:{"ip": self.host, "port": self.port}, self.hmip_id:{"ip": self.host, "port": self.port_hmip}}) except: self.logger.error("Unable to create HomeMatic object") self._init_complete = False return # build dict identifier for the homematicIP ccu of this plugin instance if self.port_hmip != 0: self.hmip_id = 'ip' if self.get_instance_name() != '': self.hmip_id += '_' + self.get_instance_name() # create HomeMaticIP object try: self.hmip = HMConnection(interface_id="myserver_ip", autostart=False, eventcallback=self.eventcallback, systemcallback=self.systemcallback, remotes={ self.hmip_id: { "ip": self.host, "port": self.port_hmip } }) except: self.logger.error("Unable to create HomeMaticIP object") # self._init_complete = False # return # set the name of the thread that got created by pyhomematic to something meaningfull self.hm._server.name = self.get_fullname() # start communication with HomeMatic ccu try: self.hm.start() self.connected = True except: self.logger.error( "Unable to start HomeMatic object - SmartHomeNG will be unable to terminate the thread vor this plugin (instance)" ) self.connected = False # self._init_complete = False # stop the thread that got created by initializing pyhomematic # self.hm.stop() # return # start communication with HomeMatic ccu try: self.hmip.start() except: self.logger.error("{}: Unable to start HomeMaticIP object".format( self.get_fullname())) if self.connected: # TO DO: sleep besser lösen! sleep(20) # self.logger.warning("Plugin '{}': self.hm.devices".format(self.hm.devices)) if self.hm.devices.get(self.hm_id, {}) == {}: self.logger.error("Connection to ccu failed") # self._init_complete = False # stop the thread that got created by initializing pyhomematic # self.hm.stop() # return self.hm_items = [] if not self.init_webinterface(): # self._init_complete = False pass return
def __init__(self, sh, *args, **kwargs): """ Initalizes the plugin. The parameters describe for this method are pulled from the entry in plugin.conf. """ from bin.smarthome import VERSION if '.'.join(VERSION.split('.', 2)[:2]) <= '1.5': self.logger = logging.getLogger(__name__) self.logger.debug("init {}".format(__name__)) self._sh = self.get_sh() # better than time.sleep() is to use an event for threading self.stopevent = threading.Event() # get the parameters for the plugin (as defined in metadata plugin.yaml): self.host = self.get_parameter_value('host') self.port = self.get_parameter_value('port') # init the Communication part which is a parent class we inherited from self.owbase = owbase.OwBase(self.host, self.port) # need to get a list of sensors with an alias self.read_alias_definitions() self._io_wait = self.get_parameter_value('io_wait') self._button_wait = self.get_parameter_value('button_wait') self._cycle = self.get_parameter_value('cycle') self.log_counter_cycle_time = self.get_parameter_value( 'log_counter_cycle_time') self._cycle_discovery = self.get_parameter_value('cycle_discovery') self.log_counter_cycle_discovery_time = self.get_parameter_value( 'log_counter_cycle_discovery_time') self.log_counter_io_loop_time = self.get_parameter_value( 'log_counter_io_loop_time') # Initialization code goes here self._buses = {} # buses reported by owserver self._sensors = { } # Temperature, Humidity, etc. populated in parse_item self._ios = {} # IO Sensors self._ibuttons = {} # iButtons populated in parse_item self._ibutton_buses = {} # found buses self._ibutton_masters = {} # all found iButton Master self._intruders = [] # any unknown sensors found self._discovered = False # set to True after first successful scan of attached owdevices self._last_discovery = [ ] # contains the latest results of discovery. If it does not change # the listing won't be processed again self._iButton_Strategy_set = False # Will be set to True as soon as first discovery is finished and iButtons and iButton Master are known """ self._sensors will contain something like {'28.16971B030000': {'T': {'item': Item: OneWire.Temperature_Multi, 'path': None}}, 'Huelsenfuehler': {'T': {'item': Item: OneWire.Temperature_Single, 'path': '/bus.0/Huelsenfuehler/temperature'}}, '26.E56727010000': {'L': {'item': Item: OneWire.brightness, 'path': None}}, '26.0D9930010000': {'H': {'item': Item: OneWire.humidity, 'path': '/bus.0/26.0D9930010000/HIH4000/humidity'}}} """ # give some info to the user via webinterface self.init_webinterface() self.logger.debug("init {} done".format(__name__)) self._init_complete = True