Page 1 of 1
device.setIcon does not update the UI instantly
Posted: Friday 31 July 2020 21:46
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?
Re: device.setIcon does not update the UI instantly [Solved]
Posted: Friday 31 July 2020 22:21
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
}
Re: device.setIcon does not update the UI instantly
Posted: Saturday 01 August 2020 8:05
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()
Re: device.setIcon does not update the UI instantly
Posted: Saturday 01 August 2020 8:22
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.
Re: device.setIcon does not update the UI instantly
Posted: Sunday 02 August 2020 22:10
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.