def createMessage(message, senderNum): if (message == "/rooms"): roomsavailable = [] allRooms = Room.GetAllRooms(); for oneRoom in allRooms: roomsInfo = AccessLog.GetLatestExitAccessLog(oneRoom.Id) if (roomsInfo != None): for x in roomsInfo: if ([x['Exit_time']][0] != None): roomsavailable.append([x['RoomName']][0]) if roomsavailable == []: roomsavailable.append("No Rooms Available") messageToSend = "Rooms Available \n" availableInString = '\n'.join(roomsavailable) messageToSend += availableInString sendMessage(messageToSend, senderNum) elif (message == "/help"): sendMessage("=====All Commands=====\n• /rooms - To see all available rooms\n• /snapshot - To get all IOT Sensor data of all rooms\n", senderNum) elif (message == "/snapshot"): messageToSend = "" roomsList = Room.GetAllRooms() for oneRoom in roomsList: roomInfo = EnviroInfo.GetLatestEnviroInfo(oneRoom.Id) imageUrl = f"{Config.aws_S3_endpoint}snapshot/{oneRoom.Id}.png" if (roomInfo is not None): roomMessage = f"=============\nRoom Name: {oneRoom.RoomName}\nLast Updated: {roomInfo['time']}\nTemperature: {roomInfo['temp']}°C" + f"\nHumidity: {roomInfo['humidity']}%\nLight: {roomInfo['light']}\n" + imageUrl + "\n" messageToSend += roomMessage # sendMessage(f"=====\nRoom Name: {oneRoom.RoomName}\nLast Updated: {roomInfo['time']}\nTemperature: {roomInfo['temp']}°C" + # f"\nHumidity: {roomInfo['humidity']}%\nLight: {roomInfo['light']}\n" + imageUrl, senderNum) sendMessage(messageToSend, senderNum) else: sendMessage("Unknown Command, Type /help for more information.", senderNum)
def removeRoomAPI(): if not IsAuthorised(): return "Not authorised", 401 Id = request.form['IotId'] if Id == None: return "Missing Data", 400 room = Room(Id=Id) if not room.TryRemove(): return "Failed to remove from Database", 401 return "removed"
def dashboardPage(): if IsAuthenticated() == True: return redirectIfNotLoginAndRender( 'dashboard.html', rooms=Room.GetAllRooms()) if session['IsAdmin'] else redirect( url_for('.publicDashBoardPage')) return redirect(url_for('.loginPage'))
def setLightStatusAPI(): if not IsAuthorised(): return "Not authorised", 401 RoomId = request.form.get("RoomId") Status = request.form.get("Status") room = Room.TryGetRoom(socket.gethostname()) if room == None or room.Id != int(RoomId): return "Error, not current room", 401 return "success"
def addRoomAPI(): if not IsAuthorised(): return "Not authorised", 401 room = Room.ParseFromForm(request.form) if not room.IsValidForAdd(): return "Missing Data", 400 if room.TryAdd() == False: return "Failed to add into Database", 401 return "added"
def updateRoomAPI(): if not IsAuthorised(): return "Not authorised", 401 room = Room.ParseFromForm(request.form) if not room.IsValidForUpdate(): return "Missing Data", 400 if room.TryUpdateDb() == False: return "Failed to update Database", 401 return "Updated"
async def snapshot(ctx): roomsList = Room.GetAllRooms() await ctx.channel.send(f"Requested by {ctx.author.mention}") for oneRoom in roomsList: roomInfo = EnviroInfo.GetLatestEnviroInfo(oneRoom.Id) imageUrl = f"{Config.aws_S3_endpoint}snapshot/{oneRoom.Id}.png" if (roomInfo is not None): await ctx.channel.send(f"====================================\nRoom Name: {oneRoom.RoomName}\nLast Updated: {roomInfo['time']}\nTemperature: {roomInfo['temp']}°C" + f"\nHumidity: {roomInfo['humidity']}%\nLight: {roomInfo['light']}\n" + imageUrl) await ctx.message.delete()
def __init__(self, **kwargs): self.Id = int(kwargs.get('Id', 0)) self.RoomId = int(kwargs.get('RoomId', 0)) self.UserId = kwargs.get('UserId', "") self.Time = kwargs.get('Time', time.strftime('%Y-%m-%d %H:%M:%S')) self.ExitTime = kwargs.get('ExitTime', "") self.IsValid = kwargs.get('IsValid', False) if self.RoomId > 0: self.room = Room.TryGetRoomById(self.RoomId) else: self.room = None
def getAvgRoomTempsAPI(roomId): if not IsAuthorised(): return "Not authorised", 401 room = Room.TryGetRoomById(roomId) if room == None: return "Error", 400 result = { "RoomName": room.RoomName, "data": EnviroInfo.GetAvgEnviroInfoByDay(room.Id) } return jsonify(result)
def __init__(self, **kwargs): self.Id = int(kwargs.get('Id', 0)) self.RoomId = int(kwargs.get('RoomId', 0)) self.UserId = int(kwargs.get('UserId', 0)) if self.RoomId > 0: self.room = Room.TryGetRoomById(self.RoomId) else: self.room = None if self.UserId > 0: self.user = User.TryGetUserById(self.UserId) else: self.user = None
async def rooms(ctx): currentDT = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p") roomsavailable = [] allRooms = Room.GetAllRooms(); for oneRoom in allRooms: roomsInfo = AccessLog.GetLatestExitAccessLog(oneRoom.Id) if (roomsInfo != None): for x in roomsInfo: if ([x['Exit_time']][0] != None): roomsavailable.append([x['RoomName']]) if roomsavailable == []: roomsavailable.append("No Rooms Available") await ctx.channel.send(f"=====================\nTime Requested: {currentDT} \nRequested By: {ctx.author.mention} \nRooms available: {roomsavailable}\n=====================") #delete command message await ctx.message.delete()
from Shared.Room import Room from LCDScroller import LCDScroller from time import sleep import RPi.GPIO as GPIO import MFRC522 import signal from Shared.User import User from Shared.AccessRight import AccessRight from Shared.AccessLog import AccessLog from MotionDetection import MotionDetection from Shared.Database import db import thread from AwsIot import AwsIot import json room = Room.TryGetRoom(socket.gethostname()) access_right = None access_user = None access_log = None mfrc522 = MFRC522.MFRC522() lcd = LCDScroller() if room == None: print("Failed to get room") exit() awsiot = AwsIot('room' + str(room.Id),2) awsiot_topic = 'rooms/' + str(room.Id) + '/LightSwitch' def OnMotionEvent(VideoPath): global awsiot
def roomAccessRightsPage(): return redirectIfNotLoginAndRender('room_access_rights.html', users=User.GetUsers(), rooms=Room.GetAllRooms())
def publicDashBoardPage(): return redirectIfNotLoginAndRender( 'publicDashboard.html', user=User.TryGetUserById(session['UserId']), rooms=Room.GetAllRooms()) if not session['IsAdmin'] else redirect( url_for('.dashboardPage'))
def getRoomsAPI(): if not IsAuthorised(): return "Not authorised", 401 return jsonify(Room.GetAllRoomsJSON())
def manageApprovalsPage(): return redirectIfNotLoginAndRender('manage_approvals.html', users=User.GetUsers(), rooms=Room.GetAllRooms())