Exemplo n.º 1
0
def editRuleInRoom(username=None, buildingName=None, roomName=None, ruleId=None):
    if request.method == "POST":

        sessionKey = validateInput(request.form["sessionKey"])
        userUuid = validateInput(request.form["userUuid"])

        priority = validateInput(request.form["priority"])
        ruleBody = validateInput(request.form["ruleBody"])

        groupId = request.form["groupId"] if "groupId" in request.form.keys() else None

        # authorUuid = userUuid
        editorUuid = userUuid

        try:
            session = SessionManager()
            session.checkSessionValidity(sessionKey, userUuid)
            buildingsManager = BuildingsManager()
            buildingsManager.checkUserBinding(buildingName, username)
            roomsManager = RoomsManager()

            return returnResult(
                roomsManager.editRule(
                    ruleId=ruleId,
                    priority=priority,
                    buildingName=buildingName,
                    roomName=roomName,
                    editorUuid=userUuid,
                    ruleBody=ruleBody,
                    groupId=groupId,
                )
            )
        except Exception as e:
            return returnError(e)
Exemplo n.º 2
0
def addRuleToGroup(username=None, buildingName=None, groupId=None):
    if request.method == "POST":

        sessionKey = validateInput(request.form["sessionKey"])
        userUuid = validateInput(request.form["userUuid"])

        priority = validateInput(request.form["priority"])
        ruleBody = validateInput(request.form["ruleBody"])

        authorUuid = userUuid

        try:
            session = SessionManager()
            session.checkSessionValidity(sessionKey, userUuid)
            buildingsManager = BuildingsManager()
            buildingsManager.checkUserBinding(buildingName, username)
            groupsManager = GroupsManager()

            return returnResult(
                groupsManager.addRule(
                    priority=priority,
                    buildingName=buildingName,
                    groupId=groupId,
                    authorUuid=authorUuid,
                    ruleBody=ruleBody,
                )
            )
        except Exception as e:
            return returnError(e)
Exemplo n.º 3
0
def roomSimulation(username=None, buildingName=None, roomName=None):
    if request.method == "POST":

        sessionKey = validateInput(request.form["sessionKey"])
        userUuid = validateInput(request.form["userUuid"])
        occupancyTimeRangeFrom = validateInput(request.form["occupancyTimeRangeFrom"])
        occupancyTimeRangeTo = validateInput(request.form["occupancyTimeRangeTo"])
        roomTemperature = validateInput(request.form["roomTemperature"])
        externalTemperature = validateInput(request.form["externalTemperature"])
        weather = validateInput(request.form["weather"])

        try:
            session = SessionManager()
            session.checkSessionValidity(sessionKey, userUuid)
            buildingsManager = BuildingsManager()
            buildingsManager.checkUserBinding(buildingName, username)
            roomSimulator = RoomSimulator(
                buildingName=buildingName,
                roomName=roomName,
                occupancyTimeRangeFrom=occupancyTimeRangeFrom,
                occupancyTimeRangeTo=occupancyTimeRangeTo,
                roomTemperature=roomTemperature,
                externalTemperature=externalTemperature,
                weather=weather,
            )

            return returnResult(roomSimulator.start())
        except Exception as e:
            return returnError(e)
Exemplo n.º 4
0
def roomRules(username=None, buildingName=None, roomName=None):

    if request.method == "POST":

        sessionKey = validateInput(request.form["sessionKey"])
        userUuid = validateInput(request.form["userUuid"])
        filterByAuthor = (
            getBoolFromString(validateInput(request.form["filterByAuthor"]))
            if "filterByAuthor" in request.form.keys()
            else False
        )
        includeGroupsRules = (
            getBoolFromString(validateInput(request.form["includeGroupsRules"]))
            if "includeGroupsRules" in request.form.keys()
            else False
        )
        orderByPriority = (
            getBoolFromString(validateInput(request.form["orderByPriority"]))
            if "orderByPriority" in request.form.keys()
            else False
        )
        includeTriggerCategory = (
            getBoolFromString(validateInput(request.form["includeTriggerCategory"]))
            if "includeTriggerCategory" in request.form.keys()
            else False
        )

        try:
            categoriesFilter = request.form["categoriesFilter"] if "categoriesFilter" in request.form.keys() else None
        except Exception as e:
            return returnError(e)

        usernameFilter = username if filterByAuthor else None

        try:
            session = SessionManager()
            session.checkSessionValidity(sessionKey, userUuid)
            buildingsManager = BuildingsManager()
            buildingsManager.checkUserBinding(buildingName, username)
            roomsManager = RoomsManager()

            return returnResult(
                roomsManager.getRules(
                    roomName=roomName,
                    buildingName=buildingName,
                    username=usernameFilter,
                    includeGroupsRules=includeGroupsRules,
                    orderByPriority=orderByPriority,
                    includeDisabled=True,
                    categoriesFilter=categoriesFilter,
                    includeTriggerCategory=includeTriggerCategory,
                )
            )
        except Exception as e:
            return returnError(e)
Exemplo n.º 5
0
def addRoomToGroup(username=None, buildingName=None, groupId=None, roomName=None):
    if request.method == "POST":

        sessionKey = validateInput(request.form["sessionKey"])
        userUuid = validateInput(request.form["userUuid"])

        try:
            session = SessionManager()
            session.checkSessionValidity(sessionKey, userUuid)
            buildingsManager = BuildingsManager()
            buildingsManager.checkUserBinding(buildingName, username)
            groupsManager = GroupsManager()
            return returnResult(groupsManager.addRoom(groupId=groupId, buildingName=buildingName, roomName=roomName))
        except Exception as e:
            return returnError(e)
Exemplo n.º 6
0
def roomActiveRules(username=None, buildingName=None, roomName=None):
    if request.method == "POST":

        sessionKey = validateInput(request.form["sessionKey"])
        userUuid = validateInput(request.form["userUuid"])

        try:
            session = SessionManager()
            session.checkSessionValidity(sessionKey, userUuid)
            buildingsManager = BuildingsManager()
            buildingsManager.checkUserBinding(buildingName, username)
            roomsManager = RoomsManager()
            return returnResult(roomsManager.getActiveRulesId(roomName=roomName, buildingName=buildingName))
        except Exception as e:
            return returnError(e)
Exemplo n.º 7
0
def disableRuleInRoom(username=None, buildingName=None, roomName=None, ruleId=None):
    if request.method == "POST":

        sessionKey = validateInput(request.form["sessionKey"])
        userUuid = validateInput(request.form["userUuid"])

        try:
            session = SessionManager()
            session.checkSessionValidity(sessionKey, userUuid)
            buildingsManager = BuildingsManager()
            buildingsManager.checkUserBinding(buildingName, username)
            roomsManager = RoomsManager()

            return returnResult(
                roomsManager.disableRule(
                    ruleId=ruleId, buildingName=buildingName, roomName=roomName, editorUuid=userUuid
                )
            )
        except Exception as e:
            return returnError(e)