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] Add Thing class & Get Thing(s) #132

Closed florian-h05 closed 2 years ago

florian-h05 commented 2 years ago

Closes #89.

Improvements

Testing

DO NOT USE ON PRODUCTION AS THIS MODIFIES A THING!!

const { things } = require('openhab');

const allThings = things.getThings();
console.info(allThings);
const astroThing = things.getThing('astro:moon:e66c230447', true);
console.info(astroThing);

const thing = allThings[0];

function analyzeThing (thing) {
  console.info('Bridge UID: ' + thing.bridgeUID);
  console.info('Thing label: ' + thing.label);
  console.info('Thing location: ' + thing.location);
  console.info('Thing sttaus: ' + thing.status);
  console.info('Thing detailed status: ' + thing.statusInfo);
  console.info('ThingTypeUID: ' + thing.thingTypeUID);
  console.info('Thing UID: ' + thing.uid);
  console.info('Thing is enabled: ' + thing.isEnabled);
}

analyzeThing(thing);

thing.setLabel('new label');
thing.setLocation('living room');
thing.setEnabled(false);

analyzeThing(thing);