From de6c3600fa830375f556f737fa8bed5e1c9b8b3d Mon Sep 17 00:00:00 2001 From: joshua stein Date: Wed, 14 Feb 2018 15:46:17 -0600 Subject: [PATCH] Check for empty string values, not just null Also send result of Pushover API call to debug log --- Pushover.indigoPlugin/Contents/Info.plist | 2 +- .../Contents/Server Plugin/plugin.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Pushover.indigoPlugin/Contents/Info.plist b/Pushover.indigoPlugin/Contents/Info.plist index 4a16fd0..6896d44 100644 --- a/Pushover.indigoPlugin/Contents/Info.plist +++ b/Pushover.indigoPlugin/Contents/Info.plist @@ -3,7 +3,7 @@ PluginVersion - 1.2.1 + 1.2.2 ServerApiVersion 2.0 IwsApiVersion diff --git a/Pushover.indigoPlugin/Contents/Server Plugin/plugin.py b/Pushover.indigoPlugin/Contents/Server Plugin/plugin.py index 00aba7c..53928a7 100644 --- a/Pushover.indigoPlugin/Contents/Server Plugin/plugin.py +++ b/Pushover.indigoPlugin/Contents/Server Plugin/plugin.py @@ -18,6 +18,9 @@ def startup(self): def shutdown(self): self.debugLog(u"shutdown called") + def present(self, prop): + return (prop and prop.strip() != "") + # helper functions def prepareTextValue(self, strInput): @@ -47,22 +50,22 @@ def send(self, pluginAction): } #populate optional parameters - if pluginAction.props['msgDevice'] is not None: + if self.present(pluginAction.props['msgDevice']): params['device'] = pluginAction.props['msgDevice'].strip() - if pluginAction.props['msgUser'] is not None: + if self.present(pluginAction.props['msgUser']): params['user'] = pluginAction.props['msgUser'].strip() - if pluginAction.props['msgSound'] is not None: + if self.present(pluginAction.props['msgSound']): params['sound'] = pluginAction.props["msgSound"].strip() - if pluginAction.props['msgSupLinkTitle'] is not None: + if self.present(pluginAction.props['msgSupLinkTitle']): params['url_title'] = self.prepareTextValue(pluginAction.props['msgSupLinkTitle']) - if pluginAction.props['msgSupLinkUrl'] is not None: + if self.present(pluginAction.props['msgSupLinkUrl']): params['url'] = self.prepareTextValue(pluginAction.props['msgSupLinkUrl']) - if pluginAction.props['msgPriority'] is not None: + if self.present(pluginAction.props['msgPriority']): params['priority'] = pluginAction.props['msgPriority'] if params['priority'] == 2 or params['priority'] == "2": # Require Confirmation priority requires 2 additional params: @@ -72,8 +75,9 @@ def send(self, pluginAction): conn = httplib.HTTPSConnection("api.pushover.net:443") conn.request( "POST", - "/1/messages", + "/1/messages.json", urllib.urlencode(params), {"Content-type": "application/x-www-form-urlencoded"} ) + self.debugLog(u"Result: %s" % conn.getresponse().read()) conn.close()