Device.Update does not work for Options?

Python and python framework
Post Reply
User avatar
Xorfor
Posts: 45
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Device.Update does not work for Options?

Post by Xorfor » Wednesday 10 January 2018 22:32

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?

User avatar
Dnpwwo
Posts: 657
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Device.Update does not work for Options?

Post by Dnpwwo » Wednesday 10 January 2018 22:48

@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.
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

User avatar
Xorfor
Posts: 45
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Device.Update does not work for Options?

Post by Xorfor » Wednesday 10 January 2018 23:04

@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 :(

User avatar
Xorfor
Posts: 45
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Device.Update does not work for Options?

Post by Xorfor » Wednesday 10 January 2018 23:27

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:

User avatar
Dnpwwo
Posts: 657
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Device.Update does not work for Options?

Post by Dnpwwo » Sunday 14 January 2018 2:28

@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.
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

User avatar
Xorfor
Posts: 45
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Device.Update does not work for Options?

Post by Xorfor » Sunday 14 January 2018 12:39

@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 :)

User avatar
Dnpwwo
Posts: 657
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Device.Update does not work for Options?

Post by Dnpwwo » Monday 15 January 2018 14:06

@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.
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

User avatar
Xorfor
Posts: 45
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Device.Update does not work for Options?

Post by Xorfor » Monday 15 January 2018 21:24

@Dnpwwo,

Yeaaahh, it works! Thanks! :D

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests