forked from fredan75/worx-landroid-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
landroid-cloud2domoticz.js
79 lines (68 loc) · 2.63 KB
/
landroid-cloud2domoticz.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
var config = require('./config'); // Read configuration
const LandroidCloud = require("./landroid-cloud");
var landroid = new LandroidCloud(config);
const Domoticz = require('./domoticz');
const AlertLevel = Domoticz.AlertLevel;
const domoticz = new Domoticz(config);
var mqttBrokerUrl = config.mqttBrokerUrl;
if(mqttBrokerUrl && mqttBrokerUrl.indexOf("//") > 0) {
var address = mqttBrokerUrl.substring(mqttBrokerUrl.indexOf("//") + 2);
var port = 1883; // Assume default MQTT port
if(address.indexOf(":") > 0) {
var colon = address.indexOf(":");
port = parseInt(address.substring(colon + 1));
address = address.substring(0, colon);
}
domoticz.initHardware("MQTT for Landroid", address, port);
}
else
console.error("Cannot automatically create Domoticz hardware for MQTT URL: " + mqttBrokerUrl);
var updateListener = function (status) {
if(status) { // We got some data from the Landroid
// Send data to Domoticz
domoticz.setAlert(status.errorMessage ? AlertLevel.RED : AlertLevel.GRAY,
status.errorMessage ? status.errorMessage : status.state);
/* TODO
switch (status.state) {
case LandroidState.ALARM:
domoticz.setAlert(AlertLevel.RED, status.errorMessage ? status.errorMessage : "[Alarm]");
break;
case LandroidState.CHARGING:
domoticz.setAlert(AlertLevel.GREEN, "Charging");
break;
case LandroidState.CHARGING_COMPLETE:
domoticz.setAlert(AlertLevel.GRAY, "Charging complete");
break;
case LandroidState.MOWING:
domoticz.setAlert(AlertLevel.YELLOW, "Mowing");
break;
case LandroidState.GOING_HOME:
domoticz.setAlert(AlertLevel.YELLOW, "Going home");
break;
case LandroidState.MANUAL_STOP:
domoticz.setAlert(AlertLevel.ORANGE, "Manual stop");
break;
case LandroidState.ERROR:
domoticz.setAlert(AlertLevel.ORANGE, "ERROR!");
break;
default:
console.error("Unknown state: " + status.state);
*/
// Send data to Domoticz
domoticz.setNoOfAlarms(status.noOfAlarms);
// domoticz.setBatteryPercentage(status.batteryPercentage);
domoticz.setTotalMowingHours(status.totalMowingHours);
}
else {
domoticz.setError("Error getting update!");
console.error("Error getting update!");
}
};
domoticz.initDevices(function() { // Detect or auto create devices
console.info("You can now navigate to " + config.domoticzUrl + "/#/Utility to see your Landroid status");
var landroid = new Landroid(config);
domoticz.connect(function () { // Connect to MQTT
console.log("Connected to Domoticz MQTT, connect to Landroid MQTT");
landroid.init(updateListener);
});
});