UI7 Plugin Migration

[quote=“futzle, post:37, topic:182574”]I found that a button on the UI7 dashboard for the Countdown Timer plugin was appearing in the log as service: undefined. This button didn’t have a Display variable (so it would never light up depending on a variable’s value), by design. In UI5 that was OK, but in UI7 the service ID comes from the “Display” section, not the “Command” section.

After adding

{ "ControlGroup": "1", "ControlType": "button", "top": 1, "left": 0, "Label": { "lang_tag": "cmd_set", "text": "Restart" }, "Display": { "Service": "urn:futzle-com:serviceId:CountdownTimer1", <== this line "Top": 20, "Left": 120, "Width": 80, "Height": 20 }, "Command": { "Service": "urn:futzle-com:serviceId:CountdownTimer1", "Action": "RestartTimer", "Parameters": [ ] } }, the button started working again.[/quote]

I wonder if this is only a problem if the tab is flagged top_navigation_tab? I have buttons on lower-level flash tabs that work without a Service entry in the Display block. Input controls also do not work when the tab is promoted so there is something different in the way the json is processed.

The second point was already identified by @RexBeckett.
The problem is that we need at least one flash tab with this flag to be able to rename the device or move it to another room, and as all my plugins have only one flash tab, that is a problem…

I just found the same problem when installing some of my plugins for testing. For some reason during installation CommFailure got set to “1” which caused an error to be constantly reported. Setting it to “0” fixed it. I have now included this in my implementation initialization code:

local commfail = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1","CommFailure", lul_device) or "0" if commfail ~= "0" then luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1","CommFailure", "0", lul_device) end

As guessed suggested yesterday, you should rather use luup.set_failure with false as parameter.

Yes that would be a cleaner solution. It seems to have the same effect.

Another unresolved problem that I’ve hit with two of my plugins that use serial connections… I’ve made a whizzbang JavaScript tab for letting users attach a serial (USB or IP) stream to the device. Screenshot is attached here for context.

The code that sets the IP variable is in an onchange attribute for the JavaScript fields:

var ipDevice = jQuery.grep(jsonp.ud.devices, function(o, i) { return o.id == deviceId; })[0]; ipDevice.ip = ipAddress + ":" + tcpPort;
This worked fine in UI5. The whole code is at J_SerialConnection.js in trunk – CurrentCost EnviR Energy Monitor

In UI7, assigning to jsonp.ud.devices[ x ].ip does not seem to stick. Even if I go straight from this tab over to Apps > Develop Apps > Serial Port Configuration > Reload Luup, it reverts back to its previous value, so users can’t make changes through the JavaScript tab.

I can’t tell if this is because of the changed semantics with SAVE/Reload in UI7 or because of changes in the read-write nature of jsonp.ud. The JavaScript API documentation doesn’t explain how to modify “special” variables for a device like IP or MAC address or Name or Room.

Question for Andrei or any other Vera employee: How do I set jsonp.ud.devices[ x ].ip from JavaScript and ensure that it is saved?

I think you need to call:

application.sendCommandSaveUserData()

Can someone attach the JSON file of the motion sensor (for example) to have a chance to discover how icons have now to be defined ?

Until now, I was able to keep one unique JSON file for UI5 and UI7. Is it still possible if I want to set an icon that will be taken into account in UI7 ?

Here you go.

MCV have not responded to my question about how to deal with the json differences between UI5 and UI7. I am using two different files and overwriting the UI5 one with the UI7 one on V1.7.xxx systems during plugin initialization. I hope that there will be a better solution at some point.

It is possible that you could include both types of icon handling in a single json and each UI version would use the tags it understands…

That was my idea. Did you not test this solution ?

Thank you for the file, I will take a look.

Did you not test this solution ?

My issues are with the whole device tile layout and the functionality of the input controls. If the only required change was for the icon processing I would have tried it. Until we have some fixes for other UI issues, I need to have separate jsons.

Unfortunately, “state_icons” has a total different format in UI5 and UI7. >:( They should have changed the tag name…

In the “img” tag, do you think we could use something like “…/Sonos.png” ? In this case, we could keep /www/cmh/skins/default/icons as the location for the icons, the same as for UI5.

[quote=“lolodomo, post:52, topic:182574”]Unfortunately, “state_icons” has a total different format in UI5 and UI7. >:( They should have changed the tag name…

In the “img” tag, do you think we could use something like “…/Sonos.png” ? In this case, we could keep /www/cmh/skins/default/icons as the location for the icons, the same as for UI5.[/quote]

It’s always hard to guess how flexible Vera’s json processing is. You’ll have to try it.

Meanwhile I discovered that, because I was renaming one of my plugin files, Vera was downloading a new copy on restarts. The new scheme checks the file size and overwrites the UI5 json if it is different but keeps the UI7 file:

if luup.version_major == 7 then useUI7json() end ... function useUI7json() local lfs = require "lfs" local ui5json = "/etc/cmh-ludl/D_MiLightWU1.json.lzo" local ui7json = "/etc/cmh-ludl/D_MiLightWU1_UI7.json.lzo" if lfs.attributes(ui7json,"size") ~= lfs.attributes(ui5json,"size") then os.execute('cp -p '..ui7json..' '.. ui5json) end end

I tried to mix UI5 and UI7 in the “state_icons” entry ! It seems to still work in UI5. I am waiting for a feedback in UI7.
Plus I tried to use relative path like “…/Sonos.png”.

@RexBeckett: did you try an icon with a WEB link ? I tried this but it seems it does not work in UI7:

"flashicon": "http://www.rfxcom.com/Content/Images/products/small/12103.jpg", "default_icon": "http://www.rfxcom.com/Content/Images/products/small/12103.jpg",

Regarding Ajax.Request, I suddenly discover that my code uses a global variable named “command_url” !

new Ajax.Request (command_url+'/data_request', {

Is it the right way to invoke Ajax.Request ? What is this variable “command_url” ?

I saw that nlrb has changed this like that in the Powermax plugin:

new Ajax.Request("../port_3480/data_request", { 

[quote=“lolodomo, post:55, topic:182574”]@RexBeckett: did you try an icon with a WEB link ? I tried this but it seems it does not work in UI7:

"flashicon": "http://www.rfxcom.com/Content/Images/products/small/12103.jpg", "default_icon": "http://www.rfxcom.com/Content/Images/products/small/12103.jpg",[/quote]

No I didn’t try calling a web-based icon. Another question for Andrei…

[quote=“lolodomo, post:56, topic:182574”]Regarding Ajax.Request, I suddenly discover that my code uses a global variable named “command_url” !

new Ajax.Request (command_url+'/data_request', {

Is it the right way to invoke Ajax.Request ? What is this variable “command_url” ?

I saw that nlrb has changed this like that in the Powermax plugin:

new Ajax.Request("../port_3480/data_request", { 

I’m also using command_url in some js code. It works fine on both UI5 and UI7. I think it is just pre-loaded with Vera’s IP and port.

For information, I was finally able to get icon and state incons working in UI7 with one unique JSON file common to UI5 and UI7 and with a unique location for the icons.

To keep compatibility with UI5, I will keep my icons in /www/cmh/skins/default/icons. Then in JSON file, a new line has to be added for UI7, something like this: “default_icon”: “…/…/…/icons/myPluginIcon.png”.

For state icons, apparently, it is allowed to mix UI5 content and UI7 content. For UI7, in the img tab, I set something like: “img”: “…/…/…/icons/myPluginStateIcon.png”.

It is working for the Sonos plugin.

Note that I discovered that my Sonos icons have disappeared. I don’t know if it is due to all the reset I was constrained to do, or if the upgrade is replacing the “icons” directory. Strangely, my DLNA icon was still present.

@RexBeckett; I have a plugin with a flash tab and 2 input fields. They seem to work well in 1.7.374. So the bug you mention with input fields could have been fixed in 1.7.374.