Skip to content

Commit eba78a9

Browse files
authored
Update index.js
1 parent b80d420 commit eba78a9

File tree

1 file changed

+3
-36
lines changed

1 file changed

+3
-36
lines changed

index.js

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ function SshAccessory(log, config) {
1515
this.service = 'Switch';
1616

1717
this.name = config['name'];
18-
this.onCommand = config['on'];
19-
this.offCommand = config['off'];
20-
this.stateCommand = config['state'];
21-
this.onValue = config['on_value'] || "playing";
22-
this.onValue = this.onValue.trim().toLowerCase();
23-
this.exactMatch = config['exact_match'] || true;
18+
this.command = config['command'];
2419
this.ssh = assign({
2520
user: config['user'],
2621
host: config['host'],
@@ -29,22 +24,11 @@ function SshAccessory(log, config) {
2924
}, config['ssh']);
3025
}
3126

32-
SshAccessory.prototype.matchesString = function(match) {
33-
if(this.exactMatch) {
34-
return (match === this.onValue);
35-
}
36-
else {
37-
return (match.indexOf(this.onValue) > -1);
38-
}
39-
}
40-
4127
SshAccessory.prototype.setState = function(powerOn, callback) {
4228
var accessory = this;
4329
var state = powerOn ? 'on' : 'off';
44-
var prop = state + 'Command';
45-
var command = accessory[prop];
4630

47-
var stream = ssh(command, accessory.ssh);
31+
var stream = ssh(accessory.command, accessory.ssh);
4832

4933
stream.on('error', function (err) {
5034
accessory.log('Error: ' + err);
@@ -59,20 +43,7 @@ SshAccessory.prototype.setState = function(powerOn, callback) {
5943

6044
SshAccessory.prototype.getState = function(callback) {
6145
var accessory = this;
62-
var command = accessory['stateCommand'];
63-
64-
var stream = ssh(command, accessory.ssh);
65-
66-
stream.on('error', function (err) {
67-
accessory.log('Error: ' + err);
68-
callback(err || new Error('Error getting state of ' + accessory.name));
69-
});
70-
71-
stream.on('data', function (data) {
72-
var state = data.toString('utf-8').trim().toLowerCase();
73-
accessory.log('State of ' + accessory.name + ' is: ' + state);
74-
callback(null, accessory.matchesString(state));
75-
});
46+
callback(null);
7647
}
7748

7849
SshAccessory.prototype.getServices = function() {
@@ -87,9 +58,5 @@ SshAccessory.prototype.getServices = function() {
8758
var characteristic = switchService.getCharacteristic(Characteristic.On)
8859
.on('set', this.setState.bind(this));
8960

90-
if (this.stateCommand) {
91-
characteristic.on('get', this.getState.bind(this))
92-
};
93-
9461
return [switchService];
9562
}

0 commit comments

Comments
 (0)