Ejemplo n.º 1
0
    def onCommand(self, Unit, Command, Level, Hue):
        Domoticz.Log("onCommand called for Unit " + str(Unit) +
                     ": Parameter '" + str(Command) + "', Level: " +
                     str(Level))
        # 2018-04-02 20:26:01.192 User: Admin initiated a switch command (17/Freebox - Presence iPhonedMatthieu/On)
        # 2018-04-02 20:26:01.209 (Freebox) onCommand called for Unit 5: Parameter 'On', Level: 0
        # 2018-04-02 20:27:50.550 User: Admin initiated a switch command (17/Freebox - Presence iPhonedMatthieu/Off)
        # 2018-04-02 20:27:50.552 (Freebox) onCommand called for Unit 5: Parameter 'Off', Level: 0
        # 2018-04-02 20:28:44.350 User: Admin initiated a switch command (18/Freebox - Presence iPhonedTiphaine/On)
        # 2018-04-02 20:28:44.380 (Freebox) onCommand called for Unit 6: Parameter 'On', Level: 0
        keyunit = self.getOrCreateUnitIdForDevice(
            self.DeviceType.deviceCommande, "WIFI")
        if (keyunit == Unit):
            f = freebox.FbxApp("idPluginDomoticz",
                               self.token,
                               host=self.freeboxURL)
            if (str(Command) == "On"):
                f.setOnOFFWifi(1)
            else:
                f.setOnOFFWifi(0)
            time.sleep(1)
            #On remet à jour l'état du wifi suite à la modification
            v_etatWIFI = f.isOnWIFI()
            self.updateDeviceIfExist(self.DeviceType.deviceCommande, "WIFI",
                                     v_etatWIFI, str(v_etatWIFI))

        keyunit = self.getOrCreateUnitIdForDevice(
            self.DeviceType.deviceCommande, "REBOOT")
        if (keyunit == Unit):
            f = freebox.FbxApp("idPluginDomoticz",
                               self.token,
                               host=self.freeboxURL)
            f.reboot()
Ejemplo n.º 2
0
 def onHeartbeat(self):
     Domoticz.Debug("onHeartbeat called")
     if self._lastExecution.minute == datetime.datetime.now().minute :
         return        
     self._lastExecution = datetime.datetime.now()
     if self.token == "" :
         Domoticz.Log("Pas de token défini.")
         return
     f=freebox.FbxApp("idPluginDomoticz",self.token,host=self.freeboxURL)
     
     usageDisk = f.diskinfo()
     for disk in usageDisk:
         self.updateDeviceIfExist(self.DeviceType.deviceTypeDisk,disk,int(float(usageDisk[disk])), str(usageDisk[disk]))
     
     sysinfo = f.sysinfo()
     for info in sysinfo:
         self.updateDeviceIfExist(self.DeviceType.deviceSystemInfo,info,int(float(sysinfo[info])), str(sysinfo[info]))
     
     listeMacString = Parameters["Mode2"]
     listeMac = listeMacString.split(";")
     for macAdresse in listeMac:
         name = f.getNameByMacAdresse(macAdresse)
         presence = 0
         if (name != None):
             if(f.isPresenceByMacAdresse(macAdresse)):
                 presence = 1
         self.updateDeviceIfExist(self.DeviceType.devicePresence,macAdresse,presence, str(presence))
     
     lanPeriph = f.lanPeripherique()
     for periph in lanPeriph:            
         Domoticz.Debug(lanPeriph[periph]+" ("+periph+") présent")
    def onHeartbeat(self):
        Domoticz.Debug("onHeartbeat called")
        try:
            if self.token == "" :
                Domoticz.Log("Pas de token défini.")
                return
            f=freebox.FbxApp("idPluginDomoticz",self.token,host=self.freeboxURL)
            

            (sensorsState, sensorBatteries) = f.sensor()
            for sensor in sensorsState:
                self.updateDeviceIfExist(self.DeviceType.devicePresence, sensor, sensorsState[sensor], str(sensorsState[sensor]), sensorBatteries[sensor])
    
            cameraState = f.camera(link=Parameters["Mode2"])
            self.updateDeviceIfExist(self.DeviceType.devicePresence, "FREEBOX - Caméra", cameraState, str(cameraState), 100)

            alarmState = f.isAlarmOn()
            alarmBattery = f.getAlarmBattery()
            self.updateDeviceIfExist(self.DeviceType.deviceCommande, "FREEBOX - Alarme", alarmState, str(alarmState), alarmBattery)

            remoteState = f.getRemoteInput()
            remoteBattery = f.getRemoteBattery()
            if(remoteState == 0):
                self.updateDeviceIfExist(self.DeviceType.deviceCommande, "FREEBOX - Télécommande", True, "True", remoteBattery)
            elif(remoteState == 1):
                self.updateDeviceIfExist(self.DeviceType.deviceCommande, "FREEBOX - Télécommande", False, "False", remoteBattery)

        except Exception as e:
            Domoticz.Log("onHeartbeat error: "+str(e))
Ejemplo n.º 4
0
    def onStart(self):
        Domoticz.Debug("onStart called")

        self.freeboxURL = Parameters["Address"]+":"+Parameters["Port"]
        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)
        DumpConfigToLog()
        if Parameters["Mode1"] == "": # Le Token
            Domoticz.Log("C'est votre première connexion, le token n'est pas renseigné.")
            Domoticz.Log("Vous avez 30 secondes pour autoriser le plugin sur l'écran de la Freebox.")
            Domoticz.Log("Une fois autorisé sur la Freebox, le token s'affichera ici.")
            Token = freebox.FbxCnx(self.freeboxURL).register("idPluginDomoticz","Plugin Freebox","1","Domoticz")
            if Token:
                Domoticz.Log("------------------------------------------------------------------------------")
                Domoticz.Log("Veuillez copier ce token dans la configuration du plugin Reglages > Matériel")
                Domoticz.Log(Token)
                Domoticz.Log("------------------------------------------------------------------------------")
            else:
                 Domoticz.Log("Vous avez été trop long (ou avez refusé), veuillez désactiver et réactiver le matériel Reglages > Matériel.")
        else:
            self.token = Parameters["Mode1"]
            Domoticz.Log("Token déjà présent. OK.")

            f=freebox.FbxApp("idPluginDomoticz",self.token,host=self.freeboxURL)
            usageDisk = f.diskinfo()
            #Creation des device Disque Dur de la Freebox
            for disk in usageDisk:
                keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceTypeDisk,disk)
                if (keyunit not in Devices):
                    v_dev = Domoticz.Device(Unit=keyunit, Name="Utilisation "+disk, TypeName="Percentage")
                    v_dev.Create()
                    Domoticz.Log("Création du dispositif "+"Utilisation "+disk)
                    # Unfortunately the image in the Percentage device can not be changed. Use Custom device!
                    # Domoticz.Device(Unit=_UNIT_USAGE, Name=Parameters["Address"], TypeName="Custom", Options={"Custom": "1;%"}, Image=3, Used=1).Create()
            
            #Creation des device infos systeme de la Freebox
            sysinfo = f.sysinfo()
            for info in sysinfo:
                keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceSystemInfo,info)
                if (keyunit not in Devices):
                    v_dev = Domoticz.Device(Unit=keyunit, Name="System "+info, TypeName="Temperature")
                    v_dev.Create()
                    Domoticz.Log("Création du dispositif "+"System "+info)

            #Creation des device presence de la Freebox
            listeMacString = Parameters["Mode2"]
            listeMac = listeMacString.split(";")
            for macAdresse in listeMac:
                name = f.getNameByMacAdresse(macAdresse)
                if (name != None):
                    keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.devicePresence,macAdresse)
                    if (keyunit not in Devices):
                        v_dev = Domoticz.Device(Unit=keyunit, Name="Presence "+name, TypeName="Switch")
                        v_dev.Create()
                        Domoticz.Log("Création du dispositif "+"Presence "+name)
                else:
                    Domoticz.Log("La mac adresse "+macAdresse+" est inconnu de la freebox, on ne crée aucun dispositif.")
            DumpConfigToLog()
Ejemplo n.º 5
0
    def onHeartbeat(self):
        Domoticz.Debug("onHeartbeat called")
        try:
            if self._lastExecution.minute == datetime.datetime.now().minute:
                return
            self._lastExecution = datetime.datetime.now()
            if self.token == "":
                Domoticz.Log("Pas de token défini.")
                return
            f = freebox.FbxApp("idPluginDomoticz",
                               self.token,
                               host=self.freeboxURL)

            usageDisk = f.diskinfo()
            for disk in usageDisk:
                self.updateDeviceIfExist(self.DeviceType.deviceTypeDisk, disk,
                                         int(float(usageDisk[disk])),
                                         str(usageDisk[disk]))

            connection = f.connectioninfo()
            for connectionDetail in connection:
                self.updateDeviceIfExist(
                    self.DeviceType.deviceConnectionInfo, connectionDetail,
                    int(float(connection[connectionDetail])),
                    str(connection[connectionDetail]))

            sysinfo = f.sysinfo()
            for info in sysinfo:
                self.updateDeviceIfExist(self.DeviceType.deviceSystemInfo,
                                         info, int(float(sysinfo[info])),
                                         str(sysinfo[info]))

            listeMacString = Parameters["Mode2"]
            listeMac = listeMacString.split(";")
            for macAdresse in listeMac:
                name = f.getNameByMacAdresse(macAdresse)
                presence = 0
                if (name != None):
                    if (f.isPresenceByMacAdresse(macAdresse)):
                        presence = 1
                self.updateDeviceIfExist(self.DeviceType.devicePresence,
                                         macAdresse, presence, str(presence))

            lanPeriph = f.lanPeripherique()
            for periph in lanPeriph:
                Domoticz.Debug(lanPeriph[periph] + " (" + periph + ") présent")

            v_etatWIFI = f.isOnWIFI()
            self.updateDeviceIfExist(self.DeviceType.deviceCommande, "WIFI",
                                     v_etatWIFI, str(v_etatWIFI))

            constatus = f.constatus()
            self.updateDeviceIfExist(self.DeviceType.deviceCommande,
                                     "WANStatus", constatus, str(constatus))

        except Exception as e:
            Domoticz.Log("onHeartbeat error: " + str(e))
    def onStart(self):
        Domoticz.Debug("onStart called")
        try:
            self.freeboxURL = Parameters["Address"]+":"+Parameters["Port"]
            if Parameters["Mode6"] == "Debug":
                Domoticz.Debugging(1)
            DumpConfigToLog()
            if Parameters["Mode1"] == "": # Le Token
                Domoticz.Log("C'est votre première connexion, le token n'est pas renseigné.")
                Domoticz.Log("Vous avez 30 secondes pour autoriser le plugin sur l'écran de la Freebox.")
                Domoticz.Log("Une fois autorisé sur la Freebox, le token s'affichera ici.")
                Token = freebox.FbxCnx(self.freeboxURL).register("idPluginDomoticz","Plugin Freebox","1","Domoticz")
                if Token:
                    Domoticz.Log("------------------------------------------------------------------------------")
                    Domoticz.Log("Veuillez copier ce token dans la configuration du plugin Reglages > Matériel")
                    Domoticz.Log(Token)
                    Domoticz.Log("------------------------------------------------------------------------------")
                else:
                    Domoticz.Log("Vous avez été trop long (ou avez refusé), veuillez désactiver et réactiver le matériel Reglages > Matériel.")
            else:
                self.token = Parameters["Mode1"]
                Domoticz.Log("Token déjà présent. OK.")

                f=freebox.FbxApp("idPluginDomoticz",self.token,host=self.freeboxURL)

                Domoticz.Heartbeat(5)
                #Creation du device pour le détecteur d'ouverture

                (v_sensors, batteries) = f.sensor()
                for sensor in v_sensors:
	                keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.devicePresence, sensor)
	                if (keyunit not in Devices):
	                    v_dev = Domoticz.Device(Unit=keyunit, Name=sensor, TypeName="Motion")
	                    v_dev.Create()
	                    Domoticz.Log("Création du dispositif " + sensor)

                keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.devicePresence, "FREEBOX - Caméra")
                if (keyunit not in Devices):
                	v_dev = Domoticz.Device(Unit=keyunit, Name= "FREEBOX - Caméra", TypeName="Motion")
                	v_dev.Create()
                	Domoticz.Log("Création du dispositif " + "FREEBOX - Caméra")

                keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceCommande,"FREEBOX - Alarme")
                if (keyunit not in Devices):
                    v_dev = Domoticz.Device(Unit=keyunit, Name="FREEBOX - Alarme", TypeName="Switch")
                    v_dev.Create()
                    Domoticz.Log("Création du dispositif " + "FREEBOX - Alarme")

                keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceCommande,"FREEBOX - Télécommande")
                if (keyunit not in Devices):
                    v_dev = Domoticz.Device(Unit=keyunit, Name="FREEBOX - Télécommande", TypeName="Switch")
                    v_dev.Create()
                    Domoticz.Log("Création du dispositif " + "FREEBOX - Télécommande")
                
                DumpConfigToLog()
        except Exception as e:
            Domoticz.Log("OnStart error: "+str(e))
    def onCommand(self, Unit, Command, Level, Hue):
        try:
            Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))

            keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceCommande,"FREEBOX - Alarme")
            if (keyunit == Unit):
                f=freebox.FbxApp("idPluginDomoticz",self.token,host=self.freeboxURL) 
                if(str(Command) == "On"):
                    f.setAlarmOn(True)
                    self.updateDeviceIfExist(self.DeviceType.deviceCommande,"FREEBOX - Alarme",True, "True")
                else:
                    f.setAlarmOn(False)
                    self.updateDeviceIfExist(self.DeviceType.deviceCommande,"FREEBOX - Alarme",False, "False")
        except (KeyError):
            pass
Ejemplo n.º 8
0
    def onStart(self):
        Domoticz.Debug("onStart called")
        try:
            self.freeboxURL = Parameters["Address"] + ":" + Parameters["Port"]
            if Parameters["Mode6"] == "Debug":
                Domoticz.Debugging(1)
            DumpConfigToLog()
            if Parameters["Mode1"] == "":  # Le Token
                Domoticz.Log(
                    "C'est votre première connexion, le token n'est pas renseigné."
                )
                Domoticz.Log(
                    "Vous avez 30 secondes pour autoriser le plugin sur l'écran de la Freebox."
                )
                Domoticz.Log(
                    "Une fois autorisé sur la Freebox, le token s'affichera ici."
                )
                Token = freebox.FbxCnx(self.freeboxURL).register(
                    "idPluginDomoticz", "Plugin Freebox", "1", "Domoticz")
                if Token:
                    Domoticz.Log(
                        "------------------------------------------------------------------------------"
                    )
                    Domoticz.Log(
                        "Veuillez copier ce token dans la configuration du plugin Reglages > Matériel"
                    )
                    Domoticz.Log(Token)
                    Domoticz.Log(
                        "------------------------------------------------------------------------------"
                    )
                else:
                    Domoticz.Log(
                        "Vous avez été trop long (ou avez refusé), veuillez désactiver et réactiver le matériel Reglages > Matériel."
                    )
            else:
                self.token = Parameters["Mode1"]
                Domoticz.Log("Token déjà présent. OK.")

                f = freebox.FbxApp("idPluginDomoticz",
                                   self.token,
                                   host=self.freeboxURL)

                #Pour trouver le pb avec la FreeBox Delta, on affiche le json
                #if Parameters["Mode6"] == "Debug":
                #    jsonUsageDisk = f.diskinfoRaw()
                #    Domoticz.Debug(jsonUsageDisk)

                #Creation des device Disque Dur de la Freebox
                usageDisk = f.diskinfo()
                for disk in usageDisk:
                    keyunit = self.getOrCreateUnitIdForDevice(
                        self.DeviceType.deviceTypeDisk, disk)
                    if (keyunit not in Devices):
                        v_dev = Domoticz.Device(Unit=keyunit,
                                                Name="Utilisation " + disk,
                                                TypeName="Percentage")
                        v_dev.Create()
                        Domoticz.Log("Création du dispositif " +
                                     "Utilisation " + disk)
                        # Unfortunately the image in the Percentage device can not be changed. Use Custom device!
                        # Domoticz.Device(Unit=_UNIT_USAGE, Name=Parameters["Address"], TypeName="Custom", Options={"Custom": "1;%"}, Image=3, Used=1).Create()

                #Creation des Débits de la Freebox
                connectionDetail = f.connectioninfo()
                for connection in connectionDetail:
                    keyunit = self.getOrCreateUnitIdForDevice(
                        self.DeviceType.deviceConnectionInfo, connection)
                    if (keyunit not in Devices):
                        v_dev = Domoticz.Device(Unit=keyunit,
                                                Name="Débit " + connection,
                                                TypeName="Custom",
                                                Options={"Custom": "1;Ko"},
                                                Used=1)
                        v_dev.Create()
                        Domoticz.Log("Création du dispositif " + "Débit " +
                                     connection)

                #Creation des device infos systeme de la Freebox
                sysinfo = f.sysinfo()
                for info in sysinfo:
                    keyunit = self.getOrCreateUnitIdForDevice(
                        self.DeviceType.deviceSystemInfo, info)
                    if (keyunit not in Devices):
                        v_dev = Domoticz.Device(Unit=keyunit,
                                                Name="System " + info,
                                                TypeName="Temperature")
                        v_dev.Create()
                        Domoticz.Log("Création du dispositif " + "System " +
                                     info)

                #Creation des device presence de la Freebox
                listeMacString = Parameters["Mode2"]
                if (listeMacString != ""):
                    listeMac = listeMacString.split(";")
                    for macAdresse in listeMac:
                        name = f.getNameByMacAdresse(macAdresse)
                        if (name != None):
                            keyunit = self.getOrCreateUnitIdForDevice(
                                self.DeviceType.devicePresence, macAdresse)
                            if (keyunit not in Devices):
                                v_dev = Domoticz.Device(Unit=keyunit,
                                                        Name="Presence " +
                                                        name,
                                                        TypeName="Switch")
                                v_dev.Create()
                                Domoticz.Log("Création du dispositif " +
                                             "Presence " + name)
                        else:
                            Domoticz.Log(
                                "La mac adresse " + macAdresse +
                                " est inconnu de la freebox, on ne crée aucun dispositif."
                            )

                #Creation du device d'activation/désactivation du WIFI
                v_etatWIFI = f.isOnWIFI()
                Domoticz.Log("Etat WIFI : " + str(v_etatWIFI))
                keyunit = self.getOrCreateUnitIdForDevice(
                    self.DeviceType.deviceCommande, "WIFI")
                if (keyunit not in Devices):
                    v_dev = Domoticz.Device(Unit=keyunit,
                                            Name="WIFI On/Off",
                                            TypeName="Switch")
                    v_dev.Create()
                    Domoticz.Log("Création du dispositif " + "WIFI On/Off")
                self.updateDeviceIfExist(self.DeviceType.deviceCommande,
                                         "WIFI", v_etatWIFI, str(v_etatWIFI))
                #Creation du device de reboot du Freebox server
                #f.reboot()
                keyunit = self.getOrCreateUnitIdForDevice(
                    self.DeviceType.deviceCommande, "REBOOT")
                if (keyunit not in Devices):
                    v_dev = Domoticz.Device(Unit=keyunit,
                                            Name="Reboot Server",
                                            TypeName="Switch")
                    v_dev.Create()
                    Domoticz.Log("Création du dispositif " + "Reboot Server")

                #Test de connection WAN (Internet)
                constatus = f.constatus()
                Domoticz.Log("Etat connexion : " + str(constatus))
                keyunit = self.getOrCreateUnitIdForDevice(
                    self.DeviceType.deviceCommande, "WANStatus")
                if (keyunit not in Devices):
                    v_dev = Domoticz.Device(Unit=keyunit,
                                            Name="WAN Status",
                                            TypeName="Switch")
                    v_dev.Create()
                    Domoticz.Log("Création du dispositif " + "WAN Status")
                self.updateDeviceIfExist(self.DeviceType.deviceCommande,
                                         "WANStatus", constatus,
                                         str(constatus))

                DumpConfigToLog()
        except Exception as e:
            Domoticz.Log("OnStart error: " + str(e))
Ejemplo n.º 9
0
client2.username_pw_set(username, password)
client2.connect(mqttbroker, 1883, 60)


# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.

client2.loop_start()

app_id = "fr.freebox.dom" 
j = json.load(open("result_auth"))
app_token = str(j["result"]["app_token"]) # freebox don't like unicode

f = freebox.FbxApp(app_id,app_token)

cnx_reconnect = 100

while True:
    time.sleep(1)
    try:
	# reconnect if needed
        cnx_reconnect = cnx_reconnect - 1
        if cnx_reconnect < 0:
            f = freebox.FbxApp(app_id,app_token)
            cnx_reconnect = 100

	# query the box
	ap = f.com("/connection")['result']