This commit is contained in:
Nick Leeman 2020-07-07 19:04:43 +02:00
parent e14097c329
commit 22385cdef3
5 changed files with 10 additions and 10 deletions

View File

@ -92,7 +92,7 @@ class LEDStrip:
return return
# Check if light levels are low enough to turn on light # Check if light levels are low enough to turn on light
collectionLight = EchoDB.EchoDB.database['LightLog'] collectionLight = EchoDB.EchoDB.database['LightLogs']
data = collectionLight.find().sort([('timestamp', -1)]).limit(1) data = collectionLight.find().sort([('timestamp', -1)]).limit(1)
if data[0]['light_amount'] > 20: if data[0]['light_amount'] > 20:
return; return;

View File

@ -21,7 +21,7 @@ class Sensor:
return {'status': 'success', 'message': actionData['message']}, 200 return {'status': 'success', 'message': actionData['message']}, 200
if action == "get_climate_data": if action == "get_climate_data":
collection = EchoDB.EchoDB.database['ClimateLogs'] collection = EchoDB.EchoDB.database['ClimateLogss']
data = collection.find().sort([('timestamp', -1)]).limit(1) data = collection.find().sort([('timestamp', -1)]).limit(1)
data_json = json.loads(json_util.dumps(data)) data_json = json.loads(json_util.dumps(data))
return {'status': 'success', 'message': actionData['message'], 'data': data_json}, 200 return {'status': 'success', 'message': actionData['message'], 'data': data_json}, 200
@ -35,7 +35,7 @@ class Sensor:
return {'status': 'success', 'message': actionData['message']}, 200 return {'status': 'success', 'message': actionData['message']}, 200
if action == "get_light_data": if action == "get_light_data":
collection = EchoDB.EchoDB.database['LightLog'] collection = EchoDB.EchoDB.database['LightLogs']
data = collection.find().sort([('timestamp', -1)]).limit(1) data = collection.find().sort([('timestamp', -1)]).limit(1)
data_json = json.loads(json_util.dumps(data)) data_json = json.loads(json_util.dumps(data))
return {'status': 'success', 'message': actionData['message'], 'data': data_json}, 200 return {'status': 'success', 'message': actionData['message'], 'data': data_json}, 200
@ -57,7 +57,7 @@ class Sensor:
# #
if action == 'climate_data': if action == 'climate_data':
collection = EchoDB.EchoDB.database['ClimateLogs'] collection = EchoDB.EchoDB.database['ClimateLogss']
climate_data = data[2].split(',') climate_data = data[2].split(',')
logData = { logData = {
@ -74,7 +74,7 @@ class Sensor:
# #
if action == 'light_data': if action == 'light_data':
collection = EchoDB.EchoDB.database['LightLog'] collection = EchoDB.EchoDB.database['LightLogs']
lightAmount = data[2] lightAmount = data[2]
logData = { logData = {

View File

@ -52,7 +52,7 @@ class Switch:
return return
# Check if light levels are low enough to turn on light # Check if light levels are low enough to turn on light
collectionLight = EchoDB.EchoDB.database['LightLog'] collectionLight = EchoDB.EchoDB.database['LightLogs']
data = collectionLight.find().sort([('timestamp', -1)]).limit(1) data = collectionLight.find().sort([('timestamp', -1)]).limit(1)
if data[0]['light_amount'] > 250: if data[0]['light_amount'] > 250:
return; return;

View File

@ -17,6 +17,6 @@ class EchoDB:
database = mongo_client['Echo'] database = mongo_client['Echo']
# Create Indexes # Create Indexes
database['MovementLog'].create_index("timestamp", expireAfterSeconds=10) database['MovementLogs'].create_index("timestamp", expireAfterSeconds=3600)
database['ClimateLog'].create_index("timestamp", expireAfterSeconds=10) database['ClimateLogs'].create_index("timestamp", expireAfterSeconds=3600)
database['LightLog'].create_index("timestamp", expireAfterSeconds=10) database['LightLogs'].create_index("timestamp", expireAfterSeconds=3600)

View File

@ -26,7 +26,7 @@ class EchoScheduler:
schedule.every(1).minute.do(EchoScheduler.checkAutomaticShutdown) schedule.every(1).minute.do(EchoScheduler.checkAutomaticShutdown)
schedule.every(1).minute.do(EchoScheduler.checkAutomaticBlinds) schedule.every(1).minute.do(EchoScheduler.checkAutomaticBlinds)
# collection_delete = EchoDB.EchoDB.database['ClimateLogs'] # collection_delete = EchoDB.EchoDB.database['ClimateLogss']
# collection_delete.remove({}) # collection_delete.remove({})
while True: while True: