openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

[things] Member bridgeUID doesn't seem correct #207

Closed jlaur closed 1 year ago

jlaur commented 1 year ago

This piece of code:

var thing = things.getThing('hue:0830:home:foh3');
console.log("bridge uid: " + thing.bridgeUID);

produces this output:

2022-12-27 00:20:43.160 [INFO ] [enhab.automation.script.file.test.js] - bridge uid: undefined

Expected Behavior

I would have expected "hue:bridge:home", since this is the UID of the thing's bridge.

Current Behavior

See above.

Possible Solution

I'm wondering if this is correct:

https://github.com/openhab/openhab-js/blob/3ba66731eee99bd8d875745ced3e6e330b3b5ab7/things/things.js#L39-L48

According to documentation, the bridge's UID, not its ID, should be returned. Furthermore, when comparing with:

https://github.com/openhab/openhab-js/blob/3ba66731eee99bd8d875745ced3e6e330b3b5ab7/things/things.js#L85-L90

it seems toString() is missing?

So perhaps it should actually be:

   /** 
    * Thing's bridge UID as `String` 
    */ 
   get bridgeUID () { 
     try { 
       return this.rawThing.getBridgeUID().toString(); 
     } catch (error) { 
       // Thing has no bridge 
     } 
   } 

Steps to Reproduce

See above.

Context

Creating new rules to monitor when Zigbee devices are unreachable.

Your Environment

openHAB 3.4

florian-h05 commented 1 year ago

Seems like you are right, I‘ll check that tomorrow.

florian-h05 commented 1 year ago

@jlaur I've fixed this, just follow the installation guide in the README to install the latest version.

jlaur commented 1 year ago

@florian-h05 - after switching to latest version in openHABian, I don't see any change. That would probably require a new release?

florian-h05 commented 1 year ago

Oh sorry, I was not clear enough. The openHABian option installs the latest release, I am planning one in the near future, but there are a few things to do until then. I meant that you can install the main branch, just follow the manual installation section here: https://github.com/openhab/openhab-js#custom-installation