Skip to content

Instantly share code, notes, and snippets.

@jessejoe
Last active August 29, 2015 14:03
Show Gist options
  • Save jessejoe/e731f810e3c285dc2474 to your computer and use it in GitHub Desktop.
Save jessejoe/e731f810e3c285dc2474 to your computer and use it in GitHub Desktop.
Add a simple on-then-off function for ouimeaux with retries: https://github.com/iancmcc/ouimeaux/issues/31
15:35:45 j@i7:/Library/Python/2.7/site-packages$ diff ouimeaux/server/__init__.py ouimeaux/server/__init__.py.bak
79c79
< if action not in ('on', 'off', 'toggle', 'on_off'):
---
> if action not in ('on', 'off', 'toggle'):
14:44:54 jarzynka@i7:/Library/Python/2.7/site-packages$ diff ouimeaux/device/switch.py ouimeaux/device/switch.py.bak
2,3c2
< import logging
< import time
---
>
35,68d33
< def on_off(self):
< """
< Turn the device on (unlock door) then back off (re-lock door)
< """
< log = logging.getLogger(__name__)
<
< # Unlock logic
< attempt = 1
< if (self.get_state() != 1):
< while (self.get_state() != 1) and (attempt <= 3):
< log.debug('Door is locked, trying to unlock, attempt #%s' % attempt)
< attempt += 1
< self.on()
< if self.get_state() == 1:
< log.debug('Successfully unlocked!')
< time.sleep(5)
< else:
< log.debug('Unable to unlock door!')
< else:
< log.debug('Door is already unlocked, will not try to unlock')
<
< # Lock logic
< attempt = 1
< if self.get_state() != 0:
< while (self.get_state() != 0) and (attempt <= 3):
< log.debug('Door is unlocked, trying to lock, attempt #%s' % attempt)
< attempt += 1
< self.off()
< if (self.get_state() == 0):
< log.debug('Successfully locked!')
< else:
< log.debug('Unable to lock door!')
< else:
< log.debug('Door is already locked, will not try to lock')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment