Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EddyVerbruggen/18dc11c274a33f4334b8991373a64f99 to your computer and use it in GitHub Desktop.
Save EddyVerbruggen/18dc11c274a33f4334b8991373a64f99 to your computer and use it in GitHub Desktop.
NativeScript HomeKit - Listing Services and Characteristics
// import a few Classes we're gonna use
import { Accessory, Service, Characteristic } from 'nativescript-homekit';
// given an accessory..
let accessory: Accessory = myPreviouslyFoundAccessory;
// .. you can now list its services..
accessory.services.forEach((s: Service) => {
console.log(`Service ${s.name} of type ${s.type} has ${s.characteristics.length} characteristics`);
// .. and the service characteristics
s.characteristics.forEach((c: Characteristic) => {
console.log(`Characteristic ${c.description} is of type ${c.type}`);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment