Customize plugin for personal usage
This commit is contained in:
20
freebox.py
20
freebox.py
@@ -167,6 +167,24 @@ class FbxApp(FbxCnx):
|
|||||||
1 #on ne fait rien, on retourne une liste vide
|
1 #on ne fait rien, on retourne une liste vide
|
||||||
return retour
|
return retour
|
||||||
|
|
||||||
|
def xdslinfo(self):
|
||||||
|
retour = {}
|
||||||
|
try:
|
||||||
|
sys = self.com( "connection/xdsl/")
|
||||||
|
retour.update({str('Connexion Uptime'):str(sys["result"]["status"]["uptime"])})
|
||||||
|
retour.update({str('Atténuation Down'):str(sys["result"]["down"]["attn_10"]/10)})
|
||||||
|
retour.update({str('Marge de bruit Down'):str(sys["result"]["down"]["snr_10"]/10)})
|
||||||
|
retour.update({str('Débit Down'):str("%.3f"%(float(sys["result"]["down"]["maxrate"])/1024))})
|
||||||
|
retour.update({str('Attenuation Up'):str(sys["result"]["up"]["attn_10"]/10)})
|
||||||
|
retour.update({str('Marge de bruit Up'):str(sys["result"]["up"]["snr_10"]/10)})
|
||||||
|
retour.update({str('Débit Up'):str("%.3f"%(float(sys["result"]["up"]["maxrate"])/1024))})
|
||||||
|
except (urllib.error.HTTPError, urllib.error.URLError) as error:
|
||||||
|
Domoticz.Log('La Freebox semble indisponible : '+ error.msg)
|
||||||
|
except timeout:
|
||||||
|
1 #on ne fait rien, on retourne une liste vide
|
||||||
|
return retour
|
||||||
|
|
||||||
|
|
||||||
def sysinfo(self):
|
def sysinfo(self):
|
||||||
retour = {}
|
retour = {}
|
||||||
try:
|
try:
|
||||||
@@ -235,4 +253,4 @@ class FbxApp(FbxCnx):
|
|||||||
v_result = self.com( "system/reboot")
|
v_result = self.com( "system/reboot")
|
||||||
if not v_result['success']:
|
if not v_result['success']:
|
||||||
Domoticz.Log("Erreur lors du Reboot")
|
Domoticz.Log("Erreur lors du Reboot")
|
||||||
Domoticz.Log("Freebox Server en cours de reboot.")
|
Domoticz.Log("Freebox Server en cours de reboot.")
|
||||||
|
|||||||
95
plugin.py
95
plugin.py
@@ -27,6 +27,7 @@ class FreeboxPlugin:
|
|||||||
class DeviceType(Enum):
|
class DeviceType(Enum):
|
||||||
deviceTypeDisk = 'DiskDevice'
|
deviceTypeDisk = 'DiskDevice'
|
||||||
deviceSystemInfo = 'SystemInfoDevice'
|
deviceSystemInfo = 'SystemInfoDevice'
|
||||||
|
deviceConnectionInfo = 'ConnectionInfoDevice'
|
||||||
devicePresence = 'PresenceDevice'
|
devicePresence = 'PresenceDevice'
|
||||||
deviceCommande = 'Commande'
|
deviceCommande = 'Commande'
|
||||||
_fileNameDeviceMapping = 'devicemapping.json'
|
_fileNameDeviceMapping = 'devicemapping.json'
|
||||||
@@ -130,18 +131,27 @@ class FreeboxPlugin:
|
|||||||
for disk in usageDisk:
|
for disk in usageDisk:
|
||||||
keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceTypeDisk,disk)
|
keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceTypeDisk,disk)
|
||||||
if (keyunit not in Devices):
|
if (keyunit not in Devices):
|
||||||
v_dev = Domoticz.Device(Unit=keyunit, Name="Utilisation "+disk, TypeName="Percentage")
|
v_dev = Domoticz.Device(Unit=keyunit, Name="Utilisation "+disk, TypeName="Percentage", Used=1)
|
||||||
v_dev.Create()
|
v_dev.Create()
|
||||||
Domoticz.Log("Création du dispositif "+"Utilisation "+disk)
|
Domoticz.Log("Création du dispositif "+"Utilisation "+disk)
|
||||||
# Unfortunately the image in the Percentage device can not be changed. Use Custom device!
|
# 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()
|
# Domoticz.Device(Unit=_UNIT_USAGE, Name=Parameters["Address"], TypeName="Custom", Options={"Custom": "1;%"}, Image=3, Used=1).Create()
|
||||||
|
|
||||||
|
#Creation des device xdsl connection de la Freebox
|
||||||
|
#xdslinfo = f.xdslinfo()
|
||||||
|
#for info in xdslinfo:
|
||||||
|
# keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceConnectionInfo,info)
|
||||||
|
# if (keyunit not in Devices):
|
||||||
|
# v_dev = Domoticz.Device(Unit=keyunit, Name=info, TypeName="Custom", Image=101, Used=1)
|
||||||
|
# v_dev.Create()
|
||||||
|
# Domoticz.Log("Création du dispositif "+"Connection "+info)
|
||||||
|
|
||||||
#Creation des device infos systeme de la Freebox
|
#Creation des device infos systeme de la Freebox
|
||||||
sysinfo = f.sysinfo()
|
sysinfo = f.sysinfo()
|
||||||
for info in sysinfo:
|
for info in sysinfo:
|
||||||
keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceSystemInfo,info)
|
keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceSystemInfo,info)
|
||||||
if (keyunit not in Devices):
|
if (keyunit not in Devices):
|
||||||
v_dev = Domoticz.Device(Unit=keyunit, Name="System "+info, TypeName="Temperature")
|
v_dev = Domoticz.Device(Unit=keyunit, Name="System "+info, TypeName="Temperature", Used=1)
|
||||||
v_dev.Create()
|
v_dev.Create()
|
||||||
Domoticz.Log("Création du dispositif "+"System "+info)
|
Domoticz.Log("Création du dispositif "+"System "+info)
|
||||||
|
|
||||||
@@ -154,7 +164,7 @@ class FreeboxPlugin:
|
|||||||
if (name != None):
|
if (name != None):
|
||||||
keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.devicePresence,macAdresse)
|
keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.devicePresence,macAdresse)
|
||||||
if (keyunit not in Devices):
|
if (keyunit not in Devices):
|
||||||
v_dev = Domoticz.Device(Unit=keyunit, Name="Presence "+name, TypeName="Switch")
|
v_dev = Domoticz.Device(Unit=keyunit, Name=name, TypeName="Switch", Used=1)
|
||||||
v_dev.Create()
|
v_dev.Create()
|
||||||
Domoticz.Log("Création du dispositif "+"Presence "+name)
|
Domoticz.Log("Création du dispositif "+"Presence "+name)
|
||||||
else:
|
else:
|
||||||
@@ -203,10 +213,10 @@ class FreeboxPlugin:
|
|||||||
f.setOnOFFWifi(1)
|
f.setOnOFFWifi(1)
|
||||||
else:
|
else:
|
||||||
f.setOnOFFWifi(0)
|
f.setOnOFFWifi(0)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
#On remet à jour l'état du wifi suite à la modification
|
#On remet à jour l'état du wifi suite à la modification
|
||||||
v_etatWIFI = f.isOnWIFI()
|
v_etatWIFI = f.isOnWIFI()
|
||||||
self.updateDeviceIfExist(self.DeviceType.deviceCommande,"WIFI",v_etatWIFI, str(v_etatWIFI))
|
self.updateDeviceIfExist(self.DeviceType.deviceCommande,"WIFI",v_etatWIFI, str(v_etatWIFI))
|
||||||
|
|
||||||
keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceCommande,"REBOOT")
|
keyunit = self.getOrCreateUnitIdForDevice(self.DeviceType.deviceCommande,"REBOOT")
|
||||||
if (keyunit == Unit):
|
if (keyunit == Unit):
|
||||||
@@ -220,39 +230,46 @@ class FreeboxPlugin:
|
|||||||
Domoticz.Log("onDisconnect called")
|
Domoticz.Log("onDisconnect called")
|
||||||
|
|
||||||
def onHeartbeat(self):
|
def onHeartbeat(self):
|
||||||
Domoticz.Debug("onHeartbeat called")
|
try:
|
||||||
if self._lastExecution.minute == datetime.datetime.now().minute :
|
Domoticz.Debug("onHeartbeat called")
|
||||||
return
|
if self._lastExecution.minute == datetime.datetime.now().minute :
|
||||||
self._lastExecution = datetime.datetime.now()
|
return
|
||||||
if self.token == "" :
|
self._lastExecution = datetime.datetime.now()
|
||||||
Domoticz.Log("Pas de token défini.")
|
if self.token == "" :
|
||||||
return
|
Domoticz.Log("Pas de token défini.")
|
||||||
f=freebox.FbxApp("idPluginDomoticz",self.token,host=self.freeboxURL)
|
return
|
||||||
|
f=freebox.FbxApp("idPluginDomoticz",self.token,host=self.freeboxURL)
|
||||||
usageDisk = f.diskinfo()
|
|
||||||
for disk in usageDisk:
|
usageDisk = f.diskinfo()
|
||||||
self.updateDeviceIfExist(self.DeviceType.deviceTypeDisk,disk,int(float(usageDisk[disk])), str(usageDisk[disk]))
|
for disk in usageDisk:
|
||||||
|
self.updateDeviceIfExist(self.DeviceType.deviceTypeDisk,disk,int(float(usageDisk[disk])), str(usageDisk[disk]))
|
||||||
sysinfo = f.sysinfo()
|
|
||||||
for info in sysinfo:
|
sysinfo = f.sysinfo()
|
||||||
self.updateDeviceIfExist(self.DeviceType.deviceSystemInfo,info,int(float(sysinfo[info])), str(sysinfo[info]))
|
for info in sysinfo:
|
||||||
|
self.updateDeviceIfExist(self.DeviceType.deviceSystemInfo,info,int(float(sysinfo[info])), str(sysinfo[info]))
|
||||||
listeMacString = Parameters["Mode2"]
|
|
||||||
listeMac = listeMacString.split(";")
|
xdslinfo = f.xdslinfo()
|
||||||
for macAdresse in listeMac:
|
for info in xdslinfo:
|
||||||
name = f.getNameByMacAdresse(macAdresse)
|
self.updateDeviceIfExist(self.DeviceType.deviceConnectionInfo,info,int(float(xdslinfo[info])), str(xdslinfo[info]))
|
||||||
presence = 0
|
|
||||||
if (name != None):
|
listeMacString = Parameters["Mode2"]
|
||||||
if(f.isPresenceByMacAdresse(macAdresse)):
|
listeMac = listeMacString.split(";")
|
||||||
presence = 1
|
for macAdresse in listeMac:
|
||||||
self.updateDeviceIfExist(self.DeviceType.devicePresence,macAdresse,presence, str(presence))
|
name = f.getNameByMacAdresse(macAdresse)
|
||||||
|
presence = 0
|
||||||
lanPeriph = f.lanPeripherique()
|
if (name != None):
|
||||||
for periph in lanPeriph:
|
if(f.isPresenceByMacAdresse(macAdresse)):
|
||||||
Domoticz.Debug(lanPeriph[periph]+" ("+periph+") présent")
|
presence = 1
|
||||||
|
self.updateDeviceIfExist(self.DeviceType.devicePresence,macAdresse,presence, str(presence*100))
|
||||||
|
|
||||||
|
lanPeriph = f.lanPeripherique()
|
||||||
|
for periph in lanPeriph:
|
||||||
|
Domoticz.Debug(lanPeriph[periph]+" ("+periph+") présent")
|
||||||
|
|
||||||
v_etatWIFI = f.isOnWIFI()
|
v_etatWIFI = f.isOnWIFI()
|
||||||
self.updateDeviceIfExist(self.DeviceType.deviceCommande,"WIFI",v_etatWIFI, str(v_etatWIFI))
|
self.updateDeviceIfExist(self.DeviceType.deviceCommande,"WIFI",v_etatWIFI, str(v_etatWIFI))
|
||||||
|
except:
|
||||||
|
Domoticz.Debug("onHeartbeat failed (exception)...")
|
||||||
|
|
||||||
global _plugin
|
global _plugin
|
||||||
_plugin = FreeboxPlugin()
|
_plugin = FreeboxPlugin()
|
||||||
|
|||||||
Reference in New Issue
Block a user