device.setIcon does not update the UI instantly  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
aBjerris
Posts: 16
Joined: Wednesday 01 May 2019 16:32
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sweden
Contact:

device.setIcon does not update the UI instantly

Post by aBjerris »

Version: 2020.2 (build 12230)
Platform: Raspberry Pi
Plugin/Hardware: N/A

Description:
I'm trying to use the setIcon function in a simple dzVents script in order to change the icon of a dummy selection switch.

Code: Select all

return {
	on = {
		devices = {
			'Larmstatus'
		}
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
		domoticz.log('Larmstatus: ' .. device.state)
		if device.state == 'Utlöst' then
		    device.setIcon(13)
		end
	end
}
After SetIcon function is called nothing happens.
If I trigger the script a second time or refresh the browser the icon is changed.

Any idea how to work around the problem?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: device.setIcon does not update the UI instantly  [Solved]

Post by waaren »

aBjerris wrote: Friday 31 July 2020 21:46 I'm trying to use the setIcon function in a simple dzVents script in order to change the icon of a dummy selection switch.

If I trigger the script a second time or refresh the browser the icon is changed.
Any idea how to work around the problem?
Workaround could look like:

Code: Select all

return {
    on = {
        devices = {
            'Larmstatus'
        }
    },
    execute = function(domoticz, device)
        domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
        domoticz.log('Larmstatus: ' .. device.state)
        if device.state == 'Utlöst' then
            device.setIcon(13)
            device.switchSelector(device.level).afterSec(2).silent()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
aBjerris
Posts: 16
Joined: Wednesday 01 May 2019 16:32
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sweden
Contact:

Re: device.setIcon does not update the UI instantly

Post by aBjerris »

Thanks for the suggestion.
I improved it by skipping the "afterSec(2)". Then there is an instant refresh of the UI.

Code: Select all

device.setIcon(13)
device.switchSelector(device.level).silent()
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: device.setIcon does not update the UI instantly

Post by waaren »

aBjerris wrote: Saturday 01 August 2020 8:05 I improved it by skipping the "afterSec(2)". Then there is an instant refresh of the UI.
That might not work in all cases. The setIcon() is handled via the queued domoticz API mechanism and switchSelector() is handled via the commandArray() mechanism. There can be situations where a small delay is required to ensure the setIcon call is finished before the switchSelector is executed.
It depends on how busy the system is in other threads. As it is just to force the GUI to show the newly set Icon, the delay does not really matter and is a simple safeguard for such situations.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
aBjerris
Posts: 16
Joined: Wednesday 01 May 2019 16:32
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sweden
Contact:

Re: device.setIcon does not update the UI instantly

Post by aBjerris »

Ok. I see. Maybe someone find the time to fix the issue so no workaround is needed. In my use case where the input comes from a triggered alarm a 2 second delay does not have any impact on the user experience so I can use the delay. Thanks for the clarifcation.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest