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

Commit

Permalink
Only track batteries for critical update interval
Browse files Browse the repository at this point in the history
  • Loading branch information
jheddings committed Mar 10, 2018
1 parent d6d75b3 commit 6cfb134
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 6 additions & 7 deletions Power Source.indigoPlugin/Contents/Server Plugin/plugin.py
Expand Up @@ -3,6 +3,10 @@
import time
import pmset

# TODO track state changes and only warn on transitions:
# e.g. "battery level critical" -> "battery level normal"
# e.g. "external power lost" -> "external power restored"

################################################################################
class Plugin(indigo.PluginBase):

Expand Down Expand Up @@ -81,9 +85,8 @@ def _getCurrentUpdateInterval(self):

# TODO it would be nice if we could just use the information collected
# during a device update; the issue would be that users won't always add
# the power supply to their list of devices - so we have to call it here
# all batteries to their list of devices - so we have to call it here
batts = pmset.getBatteryInfo()
power = pmset.getCurrentPowerInfo()

# XXX maybe we only care about critical device states if users add them?

Expand All @@ -92,13 +95,9 @@ def _getCurrentUpdateInterval(self):

for batt in batts:
if batt.level <= critThresh:
self.logger.debug(u'Critical battery level: %s', batt.name)
self.logger.warn(u'Critical battery level: %s', batt.name)
isCritical = True

if not power.isExternal:
self.logger.debug(u'Critical power supply: %s', power.source)
isCritical = True

interval = 0

if isCritical:
Expand Down
7 changes: 3 additions & 4 deletions README.md
Expand Up @@ -11,11 +11,10 @@ You can run the command `pmset -g batt` to see the data used by this plugin.
Update intervals in the plugin config are used to define how frequently power information
should be collected.

The plugin will update device states depending on the current power status. If the plugin
determines that external power is on and all batteries are above a critical monitoring
threshold, the "standard update interval" will be used. If external power is down or any
The plugin will update device states depending on the current power status. If any
batteries are below the critical threshold, the plugin will use the "critical update
interval" to refresh device states.
interval" to refresh device states. Otherwise, the "standard update interval" will be
used.

## Devices

Expand Down

0 comments on commit 6cfb134

Please sign in to comment.