Customize plugin for personal usage
This commit is contained in:
18
freebox.py
18
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:
|
||||||
|
|||||||
25
plugin.py
25
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:
|
||||||
@@ -220,6 +230,7 @@ class FreeboxPlugin:
|
|||||||
Domoticz.Log("onDisconnect called")
|
Domoticz.Log("onDisconnect called")
|
||||||
|
|
||||||
def onHeartbeat(self):
|
def onHeartbeat(self):
|
||||||
|
try:
|
||||||
Domoticz.Debug("onHeartbeat called")
|
Domoticz.Debug("onHeartbeat called")
|
||||||
if self._lastExecution.minute == datetime.datetime.now().minute :
|
if self._lastExecution.minute == datetime.datetime.now().minute :
|
||||||
return
|
return
|
||||||
@@ -237,6 +248,10 @@ class FreeboxPlugin:
|
|||||||
for info in sysinfo:
|
for info in sysinfo:
|
||||||
self.updateDeviceIfExist(self.DeviceType.deviceSystemInfo,info,int(float(sysinfo[info])), str(sysinfo[info]))
|
self.updateDeviceIfExist(self.DeviceType.deviceSystemInfo,info,int(float(sysinfo[info])), str(sysinfo[info]))
|
||||||
|
|
||||||
|
xdslinfo = f.xdslinfo()
|
||||||
|
for info in xdslinfo:
|
||||||
|
self.updateDeviceIfExist(self.DeviceType.deviceConnectionInfo,info,int(float(xdslinfo[info])), str(xdslinfo[info]))
|
||||||
|
|
||||||
listeMacString = Parameters["Mode2"]
|
listeMacString = Parameters["Mode2"]
|
||||||
listeMac = listeMacString.split(";")
|
listeMac = listeMacString.split(";")
|
||||||
for macAdresse in listeMac:
|
for macAdresse in listeMac:
|
||||||
@@ -245,7 +260,7 @@ class FreeboxPlugin:
|
|||||||
if (name != None):
|
if (name != None):
|
||||||
if(f.isPresenceByMacAdresse(macAdresse)):
|
if(f.isPresenceByMacAdresse(macAdresse)):
|
||||||
presence = 1
|
presence = 1
|
||||||
self.updateDeviceIfExist(self.DeviceType.devicePresence,macAdresse,presence, str(presence))
|
self.updateDeviceIfExist(self.DeviceType.devicePresence,macAdresse,presence, str(presence*100))
|
||||||
|
|
||||||
lanPeriph = f.lanPeripherique()
|
lanPeriph = f.lanPeripherique()
|
||||||
for periph in lanPeriph:
|
for periph in lanPeriph:
|
||||||
@@ -253,6 +268,8 @@ class FreeboxPlugin:
|
|||||||
|
|
||||||
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