From 8cb22efb833ce957a32080b4dbe3c8237f6433ec Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Tue, 1 Mar 2016 00:25:05 -0800 Subject: [PATCH] Add a example to use "identify" event --- example-plugins/homebridge-samplePlatform/index.js | 8 +++++++- lib/platformAccessory.js | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/example-plugins/homebridge-samplePlatform/index.js b/example-plugins/homebridge-samplePlatform/index.js index a7f1a8b..f3d3ba0 100644 --- a/example-plugins/homebridge-samplePlatform/index.js +++ b/example-plugins/homebridge-samplePlatform/index.js @@ -74,6 +74,10 @@ SamplePlatform.prototype.configureAccessory = function(accessory) { // accessory.updateReachability() accessory.reachable = true; + accessory.on('identify', function() { + console.log("Identify!!!"); + }); + if (accessory.getService(Service.Lightbulb)) { accessory.getService(Service.Lightbulb) .getCharacteristic(Characteristic.On) @@ -178,7 +182,9 @@ SamplePlatform.prototype.addAccessory = function(accessoryName) { uuid = UUIDGen.generate(accessoryName); var newAccessory = new Accessory(accessoryName, uuid); - + newAccessory.on('identify', function() { + console.log("Identify!!!"); + }); // Plugin can save context on accessory // To help restore accessory in configureAccessory() // newAccessory.context.something = "Something" diff --git a/lib/platformAccessory.js b/lib/platformAccessory.js index a3d8f61..cbb882e 100644 --- a/lib/platformAccessory.js +++ b/lib/platformAccessory.js @@ -2,6 +2,8 @@ var uuid = require("hap-nodejs").uuid; var Accessory = require("hap-nodejs").Accessory; var Service = require("hap-nodejs").Service; var Characteristic = require("hap-nodejs").Characteristic; +var inherits = require('util').inherits; +var EventEmitter = require('events').EventEmitter; 'use strict'; @@ -33,6 +35,8 @@ function PlatformAccessory(displayName, UUID, category) { .setCharacteristic(Characteristic.SerialNumber, "Default-SerialNumber"); } +inherits(PlatformAccessory, EventEmitter); + PlatformAccessory.prototype.addService = function(service) { // service might be a constructor like `Service.AccessoryInformation` instead of an instance // of Service. Coerce if necessary.