From 95dcfbd40bd62709fbbf4076aa4585889d4e7c15 Mon Sep 17 00:00:00 2001 From: msinn Date: Thu, 14 Sep 2023 11:36:52 +0200 Subject: [PATCH] mailsend: Fixed bug when called from onchange expression. --- mailsend/__init__.py | 16 ++++++---------- mailsend/plugin.yaml | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/mailsend/__init__.py b/mailsend/__init__.py index aad43c736..a63f61377 100755 --- a/mailsend/__init__.py +++ b/mailsend/__init__.py @@ -35,16 +35,12 @@ class SMTP(SmartPlugin): - PLUGIN_VERSION = "1.4.1" + PLUGIN_VERSION = "1.4.2" def __init__(self, sh): # Call init code of parent class (SmartPlugin) super().__init__() - from bin.smarthome import VERSION - if '.'.join(VERSION.split('.', 2)[:2]) <= '1.5': - self.logger = logging.getLogger(__name__) - self._tls = self.get_parameter_value('tls') self._host = self.get_parameter_value('host') self._port = self.get_parameter_value('port') @@ -53,14 +49,14 @@ def __init__(self, sh): self._password = self.get_parameter_value('password') - def send(self, to, sub, msg): - self.__call__(to, sub, msg) + def send(self, to, sub, msg, caller=None, source=None): + self.__call__(to, sub, msg, caller, source) - def __call__(self, to, sub, msg): + def __call__(self, to, sub, msg, caller=None, source=None): try: smtp = self._connect() except Exception as e: - self.logger.warning("Could not connect to {0}: {1}".format(self._host, e)) + self.logger.warning(f"Could not connect to {self._host}: {e}") return try: msg = MIMEText(msg, 'plain', 'utf-8') @@ -73,7 +69,7 @@ def __call__(self, to, sub, msg): self.logger.debug("email prepared for sending") smtp.sendmail(self._from, to, msg.as_string()) except Exception as e: - self.logger.warning("Could not send message {} to {}: {}".format(sub, to, e)) + self.logger.warning(f"Could not send message {sub} to {to} (caller={caller}): {e}") finally: try: smtp.quit() diff --git a/mailsend/plugin.yaml b/mailsend/plugin.yaml index 2c879edca..b14af5e64 100755 --- a/mailsend/plugin.yaml +++ b/mailsend/plugin.yaml @@ -12,7 +12,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.4.1 # Plugin version + version: 1.4.2 # Plugin version sh_minversion: 1.4 # 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