From 62cd27dadac6401fb9e62910a90f3155f415e4cd Mon Sep 17 00:00:00 2001 From: aschwith Date: Sat, 25 Nov 2023 10:38:40 +0100 Subject: [PATCH] nut: fixed bug in IP port handling; improved plugin shutdown --- nut/__init__.py | 10 ++++++---- nut/plugin.yaml | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nut/__init__.py b/nut/__init__.py index 512c7c3f3..9de84e70b 100755 --- a/nut/__init__.py +++ b/nut/__init__.py @@ -22,7 +22,7 @@ from lib.model.smartplugin import SmartPlugin class NUT(SmartPlugin): - PLUGIN_VERSION = '1.3.2' + PLUGIN_VERSION = '1.3.3' ALLOW_MULTIINSTANCE = True def __init__(self, sh): @@ -36,20 +36,21 @@ def __init__(self, sh): self._sh = sh self._cycle = self.get_parameter_value("cycle") self._host = self.get_parameter_value("host") - self._port = self.get_parameter_value("port ") + self._port = self.get_parameter_value("port") self._ups = self.get_parameter_value("ups") self._timeout = self.get_parameter_value("timeout") self._conn = None self._items = {} - self._sh.scheduler.add(__name__, self._read_ups, prio = 5, cycle = self._cycle) - self.logger.info('Init NUT Plugin') + self.logger.info('NUT Plugin initialized') def run(self): + self._sh.scheduler.add('poll_nut_device', self._read_ups, prio = 5, cycle = self._cycle) self.alive = True def stop(self): self.alive = False + self.scheduler_remove('poll_nut_device') if self._conn: self._conn.close() @@ -64,6 +65,7 @@ def update_item(self, item, caller=None, source=None, dest=None): return def _read_ups(self): + self.logger.debug(f"Trying to connect to {self._host} on port {self._port}") try: self._conn = telnetlib.Telnet(self._host, self._port) self._conn.write('LIST VAR {}\n'.format(self._ups).encode('ascii')) diff --git a/nut/plugin.yaml b/nut/plugin.yaml index f80f622ab..cfbffc1f0 100755 --- a/nut/plugin.yaml +++ b/nut/plugin.yaml @@ -21,7 +21,7 @@ plugin: # documentation: https://github.com/smarthomeNG/smarthome/wiki/CLI-Plugin # url of documentation (wiki) page # support: https://knx-user-forum.de/forum/supportforen/smarthome-py - version: 1.3.2 # Plugin version + version: 1.3.3 # Plugin version sh_minversion: 1.3 # minimum shNG version to use this plugin # sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest) multi_instance: True # plugin supports multi instance