-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
61 lines (48 loc) · 1.61 KB
/
index.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
"use strict"
const OsCommands = require('./commands')
let Service, Characteristic
module.exports = function (homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
homebridge.registerAccessory("homebridge-screen-standby", "ComputerScreen", ComputerScreen);
}
function ComputerScreen(log, config, api) {
this.log = log;
this.currentStatus = true
this.name = config["name"]
this.osType = config["osType"]
this.screenService = new Service.Switch(this.name);
this.screenService
.getCharacteristic(Characteristic.On)
.on('get', this.getSwitchOnCharacteristic.bind(this))
.on('set', this.setSwitchOnCharacteristic.bind(this));
}
ComputerScreen.prototype.getServices = function getServices() {
return [this.screenService]
}
ComputerScreen.prototype.getSwitchOnCharacteristic = function(next) {
const me = this
me.log(`Returned current state: ${me.currentStatus}`);
return next(null, me.currentStatus)
}
ComputerScreen.prototype.setSwitchOnCharacteristic = function (on, next) {
const me = this
let commands;
switch (this.osType) {
case 'windows':
commands = OsCommands.windows
break;
case 'mac':
default:
commands = OsCommands.mac
break;
}
me.log(`Set display to ${on ? 'on' : 'off'}`)
me.currentStatus = !me.currentStatus
if (!me.currentStatus) {
commands.turnOff()
} else {
commands.turnOn()
}
return next()
}