Skip to content

Commit

Permalink
Merge pull request #39 from FlyingDiver/master
Browse files Browse the repository at this point in the history
Fixed first time run error
  • Loading branch information
FlyingDiver authored Oct 12, 2023
2 parents 9df6110 + 917b87f commit e9af5bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Pushover.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>2022.0.0</string>
<string>2022.0.1</string>
<key>ServerApiVersion</key>
<string>3.0</string>
<key>IwsApiVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Label>API Token:</Label>
</Field>
<Field id="hlpApiToken" type="label" fontSize="mini" alignWithControl="true">
<Label>Required, can be created at https://pushover.net/apps/clone/indigo_domotics</Label>
<Label>Required, can be created at https://pushover.net/apps/build</Label>
</Field>
<Field id="userKey" type="textfield" default="">
<Label>User Key:</Label>
Expand Down
26 changes: 21 additions & 5 deletions Pushover.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
self.logLevel = int(pluginPrefs.get("logLevel", logging.INFO))
self.indigo_log_handler.setLevel(self.logLevel)
self.logger.debug(f"logLevel = {self.logLevel}")

self.apiToken = None
self.sounds = None

def startup(self):
self.logger.debug(f"startup called")

self.apiToken = pluginPrefs.get('apiToken', None)
if not self.apiToken:
self.logger.warning(f"PI Token not configured")

def startup(self):
self.logger.debug(f"startup called")
try:
r = requests.get(f"https://api.pushover.net/1/sounds.json?token={self.apiToken}")
customdecoder = json.JSONDecoder(object_hook=OrderedDict)
rdict = customdecoder.decode(r.text)
custom_decoder = json.JSONDecoder(object_hook=OrderedDict)
rdict = custom_decoder.decode(r.text)
self.sounds = rdict['sounds']
except Exception as err:
self.logger.warning(f"Error getting alert sounds list: {err}")
Expand Down Expand Up @@ -156,12 +156,28 @@ def cancel(self, pluginAction):
# ConfigUI methods
########################################

def validatePrefsConfigUi(self, valuesDict):
self.logger.debug(u"validatePrefsConfigUi called")
errorMsgDict = indigo.Dict()

if valuesDict["apiToken"] == "":
errorMsgDict['apiToken'] = "API Token is required"

if len(errorMsgDict) > 0:
return False, valuesDict, errorMsgDict
return True, valuesDict

def closedPrefsConfigUi(self, valuesDict, userCancelled):
self.logger.debug(u"closedPrefsConfigUi called")
if not userCancelled:
self.logLevel = int(valuesDict.get("logLevel", logging.INFO))
self.indigo_log_handler.setLevel(self.logLevel)
self.logger.debug(f"logLevel = {self.logLevel}")

self.apiToken = valuesDict.get('apiToken', None)
if not self.apiToken:
self.logger.error(f"API Token not configured")

# doesn't do anything, just needed to force other menus to dynamically refresh
@staticmethod
def menuChanged(valuesDict, typeId, devId):
Expand Down

0 comments on commit e9af5bd

Please sign in to comment.