Skip to content

Commit

Permalink
enocean: moved serial open from init to run method (to prepare plugin…
Browse files Browse the repository at this point in the history
… for restart)
  • Loading branch information
aschwith committed Oct 16, 2023
1 parent a5f995f commit 745e49a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
25 changes: 16 additions & 9 deletions enocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

class EnOcean(SmartPlugin):
ALLOW_MULTIINSTANCE = False
PLUGIN_VERSION = "1.3.11"
PLUGIN_VERSION = "1.4.0"


def __init__(self, sh):
Expand All @@ -187,13 +187,7 @@ def __init__(self, sh):
self.tx_id = int(tx_id, 16)
self.logger.info(f"Stick TX ID configured via plugin.conf to: {tx_id}")
self._log_unknown_msg = self.get_parameter_value("log_unknown_messages")
try:
self._tcm = serial.serial_for_url(self.port, 57600, timeout=1.5)
except Exception as e:
self._tcm = None
self._init_complete = False
self.logger.error(f"Exception occurred during serial open: {e}")
return
self._tcm = None
self._cmd_lock = threading.Lock()
self._response_lock = threading.Condition()
self._rx_items = {}
Expand Down Expand Up @@ -447,7 +441,18 @@ def run(self):
self.logger.debug("Call function << run >>")
self.alive = True
self.UTE_listen = False
#self.learn_id = 0

# open serial or serial2TCP device:
try:
self._tcm = serial.serial_for_url(self.port, 57600, timeout=1.5)
except Exception as e:
self._tcm = None
self._init_complete = False
self.logger.error(f"Exception occurred during serial open: {e}")
return
else:
self.logger.info(f"Serial port successfully opened at port {self.port}")

t = threading.Thread(target=self._startup, name="enocean-startup")
# if you need to create child threads, do not make them daemon = True!
# They will not shutdown properly. (It's a python bug)
Expand Down Expand Up @@ -508,6 +513,8 @@ def run(self):
self._tcm.close()
except Exception as e:
self.logger.error(f"Exception during tcm close occured: {e}")
else:
self.logger.info(f"Enocean serial device closed")
self.logger.info("Run method stopped")

def stop(self):
Expand Down
2 changes: 1 addition & 1 deletion enocean/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugin:
# url of the support thread
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/26542-featurewunsch-enocean-plugin/page13

version: 1.3.11 # Plugin version
version: 1.4.0 # 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: False # plugin supports multi instance
Expand Down
3 changes: 2 additions & 1 deletion enocean/user_doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Alternativ kann eines der oben erwähnten Serial-Geräte auch über das Netzwerk
57600n81,local
Für <PORT> und <DEVICE> sind die entsprechenden Werte einzufügen.

Konfiguration
=============

Expand Down Expand Up @@ -112,7 +113,7 @@ Zu b)

4. Nach dem Neustart das Logfile öffnen und nach dem Eintrag ``enocean: Base ID = 0xYYYYZZZZ`` suchen.

6. Übernahme dieser im Log angezeigten Base-ID in die plugin.yaml als Parameter `tx_id`.
5. Übernahme dieser im Log angezeigten Base-ID in die plugin.yaml als Parameter `tx_id`.


item.yaml
Expand Down

0 comments on commit 745e49a

Please sign in to comment.