Browse Source

Remove dependency on scheduler

master
Pete Shadbolt 6 years ago
parent
commit
e5a08d3551
2 changed files with 24 additions and 22 deletions
  1. +1
    -1
      README.md
  2. +23
    -21
      xmas.py

+ 1
- 1
README.md View File

@@ -1,6 +1,6 @@
# Christmas tree

Scheduler for our christmas tree lights. Uses PiFace and [schedule](https://github.com/dbader/schedule).
Scheduler for our christmas tree lights. Uses [PiFace](http://www.piface.org.uk/).

Use `tmux` or `supervisor` to run `xmas.py`



+ 23
- 21
xmas.py View File

@@ -1,8 +1,11 @@
import schedule
import time
import datetime
import pifacedigitalio as p

# Configures interval
START = datetime.time(17, 0, 0)
END = datetime.time(23, 59, 0)

TREE = """
* ,
_/^\_
@@ -20,9 +23,9 @@ TREE = """
* /`,@ ;+& () o*`;-';\ *
(`""--.,_0 +% @' &()\ *
/-.,_ ``''--....-'`) *
* /@%;o`:;'--,.__ __.'\
* /@%;o`:;'--,.__ __.'\
;*,&(); @ % &^;~`"`o;@(); *
/(); o^~; & ().o@*&`;&%O\
/(); o^~; & ().o@*&`;&%O\
jgs `"="==""==,,,.,="=="==="`
__.----.(\-''#####---...___...-----._
'` \)_`'''''`
@@ -31,23 +34,31 @@ TREE = """
`'''` `
"""

START = datetime.time(17, 0, 0)
END = datetime.time(23, 59, 0)

def timestamp():
""" Get a timestamp """
return datetime.datetime.now()


def turn_on():
""" Turn on the christmas tree """
print("{} ON".format(timestamp()))
p.digital_write(0, 1)
p.digital_write(0, 1)


def turn_off():
""" Turn off the christmas tree """
print("{} OFF".format(timestamp()))
p.digital_write(0, 0)
p.digital_write(0, 0)


def update():
""" Updates the state """
now = datetime.datetime.now().time()
if START <= now <= END:
turn_on()
else:
turn_off()


def check_connectivity():
@@ -60,12 +71,6 @@ def check_connectivity():
time.sleep(2)


# Turn on if we are in the correct interval
now = datetime.datetime.now().time()
if START <= now <= END:
turn_on()


if __name__ == "__main__":
# Connect to PiFace
print(TREE)
@@ -77,13 +82,10 @@ if __name__ == "__main__":
# Message
print()
print("Starting scheduler:")
print("Xmas enabled between {} and {}.".format(START.strftime("%H:%M"), END.strftime("%H:%M")))

# Set up the schedule
schedule.every().day.at(START.strftime("%H:%M")).do(turn_on)
schedule.every().day.at(END.strftime("%H:%M")).do(turn_off)
print("Xmas enabled between {} and {}.".format(
START.strftime("%H:%M"), END.strftime("%H:%M")))

# Run the event loop
while(True):
schedule.run_pending()
time.sleep(1)
while (True):
update()
time.sleep(60)

Loading…
Cancel
Save