-
Notifications
You must be signed in to change notification settings - Fork 3
/
FakeOutlet.js
108 lines (83 loc) · 2.55 KB
/
FakeOutlet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Description: Acceccory Shim to use with homebridge https://github.com/nfarina/homebridge
// Copy this file into the folder: homebridge/accessories
/* config.json Example:
{
"bridge": {
"name": "Homebridge",
"username": "CC:22:3D:E3:CE:27",
"port": 51826,
"pin": "031-45-154"
},
"platforms": [],
"accessories": [
{
"accessory": "FakeOutlet",
"name": "fake_accessory"
},
]
}
*/
var Service = require("HAP-NodeJS").Service;
var Characteristic = require("HAP-NodeJS").Characteristic;
var request = require("request");
module.exports = {
accessory: FakeOutlet
}
'use strict';
function FakeOutlet(log, config) {
this.log = log;
this.name = config["name"];
this.Characteristic = {};
this.currentValue = {};
}
FakeOutlet.prototype = {
/**
* Characteristic.On
*/
getPowerState: function(callback) {
this.log("getPowerState: " + this.currentValue.On);
callback(null, this.currentValue.On);
},
setPowerState: function(boolvalue, callback) {
this.log("setPowerState: " + boolvalue);
this.currentValue.On = boolvalue;
callback();
},
/**
* Characteristic.OutletInUse
*/
getOutletInUse: function(callback) {
this.log('getOutletInUse');
callback(null,this.currentValue.OutletInUse); // true/false
},
setOutletInUse: null, // N/A
/**
* Accessory Information Identify
*/
identify: function(callback) {
this.log("Identify requested!");
callback(); // success
},
/**
* Services and Characteristics
*/
getServices: function() {
var informationService = new Service.AccessoryInformation();
informationService
.setCharacteristic(Characteristic.Manufacturer, "Fake Manufacturer")
.setCharacteristic(Characteristic.Model, "Fake Model")
.setCharacteristic(Characteristic.SerialNumber, "Fake Serial Number")
.setCharacteristic(Characteristic.Name, this.name);
var FakeOutletService = new Service.Outlet();
this.Characteristic.On = FakeOutletService
.getCharacteristic(Characteristic.On)
.on('get', this.getPowerState.bind(this))
.on('set', this.setPowerState.bind(this));
this.currentValue.On = false;
this.Characteristic.OutletInUse = FakeOutletService
.getCharacteristic(Characteristic.OutletInUse)
.on('get', this.getOutletInUse.bind(this));
this.currentValue.OutletInUse = true;
return [informationService, FakeOutletService];
}
};