diff --git a/smlx/__init__.py b/smlx/__init__.py index 174add5fc..76717ae47 100755 --- a/smlx/__init__.py +++ b/smlx/__init__.py @@ -2,7 +2,7 @@ # vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab ######################################################################### # Copyright 2012-2014 Oliver Hinckel github@ollisnet.de -# Copyright 2018-2022 Bernd Meiners Bernd.Meiners@mail.de +# Copyright 2018-2024 Bernd Meiners Bernd.Meiners@mail.de # Copyright 2022- Michael Wenzel wenzel_michael@web.de ######################################################################### # @@ -55,7 +55,7 @@ class Smlx(SmartPlugin): the update functions for the items """ - PLUGIN_VERSION = '1.1.7' + PLUGIN_VERSION = '1.1.8' # Lookup table for smartmeter names to data format _devices = { @@ -70,7 +70,33 @@ def __init__(self, sh): # Call init code of parent class (SmartPlugin) super().__init__() + #load parameters from config + self.load_parameters() + + self.connected = False + self.alive = False + self._serial = None + self._sock = None + self._target = None + self._dataoffset = 0 + self._items = {} + self._item_dict = {} + self._lock = threading.Lock() + self._parse_lock = threading.Lock() + + self.init_webinterface(WebInterface) + + def load_parameters(self): self.cycle = self.get_parameter_value('cycle') + if self.cycle == 0: + self.cycle = None + + self.crontab = self.get_parameter_value('crontab') # the more complex way to specify the device query frequency + if self.crontab == '': + self.crontab = None + if not (self.cycle or self.crontab): + self.logger.error(f"{self.get_fullname()}: no update cycle or crontab set. The smartmeter will not be queried automatically") + self.host = self.get_parameter_value('host') # None self.port = self.get_parameter_value('port') # 0 self.serialport = self.get_parameter_value('serialport') # None @@ -87,17 +113,6 @@ def __init__(self, sh): self.xor_out = self.get_parameter_value('xor_out') # 0xffff self.swap_crc_bytes = self.get_parameter_value('swap_crc_bytes') # False - self.connected = False - self.alive = False - self._serial = None - self._sock = None - self._target = None - self._dataoffset = 0 - self._items = {} - self._item_dict = {} - self._lock = threading.Lock() - self._parse_lock = threading.Lock() - if device in self._devices: device = self._devices[device] @@ -111,24 +126,32 @@ def __init__(self, sh): self.logger.debug(f"Using CRC params poly={self.poly}, reflect_in={self.reflect_in}, xor_in={self.xor_in}, reflect_out={self.reflect_out}, xor_out={self.xor_out}, swap_crc_bytes={self.swap_crc_bytes}") - self.init_webinterface(WebInterface) def run(self): """ Run method for the plugin """ self.logger.debug(f"Plugin '{self.get_fullname()}': run method called") + self.load_parameters() + self.alive = True + # Setup scheduler for device poll loop - self.scheduler_add(SML_SCHEDULER_NAME, self.poll_device, cycle=self.cycle) + if self.cycle or self.crontab: + if self.crontab: + next = None # adhere to the crontab + else: + # no crontab given so we might just query immediately + next = shtime.now() + self.scheduler_add(self.get_fullname(), self.poll_device, prio=5, cycle=self.cycle, cron=self.crontab, next=next) + self.logger.debug(f"Plugin '{self.get_fullname()}': run method finished") - self.alive = True def stop(self): """ Stop method for the plugin """ self.logger.debug(f"Plugin '{self.get_fullname()}': stop method called") - self.scheduler_remove(SML_SCHEDULER_NAME) + self.scheduler_remove(self.get_fullname()) self.alive = False self.disconnect() @@ -168,7 +191,7 @@ def update_item(self, item, caller=None, source=None, dest=None): :param source: if given it represents the source :param dest: if given it represents the dest """ - if caller != self.get_shortname(): + if caller != self.get_fullname(): # Code to execute, only if the item has not been changed by this plugin: self.logger.info("Update item: {}, item has been changed outside this plugin".format(item.id())) pass diff --git a/smlx/plugin.yaml b/smlx/plugin.yaml index 6767ef5b5..b6e41e772 100755 --- a/smlx/plugin.yaml +++ b/smlx/plugin.yaml @@ -12,7 +12,7 @@ plugin: documentation: https://www.smarthomeng.de/developer/plugins/smlx/user_doc.html support: https://knx-user-forum.de/forum/supportforen/smarthome-py/39119-sml-plugin-datenblock-größenfehler restartable: True - version: 1.1.7 # Plugin version + version: 1.1.8 # Plugin version sh_minversion: 1.4.2 # minimum shNG version to use this plugin # sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest) # py_minversion: 3.6 # minimum Python version to use for this plugin @@ -53,10 +53,17 @@ parameters: cycle: type: int + valid_min: 0 default: 60 description: - de: 'Zeitlicher Abstand in Sekunden zwischen zwei Abfragen des Smartmeters' - en: 'Time in seconds between two queries of Smartmeter' + de: 'Zeitlicher Abstand in Sekunden zwischen zwei Abfragen des Smartmeters, wird 0 angegeben so wird der Smartmeter über cycle nicht abgefragt' + en: 'Time in seconds between two queries of Smartmeter- If given 0 the smartmeter will not be queried by means of cycle' + + crontab: + type: str + description: + de: 'Abfragen des Smartmeters mit Festlegung via Crontab' + en: 'Queries of smartmeter by means of a crontab' device: type: str diff --git a/smlx/webif/templates/index.html b/smlx/webif/templates/index.html index d23a22975..21b0811dd 100755 --- a/smlx/webif/templates/index.html +++ b/smlx/webif/templates/index.html @@ -116,8 +116,8 @@