fix
This commit is contained in:
@@ -77,4 +77,41 @@ class LEDStrip:
|
||||
|
||||
@staticmethod
|
||||
def handle_data(device, action, data):
|
||||
pass
|
||||
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 }})
|
Reference in New Issue
Block a user