Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Updated logging to Indigo 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jheddings committed Jan 7, 2018
1 parent 7c08a29 commit 354f3af
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Power Source.indigoPlugin/Contents/Info.plist
Expand Up @@ -6,7 +6,7 @@
<key>CFBundleDisplayName</key><string>Power Source</string>
<key>PluginVersion</key><string>0.2.1</string>
<key>CFBundleIdentifier</key><string>com.heddings.indigo.pmset</string>
<key>ServerApiVersion</key><string>1.9</string>
<key>ServerApiVersion</key><string>2.0</string>
<key>CFBundleVersion</key><string>1.0.0</string>

<key>CFBundleURLTypes</key>
Expand Down
Expand Up @@ -4,8 +4,4 @@
<Name>Refresh Device Status</Name>
<CallbackMethod>refreshDeviceStatus</CallbackMethod>
</MenuItem>
<MenuItem id="toggleDebugging">
<Name>Toggle Debugging</Name>
<CallbackMethod>toggleDebugging</CallbackMethod>
</MenuItem>
</MenuItems>
13 changes: 10 additions & 3 deletions Power Source.indigoPlugin/Contents/Server Plugin/PluginConfig.xml
Expand Up @@ -3,7 +3,7 @@
<SupportURL>https://github.com/jheddings/indigo-pmset</SupportURL>

<Field type="menu" id="updateInterval" defaultValue="5">
<Label>Update Interval:</Label>
<Label>Update Interval:</Label>
<List>
<Option value="1">1 Minute</Option>
<Option value="2">2 Minutes</Option>
Expand All @@ -17,7 +17,14 @@

<Field id="separator1" type="separator" />

<Field type="checkbox" id="debug">
<Label>Enable debugging:</Label>
<Field id="logLevel" type="menu" defaultValue="20">
<Label>Event Logging Level:</Label>
<List>
<Option value="10">Debugging Messages</Option>
<Option value="20">Informational Messages</Option>
<Option value="30">Warning Messages</Option>
<Option value="40">Error Messages</Option>
<Option value="50">Critical Errors Only</Option>
</List>
</Field>
</PluginConfig>
23 changes: 16 additions & 7 deletions Power Source.indigoPlugin/Contents/Server Plugin/plugin.py
Expand Up @@ -9,8 +9,7 @@ class Plugin(indigo.PluginBase):
#---------------------------------------------------------------------------
def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
indigo.PluginBase.__init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs)

self.debug = pluginPrefs.get('debug', False)
self._loadPluginPrefs(pluginPrefs)

#---------------------------------------------------------------------------
def __del__(self):
Expand All @@ -28,6 +27,7 @@ def deviceStopComm(self, device):
#---------------------------------------------------------------------------
def getBatteryNameList(self, filter='', valuesDict=None, typeId='', targetId=0):
self.logger.debug("getBatteryNameList valuesDict: %s" % str(valuesDict))

battNames = []
batts = pmset.getBatteryInfo()

Expand All @@ -44,11 +44,6 @@ def refreshDeviceStatus(self):
indigo.server.log('Updating device status.')
self._updateAllDevices()

#---------------------------------------------------------------------------
def toggleDebugging(self):
self.debug = not self.debug
self.pluginPrefs['debug'] = self.debug

#---------------------------------------------------------------------------
def runConcurrentThread(self):
try:
Expand All @@ -59,8 +54,22 @@ def runConcurrentThread(self):
except self.StopThread:
pass

#---------------------------------------------------------------------------
def _loadPluginPrefs(self, values):
logLevelTxt = values.get('logLevel', None)

if logLevelTxt is None:
self.logLevel = 20
else:
logLevel = int(logLevelTxt)
self.logLevel = logLevel

self.indigo_log_handler.setLevel(self.logLevel)

#---------------------------------------------------------------------------
def _runLoopStep(self):
# TODO pick updateInterval based on power failure

# devices are updated when added, so we'll start with a sleep
updateInterval = int(self.pluginPrefs.get('updateInterval', 5))
self.logger.debug('Next update in %d minutes' % updateInterval)
Expand Down

0 comments on commit 354f3af

Please sign in to comment.