|
|
@ -52,7 +52,7 @@ class ConvertUPS(Serial): |
|
|
|
if self.shutdownTimeout is None: |
|
|
|
self.shutdownTimeout = float(cfg['shutdown'].get('timeout', 3600)) |
|
|
|
if self.shutdownCommand is None: |
|
|
|
self.shutdownCommand = shlex.split(cfg['shutdown'].get('command', '/sbin/shutdown -h now')) |
|
|
|
self.shutdownCommand = shlex.split(cfg['shutdown'].get('command', '/sbin/shutdown -h +2')) |
|
|
|
except OSError: |
|
|
|
if debug: |
|
|
|
print('Could not read config file %s.' % configfile) |
|
|
@ -68,7 +68,7 @@ class ConvertUPS(Serial): |
|
|
|
if self.shutdownTimeout is None: |
|
|
|
self.shutdownTimeout = 3600.0 |
|
|
|
if self.shutdownCommand is None: |
|
|
|
self.shutdownCommand = shlex.split('/sbin/shutdown -h now') |
|
|
|
self.shutdownCommand = shlex.split('/sbin/shutdown -h +2') |
|
|
|
|
|
|
|
if self.debug: |
|
|
|
print('Configuration:') |
|
|
@ -189,12 +189,12 @@ class ConvertUPS(Serial): |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
#try: |
|
|
|
ups = ConvertUPS() |
|
|
|
#except: |
|
|
|
# print('Error: Could not open UPS serial connection.') |
|
|
|
# print('\tCheck the config file!') |
|
|
|
# sys.exit(1) |
|
|
|
try: |
|
|
|
ups = ConvertUPS() |
|
|
|
except: |
|
|
|
print('Error: Could not open UPS serial connection.') |
|
|
|
print('\tCheck the config file!') |
|
|
|
sys.exit(1) |
|
|
|
|
|
|
|
if not ups.upsInit(): |
|
|
|
print('Error: Could not initialize UPS.') |
|
|
@ -204,7 +204,9 @@ if __name__ == "__main__": |
|
|
|
(toggled, onBatt) = ups.powerToggled() |
|
|
|
if toggled: |
|
|
|
if onBatt: |
|
|
|
print('UPS AC power loss. Starting shutdown timer.') |
|
|
|
ups.startShutdownTimer() |
|
|
|
if not onBatt: |
|
|
|
print('UPS AC power restored. Cancelling shutdown timer.') |
|
|
|
ups.cancelShutdownTimer() |
|
|
|
sleep(ups.interval) |