Skip to content

Commit

Permalink
nut: fixed bug in IP port handling; improved plugin shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
aschwith committed Nov 25, 2023
1 parent 3ac1457 commit 62cd27d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions nut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()

Expand All @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion nut/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 62cd27d

Please sign in to comment.