Page 1 of 1

Device.Update does not work for Options?

Posted: Wednesday 10 January 2018 21:32
by Xorfor
I am working on a plugin, where I retrieve a value in seconds. I want to display this value in seconds, minutes, hours or days, depending on the retrieved value. So I create a device with:

Code: Select all

Domoticz.Device(Unit=1, Name="Time", TypeName="Custom", Options={"Custom": "1;sec"}).Create()
In the plugin, I get the value (1800) and have piece of code like:

Code: Select all

if fnumber >= 60:
   fnumber = round(fnumber / 60, 2)
   UpdateDeviceOptions(1, {"Custom": "1;min"})
The function called is:

Code: Select all

def UpdateDeviceOptions(Unit, Options={}):
    Devices[Unit].Update(nValue=Devices[Unit].nValue, sValue=Devices[Unit].sValue, Options=Options)
    Domoticz.Debug("Update options " + Devices[Unit].Name + ": " + str(Options))
In the log, I see:

Code: Select all

2018-01-10 21:12:37.096 (Test) Update options Test - Time: {'Custom': '1;min'}
But in the web interface I see the time value (1800/60 = 30) in minutes but still with the units 'sec'.
In the documentation (http://www.domoticz.com/wiki/Developing ... in#Devices) is described that Options can be updated, but that doesn't work?

Re: Device.Update does not work for Options?

Posted: Wednesday 10 January 2018 21:48
by Dnpwwo
@Xorfor,

As far as I know the Options update does work (or used to). That said, Domoticz may not work as you expect for what you are doing.

I would suggest a couple of things:
  • Have a look directly in the database to see if the Hardware's Options field has changed (pretty sure it will)
  • Try navigating to a different tab and then back to where your device is shown. That should reload the devices and might fix it.
  • Try restarting t Domoticz to see if it changes
Domoticz tends to hold some details in memory rather than reading from the database all the time, we may need to trigger a refresh somewhere to make this work properly.

Re: Device.Update does not work for Options?

Posted: Wednesday 10 January 2018 22:04
by Xorfor
@Dnpwwo,

Thnx for your fast response!
I changed tabs, refreshed the browser, restarted Domoticz, but that did not help.
I added a debug line:

Code: Select all

if fnumber >= 60:
   fnumber = round(fnumber / 60, 2)
   UpdateDeviceOptions(1, {"Custom": "1;min"})
   Domoticz.Debug("Device Options:   " + str(Devices[1].Options))
   
But got in the log:

Code: Select all

2018-01-10 21:57:57.819 (Test) Update options Test - Time: {'Custom': '1;min'} 
2018-01-10 21:57:57.819 (Test) Device Options: {'Custom': '1;sec'} 
So not update :(

Re: Device.Update does not work for Options?

Posted: Wednesday 10 January 2018 22:27
by Xorfor
I just installed 'DB Browser' from Portable Apps and found out that the file domoticz.db is a sqllite database ;) . In the table DeviceStatus, I also see '1;sec'.

PS
Never looked in this database, but I see some other possibilities :idea:

Re: Device.Update does not work for Options?

Posted: Sunday 14 January 2018 1:28
by Dnpwwo
@Xorfor,

I think this is an oversight.

Custom devices handle the Options field differently to everything else (for some bizzare reason) so they need to be handled separately. The device Create code handles both cases, the Update only handles non-Custom devices.

I pushed an update in to the development branch to sort this out, will be in a beta soon.

Re: Device.Update does not work for Options?

Posted: Sunday 14 January 2018 11:39
by Xorfor
@Dnpwwo,

I just did an update to 3.8806. Now the options are updated, but...

they are all set to "0" (I looked in the database). Not only in the device where I call my UpdateOptions procedure, but also in all custom devices!
A device created with ', Options={"Custom": "1;MB"}' will appear with '0 Mb', but after an update I see eg. '10' (without the units MB).

Strange that a Custom device has a different update. I expect the same update for all devices.

Would also be a nice feature to be able to change images in non Custom devices :)

Re: Device.Update does not work for Options?

Posted: Monday 15 January 2018 13:06
by Dnpwwo
@Xorfor,

Pushed the fix for the update (after doing better testing :oops: )

You can already set the device image for any device in the plugin framework, the problem is that some device types ignore the image setting in the Domoticz web pages. Basically, any device where you can select the image in the web UI will work if the framework sets the image.

Re: Device.Update does not work for Options?

Posted: Monday 15 January 2018 20:24
by Xorfor
@Dnpwwo,

Yeaaahh, it works! Thanks! :D