From e997b18c72ac447e4b91a8e7693d4ba85f86e16c Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Sun, 22 May 2016 10:56:53 -0400 Subject: [PATCH] Use time.sleep instead of asyncio for py2 compat We are currently bound to Python 2 until scapy supports Python3 --- lights.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lights.py b/lights.py index 854f838..7f64a1d 100644 --- a/lights.py +++ b/lights.py @@ -1,7 +1,7 @@ -import asyncio -import logging -import datetime +# -*- coding: utf-8 -*- +from time import sleep import csv +import logging from phue import Bridge import pychromecast @@ -67,13 +67,17 @@ def change_light(bridge, color): light.xy = HUE_COLORS[color] def main(): - loop = asyncio.get_event_loop() start_video() bridge = setup_hue() - for time, color in HUE_CUES: - loop.call_later(time + DELAY, change_light, bridge, color) - loop.run_forever() - loop.close() + sleep(DELAY) + for index, (time, color) in enumerate(HUE_CUES): + change_light(bridge, color) + try: + next_time = HUE_CUES[index + 1][0] + except IndexError: # At last iteration + continue + delta = next_time - time + sleep(delta) if __name__ == "__main__": logging.basicConfig(