Plugin Python :how update SignalLevel and BatteryLevel (and custumImage)

Python and python framework

Moderator: leecollings

Post Reply
zaraki673
Posts: 32
Joined: Thursday 19 January 2017 23:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Plugin Python :how update SignalLevel and BatteryLevel (and custumImage)

Post by zaraki673 »

Hi everybody!!

For a plugin, i need to update the BatteryLevel to devices in domoticz
To do it, i have update the UpdateDevice code like that :
before :

Code: Select all

def UpdateDevice(Unit, nValue, sValue):
	# Make sure that the Domoticz device still exists (they can be deleted) before updating it 
	if (Unit in Devices):
		if (Devices[Unit].nValue != nValue) or (Devices[Unit].sValue != sValue):
			Devices[Unit].Update(nValue, str(sValue))
			Domoticz.Log("Update "+str(nValue)+":'"+str(sValue)+"' ("+Devices[Unit].Name+")")
	return
after :

Code: Select all

def UpdateDeviceWithBattery(Unit, nValue, sValue, CustomImage, SignalLevel, BatteryLevel):
	# Make sure that the Domoticz device still exists (they can be deleted) before updating it 
	if (Unit in Devices):
		if (Devices[Unit].nValue != nValue) or (Devices[Unit].sValue != sValue) or (Devices[Unit].SignalLevel != SignalLevel) or (Devices[Unit].BatteryLevel != BatteryLevel) :
			Devices[Unit].Update(nValue, str(sValue),CustomImage, SignalLevel, BatteryLevel)
			Domoticz.Log("Update "+str(nValue)+":'"+str(sValue)+"' SignalLevel:"+str(SignalLevel)+" batteryLevel:'"+str(BatteryLevel)+"%' ("+Devices[Unit].Name+")")
	return
As you can see, i also update the CustumImage attribut, but i didn't find how to get it back from domoticz's DB, so i can't check if the value have change :cry:

If anyone know how to get it ...

thk's
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Plugin Python :how update SignalLevel and BatteryLevel (and custumImage)

Post by Dnpwwo »

@zaraki673,

At the end of the Device.Update() call the python framework reloads all the device details from the database for you and refreshes the Device object contents. This means that if the Device[Unit].Image is set to what you want, the database update was successful (although Device.Update() will return an error if it fails anyway).

If you are really worried you can call Device[Unit].Refresh() inside your plugin to manually force a device refresh but it shouldn't be required because all updates should be driven by the plugin itself.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
zaraki673
Posts: 32
Joined: Thursday 19 January 2017 23:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Plugin Python :how update SignalLevel and BatteryLevel (and custumImage)

Post by zaraki673 »

Sorry to answer so late,

Thank you for your answer, I undestand what you said, the only think i miss was 'Device[Unit].image' as customImage (name in DB).

now all seem to work fine :D
thks
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest