Пример #1
0
    def on_PB_deleteAc_clicked(self):
        acID = self.LE_ac.text()

        if (acID == "" or not(str(acID).isdecimal())):
            print("AirConditioner ID empty or non numerical!")
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText(
                "Insert a valid numerical-only ID")
            msg.setWindowTitle("Error")
            msg.exec_()

        else: # ID AC inserito correttamente
            # Cerca l'AC, se esiste eliminalo
            flag = 0
            actualNumActuators = len(self.actuatorsConfiguration["conf"])
            for i in range(0, actualNumActuators):
                if (str(acID).lower() == str(self.actuatorsConfiguration["conf"][i]["actuatorID"]).lower() and str(self.actuatorsConfiguration["conf"][i]["type"]) == "cold"):
                    del self.actuatorsConfiguration["conf"][i]
                    flag = 1
                    break
                    
            if (flag == 1): 

                flag = 0
                actualNumActuators = len(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"])
                for i in range(0, actualNumActuators):
                    if (str(acID).lower() == str(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]["actuatorID"]).lower() and str(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]["type"]) == "cold"):
                        del self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]
                        flag = 1
                        break

                print("\t --> COMMIT")
                database_manager.update_actuators_configuration(self.db, self.actuatorsConfiguration)
                database_manager.update_roomData_configuration(self.db, self.roomDataConfiguration)

                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Information)
                msg.setInformativeText(
                    "Actuator Deleted!")
                msg.setWindowTitle("Deleted!")
                msg.exec_()

            else: # ID Attuatore non trovato, messaggio di errore
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Critical)
                msg.setInformativeText(
                    "ID Actuator not found!")
                msg.setWindowTitle("Error")
                msg.exec_()
                
        self.PB_deleteAc.setText(QtCore.QCoreApplication.translate(
            "DeleteActuatorWindow", "Delete"))
        pass
Пример #2
0
    def on_PB_deleteSensor_clicked(self):
        sensorID = self.LE_sensor.text()

        if (sensorID == "" or not (str(sensorID).isdecimal())):
            print("Sensor ID empty or non numerical!")
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText("Insert a valid numerical-only ID")
            msg.setWindowTitle("Error")
            msg.exec_()
            return

        else:  # ID sensore inserito correttamente
            # Cerca il sensore, se esiste eliminalo
            flag = 0
            actualNumSensors = len(self.roomDataConfiguration["conf"][
                self.actualRoomIndex]["sensors"])
            for i in range(0, actualNumSensors):
                if (str(sensorID).lower() == str(
                        self.roomDataConfiguration["conf"]
                    [self.actualRoomIndex]["sensors"][i]["sensorID"]).lower()):
                    del self.roomDataConfiguration["conf"][
                        self.actualRoomIndex]["sensors"][i]
                    if (len(self.roomDataConfiguration["conf"][
                            self.actualRoomIndex]["sensors"]) == 0):
                        self.roomDataConfiguration["conf"][
                            self.actualRoomIndex]["sensors"].append(
                                {"sensorID": ""})
                    flag = 1
                    break

            if (flag == 1):
                database_manager.update_roomData_configuration(
                    self.db, self.roomDataConfiguration)
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Information)
                msg.setInformativeText(
                    "Sensor deleted!\nYou will no more receive data from it.")
                msg.setWindowTitle("Info")
                msg.exec_()
            else:
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Critical)
                msg.setInformativeText("Error! Sensor not found!")
                msg.setWindowTitle("Error")
                msg.exec_()
Пример #3
0
    def on_PB_addRoom_clicked(self):

        self.actualNumRooms = len(self.configuration["rooms_settings"])
        self.nextRoomID = int(
            self.configuration["rooms_settings"][self.actualNumRooms -
                                                 1]["room"]) + 1

        roomName = self.LE_room.text()
        if (roomName == ""):
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText("Room name cannot be empty!")
            msg.setWindowTitle("Error")
            msg.exec_()
            return

        # Aggiungi stanza alla configurazione
        self.configuration["rooms_settings"].append({
            "room":
            str(self.nextRoomID),
            "room_name":
            roomName,
            "mode":
            "manual",
            "info": {
                "temp": 25,
                "weekend": 0
            },
            "season":
            "hot",
            "program": {
                "MFM": "",
                "MFE": "",
                "MFN": "",
                "WEM": "",
                "WEE": "",
                "WEN": ""
            }
        })
        # self.roomDataConfiguration = {"conf" : [{"roomID" : 0, "roomName" : "default",  "sensors" : {"sensorID" : ""}, "actuators" : {"actuatorID" : "", "valves" : {"valveID": ""}}}]}
        self.roomDataConfiguration["conf"].append({
            "roomID":
            str(self.nextRoomID),
            "roomName":
            roomName,
            "sensors": [{
                "sensorID": ""
            }],
            "actuators": [{
                "actuatorID": "",
                "type": "hot",
                "valves": [{
                    "valveID": ""
                }]
            }]
        })

        self.newConfiguration = self.configuration
        database_manager.update_configuration(self.db, self.newConfiguration)
        database_manager.update_roomData_configuration(
            self.db, self.roomDataConfiguration)

        print("\t --> COMMIT: Stanza aggiunta")
        msg = QtWidgets.QMessageBox()
        msg.setIcon(QtWidgets.QMessageBox.Information)
        msg.setInformativeText("Room added!")
        msg.setWindowTitle("Info")
        msg.exec_()
    def on_PB_connectValve_clicked(self):

        self.roomDataConfiguration = database_manager.get_roomData_configuration(self.db)
        actuatorID = self.LE_actuator.text()
        valveID = self.LE_valve.text()
        if (actuatorID == "" or valveID == ""):
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText(
                "Actuator ID and Valve ID cannot be empty!")
            msg.setWindowTitle("Error")
            msg.exec_()
            return
        else:
            # Actuator and Valve ID corretti

            # Cerca se l'attuatore esiste in actuatorsConfig
            # L'attuatore deve essere di tipo caldo
            flag = 0
            indexInActuatorList = 0
            actualNumActuators = len(self.actuatorsConfiguration["conf"])
            for i in range(0, actualNumActuators):
                if (str(actuatorID).lower() == str(self.actuatorsConfiguration["conf"][i]["actuatorID"]).lower() and self.actuatorsConfiguration["conf"][i]["type"] == "hot"):
                    indexInActuatorList = i
                    flag = 1
                    break
            if (flag == 1): # L'ID Attuatore esiste già, ottimo
                print("ID Actuator found!")

                if (int(valveID) >= 1 and int(valveID) <= 8):
                    # Cerca se la valvola relativa a questo attuatore non è già stata impegnata
                    free = 1
                    actualNumValves = len(self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"])
                    for i in range(0, actualNumValves):
                        if (str(valveID).lower() == str(self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"][i]["valveID"].lower())):
                            free = 0
                            # questa valvola di questo attuatore è già usata, non posso considerarla
                            msg = QtWidgets.QMessageBox()
                            msg.setIcon(QtWidgets.QMessageBox.Critical)
                            msg.setInformativeText(
                                "This Valve on this actuator is already used!")
                            msg.setWindowTitle("Error")
                            msg.exec_()
                            return
                    if (free == 1):
                        # La valvola per questo attuatore è libera, impegnamola

                        # Prima devo linkare l'attuatore alla stanza
                        # Vediamo prima se non è già stato linkato
                        actualNumActuators = len(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"])

                        # Faccio un loop su tutti gli attuatori della stanza, se non trovo il mio attuatore vuol dire che non è stato ancora associato alla stanza
                        for i in range(0, actualNumActuators):
                            associatedFlag = 0

                            if (str(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]["actuatorID"]).lower() == str(actuatorID).lower() and str(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]["type"]) == "hot"):
                                # L'Actuator è già associato alla stanza corrente, è solo necessario linkare la valvola

                                associatedFlag = 1
                                indexInActuatorList = i

                                # Poiché l'Actuator è già stato linkato, sappiamo per certo che è stata linkata anche una valvola a suo tempo,
                                # so già per certo che devo fare la append sulla lista delle valvole.

                                # Linkiamo ora la valvola al suo attuatore e alla stanza attuale
                                self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][indexInActuatorList]["valves"].append({"valveID": valveID})

                                # Aggiungiamo la valvola anche nella lista delle valvole del singolo attuatore
                                # Stessa cosa di prima, basta una append sulla lista delle valvole
                                actualNumValves = len(self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"])
                                self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"].append({"valveID" : str(valveID)})

                                # Finito, commit
                                print("\t --> COMMIT actuatorsConfiguration")
                                print("\t --> COMMIT roomDataConfiguration")
                                database_manager.update_actuators_configuration(self.db, self.actuatorsConfiguration)
                                database_manager.update_roomData_configuration(self.db, self.roomDataConfiguration)

                                msg = {"room" : str(self.actualRoomID), "actuator" : str(actuatorID), "valve" : str(valveID)}
                                connection_manager.mqtt_publish(self.mqttClient, "actuator/configuration", str(msg))

                                msg = QtWidgets.QMessageBox()
                                msg.setIcon(QtWidgets.QMessageBox.Information)
                                msg.setInformativeText("Valve connected to actuator!")
                                msg.setWindowTitle("Info")
                                msg.exec_()

                                return

                        if (associatedFlag == 0):
                            # L'actuator non è stato ancora associato alla stanza corrente

                            if (actualNumActuators == 1 and self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][0]["actuatorID"] == ""):
                                # Se è anche il primo actuator ad essere associato alla stanza corrente...
                                self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][0]["actuatorID"] = actuatorID

                                # Linkiamo ora la valvola al suo attuatore e alla stanza attuale
                                actualNumValves = len(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][0]["valves"])
                                if (actualNumValves == 1 and self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][0]["valves"][0]["valveID"] == ""):
                                    self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][0]["valves"][0]["valveID"] = valveID
                                else:
                                    self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][actualNumActuators]["valves"].append({"valveID": valveID})

                            else:
                                # Questo non è il primo actuator che è stato associato alla stanza corrente
                                self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"].append({"actuatorID" : actuatorID, "type": "hot", "valves" : [{"valveID": ""}]})

                                # Linkiamo ora la valvola al suo attuatore e alla stanza attuale
                                actualNumValves = len(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][actualNumActuators]["valves"])

                                if (actualNumValves == 1 and self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][actualNumActuators]["valves"][0]["valveID"] == ""):
                                    # Se questa è la prima valvola ad essere associata all'actuator corrente
                                    self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][actualNumActuators]["valves"][0]["valveID"] = valveID
                                else:
                                    # Questa non è la prima valvola associata all'actuator corrente
                                    self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][actualNumActuators]["valves"].append({"valveID": valveID})

                            actualNumValves = len(self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"])
                            if (actualNumValves == 1 and self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"][0]["valveID"] == ""):
                                self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"][0]["valveID"] = str(valveID)
                            else:
                                self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"].append({"valveID" : str(valveID)})

                            print("\t --> COMMIT actuatorsConfiguration")
                            print("\t --> COMMIT roomDataConfiguration")
                            database_manager.update_actuators_configuration(self.db, self.actuatorsConfiguration)
                            database_manager.update_roomData_configuration(self.db, self.roomDataConfiguration)

                            msg = {"room": str(self.actualRoomID), "actuator": str(actuatorID), "valve": str(valveID)}
                            connection_manager.mqtt_publish(self.mqttClient, "actuator/configuration", str(msg))

                            msg = QtWidgets.QMessageBox()
                            msg.setIcon(QtWidgets.QMessageBox.Information)
                            msg.setInformativeText(
                                "Valve connected to actuator!")
                            msg.setWindowTitle("Info")
                            msg.exec_()


                else:
                    # L'ID della valvola non esiste
                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Please insert a valid Valve ID, valid IDs from 0 to 7")
                    msg.setWindowTitle("Error")
                    msg.exec_()
                    return
            else:
                # ID dell'attuatore non trovato
                print("ID actuator not found!")
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Critical)
                msg.setInformativeText(
                    "ID Actuator not found!")
                msg.setWindowTitle("Error")
                msg.exec_()
                return
    def on_PB_deleteValve_clicked(self):
        self.roomDataConfiguration = database_manager.get_roomData_configuration(self.db)
        actuatorID = self.LE_actuator.text()
        valveID = self.LE_valve.text()

        if (actuatorID == "" or valveID == ""):
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText(
                "Actuator ID and Valve ID cannot be empty!")
            msg.setWindowTitle("Error")
            msg.exec_()
            return
        else:
            # Actuator and Valve ID corretti
            # Cerca se l'attuatore esiste in actuatorsConfig
            actuatorFlag = 0
            indexInActuatorList = 0
            actualNumActuators = len(self.actuatorsConfiguration["conf"])

            for i in range(0, actualNumActuators):
                if (str(actuatorID).lower() == str(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]["actuatorID"]).lower() and str(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]["type"]) == "hot"):
                    indexInActuatorList = i
                    actuatorFlag = 1
                    break

            if (actuatorFlag == 1): # L'attuatore esiste
                print("ID Actuator found!")
                if (int(valveID) >= 1 and int(valveID) <= 8):
                    # L'ID della valvola è valido

                    # Cerchiamo la valvola
                    valveFlag = 0
                    indexInValveList = 0
                    actualNumValves = len(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]["valves"])
                    for j in range(0, actualNumValves):
                        if (str(valveID).lower() == str(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][i]["valves"][j]["valveID"]).lower()):
                            indexInValveList = j
                            valveFlag = 1
                            break

                    if (valveFlag == 1): # La valvola è stata trovata
                        # Cancelliamo la valvola, ora non sarà più usata dalla stanza attuale
                        del self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][indexInActuatorList]["valves"][indexInValveList]
                        if (len(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][indexInActuatorList]["valves"]) == 0):
                            self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][indexInActuatorList]["valves"].append({"valveID": ""})

                        actuatorFlag = 0
                        indexInActuatorList = 0
                        actualNumActuators = len(self.actuatorsConfiguration["conf"])
                        for i in range(0, actualNumActuators):
                            if (str(actuatorID).lower() == str(self.actuatorsConfiguration["conf"][i]["actuatorID"]).lower() and str(self.actuatorsConfiguration["conf"][i]["type"]) == "hot"):
                                indexInActuatorList = i
                                actuatorFlag = 1
                                break
                        if (actuatorFlag == 1):
                            del self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"][indexInValveList]
                            if (len(self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"]) == 0):
                                self.actuatorsConfiguration["conf"][indexInActuatorList]["valves"].append({"valveID" : ""})

                        print("\t --> COMMIT actuatorsConfiguration")
                        print("\t --> COMMIT roomDataConfiguration")
                        database_manager.update_actuators_configuration(self.db, self.actuatorsConfiguration)
                        database_manager.update_roomData_configuration(self.db, self.roomDataConfiguration)



                    else:
                        # La valvola NON è stata trovata
                        msg = QtWidgets.QMessageBox()
                        msg.setIcon(QtWidgets.QMessageBox.Critical)
                        msg.setInformativeText(
                            "Valve not found!")
                        msg.setWindowTitle("Error")
                        msg.exec_()
                        return
                else:
                    # L'ID della valvola non esiste
                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Please insert a valid Valve ID, valid IDs from 0 to 7")
                    msg.setWindowTitle("Error")
                    msg.exec_()
                    return

            else:
                # ID dell'attuatore non trovato
                print("ID actuator not found!")
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Critical)
                msg.setInformativeText(
                    "ID Actuator not found!")
                msg.setWindowTitle("Error")
                msg.exec_()
                return
Пример #6
0
    def on_PB_connectAc_released(self):
        acID = self.LE_ac.text()

        # Check se il campo inserito è vuoto
        if (acID == "" or not(str(acID).isdecimal())):
            print("AirConditioner ID empty or non numerical!")
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText(
                "Insert a valid numerical-only ID")
            msg.setWindowTitle("Error")
            msg.exec_()
            self.PB_connectAc.setEnabled(True)
            self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Connect"))
        else:
            # Check se ID attuatore già presente
            # Devo però controllare anche che l'actuator sia di tipo freddo COLD = condizionatore
            flag = 0
            actualNumAc = len(self.actuatorsConfiguration["conf"])
            for i in range(0, actualNumAc):
                if (str(acID).lower() == str(self.actuatorsConfiguration["conf"][i]["actuatorID"]).lower() and self.actuatorsConfiguration["conf"][i]["type"] == "cold"):
                    flag = 1
                    break
            if (flag == 1): # L'ID AC esiste già, ritorna errore
                print("ID AirConditioner already IN!")
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Critical)
                msg.setInformativeText(
                    "This AirConditioner has been already connected!")
                msg.setWindowTitle("Error")
                msg.exec_()
                self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Connect"))
                return

            net_SSID = data.networkData["net_SSID"]
            net_PWD = data.networkData["net_PWD"]
            # net_SSID = "ciao"
            # net_PWD = "bela"

            if (net_SSID == "" or net_PWD == ""):
                print("Net SSID and NET PWD cannot be empty! Maybe Raspone is not connected to network...")

                print("No SSID and PWD found when connecting AC")
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Critical)
                msg.setInformativeText(
                    "Please connect the thermostat to WiFi before adding and AC")
                msg.setWindowTitle("Error")
                msg.exec_()

            else: 
                returnID = connection_actuator_cold.connection(acID, actualRoomID, net_SSID, net_PWD)    
                # returnID = 0
                if (returnID == 0):
                    print("OK! AC is being connected!")

                    if (len(self.actuatorsConfiguration["conf"]) == 1 and str(self.actuatorsConfiguration["conf"][0]["actuatorID"]) == ""):
                        self.actuatorsConfiguration["conf"][0]["actuatorID"] = acID
                        self.actuatorsConfiguration["conf"][0]["type"] = "cold"

                    else:
                        self.actuatorsConfiguration["conf"].append({"actuatorID" : acID, "type": "cold", "valves" : [{"valveID": ""}]})

                    if (len(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"]) == 1 and str(self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][0]["actuatorID"]) == ""):
                        self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][0]["actuatorID"] = acID
                        self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"][0]["type"] = "cold"
                    else:
                        self.roomDataConfiguration["conf"][self.actualRoomIndex]["actuators"].append({"actuatorID": acID, "type": "cold", "valves": [{"valveID": ""}]})

                    print("\t --> COMMIT actuatorsConfiguration")    
                    database_manager.update_actuators_configuration(self.db, self.actuatorsConfiguration)
                    print("\t --> COMMIT roomDataConfiguration")
                    database_manager.update_roomData_configuration(self.db, self.roomDataConfiguration)

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Information)
                    msg.setInformativeText(
                        "AC connected!")
                    msg.setWindowTitle("Connected!")
                    msg.exec_()

                    self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Connect"))

                elif (returnID == -1):
                    print("AC not found in BT proximity, check AC ID pliz")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "AC ID not found, please retry")
                    msg.setWindowTitle("Errore")
                    msg.exec_()
                    
                    self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Not connected, please retry..."))
                    self.PB_connectAc.setEnabled(True)

                elif (returnID == -2):
                    print("Cannot connect, Bluetooth Socket error.")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "AC not connected, error in BT socket")
                    msg.setWindowTitle("Errore")
                    msg.exec_()

                    self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Not connected, please retry..."))
                    self.PB_connectAc.setEnabled(True)

                elif (returnID == -3):
                    print("Nothing received from AC, did you pushed the button?")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Push the AC button BEFORE the connection attempt!")
                    msg.setWindowTitle("Error")
                    msg.exec_()

                    self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Not connected, please retry..."))
                    self.PB_connectAc.setEnabled(True)

                elif (returnID == -4):
                    print("Cannot connect, no transmission from actACuator")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "No transmission from the AC")
                    msg.setWindowTitle("Error")
                    msg.exec_()

                    self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Not connected, please retry..."))
                    self.PB_connectAc.setEnabled(True)

                elif (returnID == -5):
                    print("Cannot connect, error transmitting SSID")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Error while transferring the SSID to the AC")
                    msg.setWindowTitle("Error")
                    msg.exec_()

                    self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Not connected, please retry..."))
                    self.PB_connectAc.setEnabled(True)

                elif (returnID == -6):
                    print("Cannot connect, error transmitting WIFI Password")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Error while tansferring the network password to the AC")
                    msg.setWindowTitle("Error")
                    msg.exec_()

                    self.PB_connectAc.setText(QtCore.QCoreApplication.translate(
                            "ACSettingsWindow", "Not connected, please retry..."))
                    self.PB_connectAc.setEnabled(True)
Пример #7
0
    def on_PB_deleteRoom_clicked(self):
        self.actualNumRooms = len(self.configuration["rooms_settings"])
        roomName = self.LE_room.text()
        if (roomName == ""):
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText(
                "Room name cannot be empty")
            msg.setWindowTitle("Error")
            msg.exec_()
            return

        if (roomName.lower() == "default"):
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText(
                "Error! You cannot delete the main room!")
            msg.setWindowTitle("Error")
            msg.exec_()
            return

        flag = 0
        for i in range(0, self.actualNumRooms):
            if (str(roomName).lower() == str(self.configuration["rooms_settings"][i]["room_name"]).lower()):
                if (str(roomName).lower() == str(self.roomDataConfiguration["conf"][i]["roomName"]).lower()):

                    # Se ci sono valvole associate, elimina la valvola utilizzata rendendola libera per altre stanze
                    actualNumActuators = len(self.roomDataConfiguration["conf"][i]["actuators"])
                    for j in range(0, actualNumActuators):  # Cicla sugli attatori disponibili per questa stanza
                        actualNumValves = len(self.roomDataConfiguration["conf"][i]["actuators"][j]["valves"])
                        actualNumValves_actuatorsConfig = actualNumValves
                        for k in range(0, actualNumValves): # Cicla sulle valvole disponibili per questo attuatore
                            # if (k < actualNumValves_actuatorsConfig):
                            if (str(self.roomDataConfiguration["conf"][i]["actuators"][j]["valves"][k]["valveID"]) != "" and str(self.roomDataConfiguration["conf"][i]["actuators"][j]["type"]) == "hot"):
                                # Questa valvola è collegata, togliamola da actuatorsConfiguration perché è tornata libera
                                connectedValveID = self.roomDataConfiguration["conf"][i]["actuators"][j]["valves"][k]["valveID"]
                                connectedActuatorID = self.roomDataConfiguration["conf"][i]["actuators"][j]["actuatorID"]

                                actualNumActuators_actuatorsConfig = len(self.actuatorsConfiguration["conf"])
                                for l in range(0, actualNumActuators_actuatorsConfig): # Cicla sugli attuatori disponibili nella actuatorsConfiguration
                                    if (str(self.actuatorsConfiguration["conf"][l]["actuatorID"]) == connectedActuatorID):
                                        actualNumValves_actuatorsConfig = len(self.actuatorsConfiguration["conf"][l]["valves"])
                                        for m in range(0, actualNumValves_actuatorsConfig):
                                            if (m < len(self.actuatorsConfiguration["conf"][l]["valves"])):
                                                if (str(self.actuatorsConfiguration["conf"][l]["valves"][m]["valveID"]) == connectedValveID):
                                                    # self.actuatorsConfiguration["conf"][l]["valves"][m]["valveID"] = "" # Imposta la valvola come libera
                                                    del self.actuatorsConfiguration["conf"][l]["valves"][m]
                                                    actualNumValves_actuatorsConfig = actualNumValves_actuatorsConfig - 1
                                                    # actualNumValves = actualNumValves - 1
                                                    if (len(self.actuatorsConfiguration["conf"][l]["valves"]) == 0):
                                                        self.actuatorsConfiguration["conf"][l]["valves"].append({"valveID" : ""})

                    del self.configuration["rooms_settings"][i]
                    if (len(self.configuration["rooms_settings"]) == 0):
                        self.configuration["rooms_settings"].append({'room': "0", 'room_name': 'default', 'mode': 'manual', 'info': {'temp': 25, 'weekend': 0}, 'season': 'hot', "program" : {"MFM" : "", "MFE" : "", "MFN" : "", "WEM" : "", "WEE" : "", "WEN" : ""}})
                    del self.roomDataConfiguration["conf"][i]
                    if (len(self.roomDataConfiguration["conf"]) == 0):
                        self.roomDataConfiguration["conf"].append({"roomID" : "0", "roomName" : "default",  "sensors" : [{"sensorID" : ""}], "actuators" : [{"actuatorID" : "", "type" : "hot", "valves" : [{"valveID": ""}]}]})
                    flag = 1

                    break

        if (flag == 1):
            self.newConfiguration = self.configuration
            database_manager.update_configuration(self.db, self.newConfiguration)
            database_manager.update_roomData_configuration(self.db, self.roomDataConfiguration)
            database_manager.update_actuators_configuration(self.db, self.actuatorsConfiguration)

            print("\t --> COMMIT: Stanza rimossa")
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Information)
            msg.setInformativeText(
                "Room deleted!\nYou will no more receive data from the related sensor. Disconnect it.")
            msg.setWindowTitle("Info")
            msg.exec_()
        else:
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText(
                "Error! Room not found!")
            msg.setWindowTitle("Error")
            msg.exec_()
Пример #8
0
    def on_PB_connectSensor_released(self):
        sensorID = self.LE_sensor.text()

        if (sensorID == "" or not (str(sensorID).isdecimal())):
            print("Sensor ID empty or non numerical!")
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Critical)
            msg.setInformativeText("Insert a valid numerical-only ID")
            msg.setWindowTitle("Error")
            msg.exec_()
            self.PB_connectSensor.setEnabled(True)
            self.PB_connectSensor.setText(
                QtCore.QCoreApplication.translate("SensorSettingsWindow",
                                                  "Add Sensor..."))

        else:  # ID sensore inserito

            # Check se ID attuatore già presente
            flag = 0
            actualNumSensors = len(self.roomDataConfiguration["conf"][
                self.actualRoomIndex]["sensors"])
            for i in range(0, actualNumSensors):
                if (str(sensorID).lower() == str(
                        self.roomDataConfiguration["conf"]
                    [self.actualRoomIndex]["sensors"][i]["sensorID"]).lower()):
                    flag = 1
                    break
            if (flag == 1):  # L'ID Attuatore esiste già, ritorna errore
                print("ID Sensors already IN!")
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Critical)
                msg.setInformativeText(
                    "This sensor has been already connected!")
                msg.setWindowTitle("Error")
                msg.exec_()
                self.PB_connectSensor.setText(
                    QtCore.QCoreApplication.translate("SensorSettingsWindow",
                                                      "Add"))
                return

            net_SSID = data.networkData["net_SSID"]
            net_PWD = data.networkData["net_PWD"]

            if (net_SSID == "" or net_PWD == ""):
                print(
                    "Net SSID and NET PWD cannot be empty! Maybe Raspone is not connected to network..."
                )

                print("No SSID and PWD found when connecting actuator")
                msg = QtWidgets.QMessageBox()
                msg.setIcon(QtWidgets.QMessageBox.Critical)
                msg.setInformativeText(
                    "Please connect the thermostat to WiFi before adding an actuator!"
                )
                msg.setWindowTitle("Error")
                msg.exec_()

            else:
                returnID = connection_sensor.connection(
                    sensorID, net_SSID, net_PWD,
                    str(self.actualRoomName) + str(self.actualRoomID))
                # returnID = 0
                if (returnID == 0):
                    print("OK! Sensor is being connected!")

                    if (len(
                            self.roomDataConfiguration["conf"]
                        [self.actualRoomIndex]["sensors"]) == 1 and str(
                            self.roomDataConfiguration["conf"]
                            [self.actualRoomIndex]["sensors"][0]["sensorID"])
                            == ""):
                        self.roomDataConfiguration["conf"][
                            self.actualRoomIndex]["sensors"][0][
                                "sensorID"] = sensorID
                    else:
                        self.roomDataConfiguration["conf"][
                            self.actualRoomIndex]["sensors"].append(
                                {"sensorID": sensorID})

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Information)
                    msg.setInformativeText("Sensor connected!")
                    msg.setWindowTitle("Connected!")
                    msg.exec_()

                    database_manager.update_roomData_configuration(
                        self.db, self.roomDataConfiguration)
                    self.PB_connectSensor.setText(
                        QtCore.QCoreApplication.translate(
                            "SensorSettingsWindow", "Connect"))

                elif (returnID == -1):
                    print(
                        "Sensor not found in BT proximity, check actuator ID pliz"
                    )

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText("Sensor ID not found, please retry")
                    msg.setWindowTitle("Errore")
                    msg.exec_()

                    self.PB_connectSensor.setText(
                        QtCore.QCoreApplication.translate(
                            "SensorSettingsWindow", "Not connected!"))
                    self.PB_connectSensor.setEnabled(True)

                elif (returnID == -2):
                    print("Cannot connect, Bluetooth Socket error.")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Actuator not connected, error in BT socket")
                    msg.setWindowTitle("Errore")
                    msg.exec_()

                    self.PB_connectSensor.setText(
                        QtCore.QCoreApplication.translate(
                            "SensorSettingsWindow", "Not connected!"))
                    self.PB_connectSensor.setEnabled(True)

                elif (returnID == -3):
                    print(
                        "Nothing received from sensor, did you pushed the button?"
                    )

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Push the sensor button BEFORE the connection attempt!"
                    )
                    msg.setWindowTitle("Errore")
                    msg.exec_()

                    self.PB_connectSensor.setText(
                        QtCore.QCoreApplication.translate(
                            "SensorSettingsWindow", "Not connected!"))
                    self.PB_connectSensor.setEnabled(True)

                elif (returnID == -4):
                    print("Cannot connect, no transmission from sensor")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText("No transmission from the sensor")
                    msg.setWindowTitle("Errore")
                    msg.exec_()

                    self.PB_connectSensor.setText(
                        QtCore.QCoreApplication.translate(
                            "SensorSettingsWindow", "Not connected!"))
                    self.PB_connectSensor.setEnabled(True)

                elif (returnID == -5):
                    print("Cannot connect, error transmitting SSID")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Error while transferring the SSID to the sensor")
                    msg.setWindowTitle("Errore")
                    msg.exec_()

                    self.PB_connectSensor.setText(
                        QtCore.QCoreApplication.translate(
                            "SensorSettingsWindow", "Not connected!"))
                    self.PB_connectSensor.setEnabled(True)

                elif (returnID == -6):
                    print("Cannot connect, error transmitting WIFI Password")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Error while tansferring the network password to the senosr"
                    )
                    msg.setWindowTitle("Errore")
                    msg.exec_()

                    self.PB_connectSensor.setText(
                        QtCore.QCoreApplication.translate(
                            "SensorSettingsWindow", "Not connected!"))
                    self.PB_connectSensor.setEnabled(True)

                # elif (returnID == -7):
                #     print("Cannot connect, error transmitting MQTT Info")

                #     msg = QtWidgets.QMessageBox()
                #     msg.setIcon(QtWidgets.QMessageBox.Critical)
                #     msg.setInformativeText(
                #         "Errore nella trasmissione delle info MQTT al sensore")
                #     msg.setWindowTitle("Error")
                #     msg.exec_()

                #     self.PB_connectSensor.setText(QtCore.QCoreApplication.translate(
                #             "SensorSettingsWindow", "Not connected!"))
                #     self.PB_connectSensor.setEnabled(True)

                elif (returnID == -8):
                    print("Cannot connect, error transmitting room name Info")

                    msg = QtWidgets.QMessageBox()
                    msg.setIcon(QtWidgets.QMessageBox.Critical)
                    msg.setInformativeText(
                        "Error while transferring MQTT info to the sensor")
                    msg.setWindowTitle("Error")
                    msg.exec_()

                    self.PB_connectSensor.setText(
                        QtCore.QCoreApplication.translate(
                            "SensorSettingsWindow", "Not connected!"))
                    self.PB_connectSensor.setEnabled(True)