diff --git a/echo-master/echo_controller/__pycache__/controller.cpython-38.pyc b/echo-master/echo_controller/__pycache__/controller.cpython-38.pyc index 3bfb171..436189f 100644 Binary files a/echo-master/echo_controller/__pycache__/controller.cpython-38.pyc and b/echo-master/echo_controller/__pycache__/controller.cpython-38.pyc differ diff --git a/echo-master/echo_controller/__pycache__/led_strip.cpython-38.pyc b/echo-master/echo_controller/__pycache__/led_strip.cpython-38.pyc index 041afdb..05333f4 100644 Binary files a/echo-master/echo_controller/__pycache__/led_strip.cpython-38.pyc and b/echo-master/echo_controller/__pycache__/led_strip.cpython-38.pyc differ diff --git a/echo-master/echo_controller/led_strip.py b/echo-master/echo_controller/led_strip.py index c38a82d..78c0203 100644 --- a/echo-master/echo_controller/led_strip.py +++ b/echo-master/echo_controller/led_strip.py @@ -77,4 +77,41 @@ class LEDStrip: @staticmethod def handle_data(device, action, data): - pass \ No newline at end of file + pass + + @staticmethod + def handle_movement_led(): + mainBedLEDUUID = '34gr-54jf' + collection = EchoDB.EchoDB.database['Devices'] + + # Get Device (Main Light) + mainBedLEDDevice = collection.find_one({'uuid': mainBedLEDUUID}) + + # Check if automatic movement mode of main light is enabled, else do nothing + if mainBedLEDDevice['automatic_movement'] == False: + return + + # Check if light levels are low enough to turn on light + collectionLight = EchoDB.EchoDB.database['LightLog'] + data = collectionLight.find().sort([('timestamp', -1)]).limit(1) + if data[0]['light_amount'] > 20: + return; + + # Light is already on, update automatic shutdown. + if mainBedLEDDevice['status'] == "on": + now_time = datetime.datetime.now() + auto_shutdown = now_time + datetime.timedelta(minutes = 2) + collection.update_one({'uuid': mainBedLEDUUID}, {"$set": { 'automatic_shutdown': auto_shutdown }}) + return + + # Light is off, turn it on + + # Send Serial Command + EchoSerial.EchoSerial.send_commmand(mainBedLEDDevice, "set_color", mainBedLEDDevice['current_color']) + + # Auto shutdown time + now_time = datetime.datetime.now() + auto_shutdown = now_time + datetime.timedelta(minutes= 2) + + # Update Database + collection.update_one({'uuid': mainBedLEDUUID}, {"$set": { 'last_used': datetime.datetime.now(), 'status': "on", 'automatic_shutdown': auto_shutdown }}) \ No newline at end of file diff --git a/echo-master/echo_scheduler/__pycache__/scheduler.cpython-38.pyc b/echo-master/echo_scheduler/__pycache__/scheduler.cpython-38.pyc index fb660d9..a0db31e 100644 Binary files a/echo-master/echo_scheduler/__pycache__/scheduler.cpython-38.pyc and b/echo-master/echo_scheduler/__pycache__/scheduler.cpython-38.pyc differ diff --git a/echo-master/echo_scheduler/scheduler.py b/echo-master/echo_scheduler/scheduler.py index 377114d..1a40ba6 100644 --- a/echo-master/echo_scheduler/scheduler.py +++ b/echo-master/echo_scheduler/scheduler.py @@ -21,8 +21,8 @@ class EchoScheduler: print('Echo Scheduler Thread started!') # Schedule Tasks - schedule.every(2).minutes.do(EchoScheduler.getClimateData) - schedule.every(2).minutes.do(EchoScheduler.getLightData) + schedule.every(2.1).minutes.do(EchoScheduler.getClimateData) + schedule.every(2.2).minutes.do(EchoScheduler.getLightData) schedule.every(1).minute.do(EchoScheduler.checkAutomaticShutdown) schedule.every(1).minute.do(EchoScheduler.checkAutomaticBlinds) @@ -57,25 +57,53 @@ class EchoScheduler: @staticmethod def checkAutomaticShutdown(): - # Get Device collection = EchoDB.EchoDB.database['Devices'] - device = collection.find_one({'uuid': '9472-4f60'}) + + # + # Main Light + # + + # Get Device + device_main_light = collection.find_one({'uuid': '9472-4f60'}) # Check if light is on - if device['status'] == "off": + if device_main_light['status'] == "off": return; # Check if automatic movement is enabled - if device['automatic_movement'] == False: + if device_main_light['automatic_movement'] == False: return; # Check if date is current time is past device automatic shutdown time - automatic_shutdown_time = device['automatic_shutdown'] + automatic_shutdown_time = device_main_light['automatic_shutdown'] current_time = datetime.datetime.now() if current_time > automatic_shutdown_time: - Controller.Controller.handle_action(device, "off") - print('Scheduler Turned off light') + Controller.Controller.handle_action(device_main_light, "off") + print('Scheduler Turned off main light') + + # + # LED Light + # + + # Get Device + device_bed_led = collection.find_one({'uuid': '34gr-54jf'}) + + # Check if light is on + if device_bed_led['status'] == "off": + return; + + # Check if automatic movement is enabled + if device_bed_led['automatic_movement'] == False: + return; + + # Check if date is current time is past device automatic shutdown time + automatic_shutdown_time = device_bed_led['automatic_shutdown'] + current_time = datetime.datetime.now() + + if current_time > automatic_shutdown_time: + Controller.Controller.handle_action(device_bed_led, "off") + print('Scheduler Turned off main bed led light') @staticmethod def checkAutomaticBlinds():