Skip to content

Commit

Permalink
Merge pull request iancmcc#69 from jgstew/master
Browse files Browse the repository at this point in the history
Add a simple example to randomize toggling of switches
  • Loading branch information
iancmcc committed Feb 9, 2015
2 parents 174a65f + ecfc682 commit 12fd303
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ouimeaux/examples/Randomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import random
import datetime
import time
import ouimeaux
from ouimeaux.environment import Environment

# http:https://pydoc.net/Python/ouimeaux/0.7.3/ouimeaux.examples.watch/
if __name__ == "__main__":
print ""
print "WeMo Randomizer"
print "---------------"
env = Environment()
# TODO: run from 10am to 10pm
try:
env.start()
env.discover(100)
print env.list_switches()
print env.list_motions()
print "---------------"
while True:
# http:https://stackoverflow.com/questions/306400/how-do-i-randomly-select-an-item-from-a-list-using-python
switchRND = env.get_switch( random.choice( env.list_switches() ) )
print switchRND
switchRND.toggle()
env.wait(90)

except (KeyboardInterrupt, SystemExit):
print "---------------"
print "Goodbye!"
print "---------------"
# Turn off all switches
for switch in ( env.list_switches() ):
print "Turning Off: " + switch
env.get_switch( switch ).off()

0 comments on commit 12fd303

Please sign in to comment.