This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
homematic.js
76 lines (64 loc) · 2.23 KB
/
homematic.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
"use strict";
class Homematic {
constructor (host) {
this.host = host;
this.DECREASING = 0;
this.INCREASING = 1;
this.STOPPED = 2;
}
getState (channel, callback) {
this.getValue(channel, "STATE", function (error, response) {
const isPowerOn = response == "true";
if(callback) callback(error, isPowerOn);
});
}
setState (channel, value, callback) {
const powerOn = value ? "true" : "false";
this.setValue(channel, "STATE", value, callback);
}
isLevelOn (channel, callback) {
this.getValue(channel, "LEVEL", function (error, response) {
const isPowerOn = parseFloat(response) > 0;
if(callback) callback(error, isPowerOn);
});
}
getLevel (channel, callback) {
this.getValue(channel, "LEVEL", function (error, response) {
let value = parseFloat(response) * 100;
if(callback) callback(error, value);
});
}
setLevel (channel, value, callback) {
let levelString;
if (typeof value == "boolean") {
levelString = value ? "1" : "0";
} else if (typeof value == "string" || typeof value == "number") {
levelString = (parseFloat(value) / 100).toString();
}
this.setValue(channel, "LEVEL", levelString, callback);
}
getTargetTemperature (channel, callback) {
this.getValue(channel, "SET_TEMPERATURE", callback);
}
setTargetTemperature (channel, value, callback) {
this.setValue(channel, "SET_TEMPERATURE", value, callback);
}
getCurrentTemperature (channel, callback) {
this.getValue(channel, "ACTUAL_TEMPERATURE", callback);
}
getWindowCoveringPositionState (channel, callback) {
this.getValue(channel, "DIRECTION", function (error, response) {
let positionState = this.STOPPED;
switch (response) {
case 1:
positionState = this.INCREASING;
break;
case 2:
positionState = this.DECREASING;
break;
}
if(callback) callback(error, positionState);
});
}
}
module.exports = Homematic;