openhab / org.openhab.ui.habpanel

OUTDATED repo - HABPanel has moved to the openhab-webui repo!
https://github.com/openhab/openhab-webui
Eclipse Public License 1.0
97 stars 93 forks source link

Automatic image refresh does not work #342

Open sidamos opened 5 years ago

sidamos commented 5 years ago

I have an image widget with an openHAB String item which contains a snapshot url for my Nest camera and I have set auto refresh to 60 seconds.

Instead of refreshing the image, I get this in the browser console: vendor.js:119 TypeError: Cannot read property 'indexOf' of undefined at image.widget.js:70 at n (vendor.js:108) at m.$eval (vendor.js:147) at m.$digest (vendor.js:144) at m.$apply (vendor.js:147) at vendor.js:109

When I enable No Cachebusting, then I don't get an error in the browser console, but the image goes black after 60 seconds.

Using openHAB 2.4.0. Tested on newest Chrome version on Linux and Android.

sidamos commented 5 years ago

I did further testing and auto refresh does work if I use the Nest URL as a static URL instead of from an openHAB String Item.

For an example on how the image URL looks like (I deleted some chars here and there, so that it does not really work with my camera):

https://www.dropcam.com/api/wwn.get_snapshot/CjYtbXFPZXFVDaXp6eWJoOENHcEJKWEhqWE5Nb2Q2ZlBsTlZo4Z2x6YjVsNWhYcamcSFjdCejZHSHFtdXV4ZzlKUmlweUZVY1EaNm1SSlFPWjlVMHNxNnoweW5GMkhCLWsyOGE5NWdxRTWI5ZF83YnI2MTRLX25rQ2FCNERlQQ?auth=462ZAS4JeGb7hg6yK3siAVwiiz-xTomCKQKEUnVJ5BLB5ANy_a-7fcwF3ysEVMOyjGDY0tgJR_rrtQSvTl_P7JYVnl4QYzJRpttyqKAOAf41nyB7DjZ9_RW62fNFJ1Bh_VTz4qOBrEEABfNdtdmAkTE1sRq_F2hE0TZB9l7M0C80dY0mf3W3upZfXaM-3ns

ghys commented 5 years ago

Looks like vm.original_url could indeed be undefined. https://github.com/openhab/org.openhab.ui.habpanel/blob/7fbdf026e18656ede362351d44267bce844e665b/web/app/widgets/image/image.widget.js#L70 Since it's only defined here - only for static urls: https://github.com/openhab/org.openhab.ui.habpanel/blob/7fbdf026e18656ede362351d44267bce844e665b/web/app/widgets/image/image.widget.js#L58-L60 This was introduced in #143. I think the rationale at the time was that if you're specifying a String item, you're responsible for autoupdating it via rules instead of relying on the widget's autoupdate. Nonetheless, it's still a bug.

sidamos commented 5 years ago

At the moment, I am using a time triggered rule as a workaround, but it is very hacky:

rule "Nest Snapshot Refresh" when Time cron "0 0/5 * ?" // every 5 minutes then var orig = FrontDoorCameraNestHello_Camera_SnapshotURL.state.toString FrontDoorCameraNestHello_Camera_SnapshotURL.sendCommand("/static/black.jpg") Thread::sleep(500) FrontDoorCameraNestHello_Camera_SnapshotURL.sendCommand(orig) end

It is necessary to really change the URL and the sleep is also necessary, otherwise it won't update.

LuckyMallari commented 5 years ago

I will check if we can add input validation on the widget configuration when I get on a PC.