Customize plugin for personal usage
This commit is contained in:
95
plugin.py
95
plugin.py
@@ -27,6 +27,7 @@ class FreeboxPlugin:
|
||||
class DeviceType(Enum):
|
||||
deviceTypeDisk = 'DiskDevice'
|
||||
deviceSystemInfo = 'SystemInfoDevice'
|
||||
deviceConnectionInfo = 'ConnectionInfoDevice'
|
||||
devicePresence = 'PresenceDevice'
|
||||
deviceCommande = 'Commande'
|
||||
_fileNameDeviceMapping = 'devicemapping.json'
|
||||
@@ -130,18 +131,27 @@ class FreeboxPlugin:
|
||||
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 = Domoticz.Device(Unit=keyunit, Name="Utilisation "+disk, TypeName="Percentage", Used=1)
|
||||
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 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
|
||||
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 = Domoticz.Device(Unit=keyunit, Name="System "+info, TypeName="Temperature", Used=1)
|
||||
v_dev.Create()
|
||||
Domoticz.Log("Création du dispositif "+"System "+info)
|
||||
|
||||
@@ -154,7 +164,7 @@ class FreeboxPlugin:
|
||||
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 = Domoticz.Device(Unit=keyunit, Name=name, TypeName="Switch", Used=1)
|
||||
v_dev.Create()
|
||||
Domoticz.Log("Création du dispositif "+"Presence "+name)
|
||||
else:
|
||||
@@ -203,10 +213,10 @@ class FreeboxPlugin:
|
||||
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))
|
||||
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):
|
||||
@@ -220,39 +230,46 @@ class FreeboxPlugin:
|
||||
Domoticz.Log("onDisconnect called")
|
||||
|
||||
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")
|
||||
try:
|
||||
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]))
|
||||
|
||||
xdslinfo = f.xdslinfo()
|
||||
for info in xdslinfo:
|
||||
self.updateDeviceIfExist(self.DeviceType.deviceConnectionInfo,info,int(float(xdslinfo[info])), str(xdslinfo[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*100))
|
||||
|
||||
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))
|
||||
v_etatWIFI = f.isOnWIFI()
|
||||
self.updateDeviceIfExist(self.DeviceType.deviceCommande,"WIFI",v_etatWIFI, str(v_etatWIFI))
|
||||
except:
|
||||
Domoticz.Debug("onHeartbeat failed (exception)...")
|
||||
|
||||
global _plugin
|
||||
_plugin = FreeboxPlugin()
|
||||
|
||||
Reference in New Issue
Block a user