We have moved at community.getvera.com

Author Topic: Checking the controller type in javascript file  (Read 399 times)

Offline reneboer

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1574
  • Karma: +110/-31
Checking the controller type in javascript file
« on: February 11, 2019, 12:19:37 pm »
Hi amg0,

In my plugin J_Harmony_UI7.js file that displays the Settings and other panels (so not the J_ALTUI_plugins.js equivalent) I want to know if the controller I am talking to is a Vera or openLuup so I can show/hide some settings as applicable to the target platform. I found how to check that the controller is UI5, but not seeing more options.
Code: [Select]
var controller = MultiBox.controllerOf(deviceObj.altuiid).controller;
var isUI5 = MultiBox.isUI5(controller);
But, how can I see it is openLuup vs. Vera. The same bit of javascript is loaded in ALTUI on openLuup for a local or briged device so I would like to see what I am talking to. Is there a clean way?

Cheers Rene
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline amg0

  • Moderator
  • Master Member
  • *****
  • Posts: 3174
  • Karma: +210/-8
Re: Checking the controller type in javascript file
« Reply #1 on: February 11, 2019, 12:28:26 pm »
Hi amg0,

In my plugin J_Harmony_UI7.js file that displays the Settings and other panels (so not the J_ALTUI_plugins.js equivalent) I want to know if the controller I am talking to is a Vera or openLuup so I can show/hide some settings as applicable to the target platform. I found how to check that the controller is UI5, but not seeing more options.
Code: [Select]
var controller = MultiBox.controllerOf(deviceObj.altuiid).controller;
var isUI5 = MultiBox.isUI5(controller);
But, how can I see it is openLuup vs. Vera. The same bit of javascript is loaded in ALTUI on openLuup for a local or briged device so I would like to see what I am talking to. Is there a clean way?

Cheers Rene

there is a method isOpenLuup on the VeraBox object so you can try ( not tested )
Code: [Select]
var controller = MultiBox.controllerOf(deviceObj.altuiid).controller;
return controller.isOpenLuup()

Offline reneboer

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1574
  • Karma: +110/-31
Re: Checking the controller type in javascript file
« Reply #2 on: February 12, 2019, 07:50:12 am »
Hi amgo,

I could not figure out how to get from the MultiBox to the VeraBox so the IsOpenLuup becomes available. MultiBox.controllerOf does not seem to return a VeraBox object, but just a number.

So, I thought I could take a shortcut assuming openluup always has version 1.7.0;
Code: [Select]
var udObj = api.getUserData();
if (udObj.BuildVersion === "*1.7.0*") { bControllerIsVera = false; }

But that does not work. It always thinks it runs on openLuup.

Cheers Rene
« Last Edit: February 12, 2019, 08:09:53 am by reneboer »
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline amg0

  • Moderator
  • Master Member
  • *****
  • Posts: 3174
  • Karma: +210/-8
Re: Checking the controller type in javascript file
« Reply #3 on: February 12, 2019, 10:27:29 am »
Hi amgo,

I could not figure out how to get from the MultiBox to the VeraBox so the IsOpenLuup becomes available. MultiBox.controllerOf does not seem to return a VeraBox object, but just a number.

So, I thought I could take a shortcut assuming openluup always has version 1.7.0;
Code: [Select]
var udObj = api.getUserData();
if (udObj.BuildVersion === "*1.7.0*") { bControllerIsVera = false; }

But that does not work. It always thinks it runs on openLuup.

Cheers Rene

yes it is a bit cumbersome but this should work
Code: [Select]
var altuiid = "0-2"   // example
var ctrnum = MultiBox.controllerOf( altuiid  ).controller 
MultiBox.getControllers()[  ctrnum  ].controller.isOpenLuup()


Offline reneboer

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1574
  • Karma: +110/-31
Re: Checking the controller type in javascript file
« Reply #4 on: February 12, 2019, 12:28:05 pm »
Hi amg0,

That still gives me the type of my local controller only and not the bridged. I now made the assumption that all bridged devices are Vera, but I know akbooer is making bridging to a second openLuup controller via the VeraBridge too. So now doing this:
Code: [Select]
var udObj = api.getUserData();
// We are running on openLuup locally, for now we assume if bridged then it is a Vera.
bControllerIsVera = !(Boolean((udObj.BuildVersion === "*1.7.0*") && (deviceObj.id_parent == 0)));

Cheers Rene
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline amg0

  • Moderator
  • Master Member
  • *****
  • Posts: 3174
  • Karma: +210/-8
Re: Checking the controller type in javascript file
« Reply #5 on: February 12, 2019, 12:51:14 pm »
Hi amg0,

That still gives me the type of my local controller only and not the bridged. I now made the assumption that all bridged devices are Vera, but I know akbooer is making bridging to a second openLuup controller via the VeraBridge too. So now doing this:
Code: [Select]
var udObj = api.getUserData();
// We are running on openLuup locally, for now we assume if bridged then it is a Vera.
bControllerIsVera = !(Boolean((udObj.BuildVersion === "*1.7.0*") && (deviceObj.id_parent == 0)));

Cheers Rene

ALTUI gives you the type of what it controls ( so tells you if the underlying platform it talks to is a vera or openluup )
but if you use a verabridge and you want to know if the bridged box is a vera or openluup, I would imagine this is a property that verabridge should expose as part of its own properties ( maybe as a variable of the device ? )

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: Checking the controller type in javascript file
« Reply #6 on: February 12, 2019, 01:35:21 pm »
...but if you use a verabridge and you want to know if the bridged box is a vera or openluup, I would imagine this is a property that verabridge should expose as part of its own properties ( maybe as a variable of the device ? )

If the VeraBridge variable RemotePort is /port_3480, then it's talking to a Vera, otherwise, it will be :3480 for openLuup.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline reneboer

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1574
  • Karma: +110/-31
Re: Checking the controller type in javascript file
« Reply #7 on: February 12, 2019, 03:51:18 pm »
Champs to the rescue again. Thanks I have a solution now  :)

Cheers Rene
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.