Skip to content

Commit c100510

Browse files
authored
Merge pull request #54 from RyanHS7VM/CurrentRainLevel
RainLevelCharacteristic
2 parents 4231ffa + 647f4aa commit c100510

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

accessory/eveatmo-rain-accessory.js

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = function(pHomebridge) {
2626
super(homebridge, accessoryConfig, netatmoDevice);
2727
this.buildServices(accessoryConfig);
2828

29+
this.rainLevel = 0;
2930
this.rainLevelSum1 = 0;
3031
this.rainLevelSum24 = 0;
3132

@@ -67,6 +68,9 @@ module.exports = function(pHomebridge) {
6768
var result = {};
6869
var dashboardData = accessoryData.dashboard_data;
6970
if (dashboardData) {
71+
if (dashboardData.hasOwnProperty("Rain")) {
72+
result.rainLevel = Math.round(dashboardData.Rain * 1000) / 1000;
73+
}
7074
if (dashboardData.hasOwnProperty("sum_rain_1")) {
7175
result.rainLevelSum1 = Math.round(dashboardData.sum_rain_1 * 1000) / 1000;
7276
}
@@ -87,6 +91,10 @@ module.exports = function(pHomebridge) {
8791
applyWeatherData(weatherData) {
8892
var dataChanged = false;
8993

94+
if (weatherData.hasOwnProperty("rainLevel") && this.rainLevel != weatherData.rainLevel) {
95+
this.rainLevel = weatherData.rainLevel;
96+
dataChanged = true;
97+
}
9098
if (weatherData.hasOwnProperty("rainLevelSum1") && this.rainLevelSum1 != weatherData.rainLevelSum1) {
9199
this.rainLevelSum1 = weatherData.rainLevelSum1;
92100
dataChanged = true;

service/eveatmo-rain.js

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var homebridge;
44
var Characteristic;
55

66
const RAIN_LEVEL_STYPE_ID = "D92D5391-92AF-4824-AF4A-356F25F25EA1";
7+
const RAIN_LEVEL_CTYPE_ID = "C53F35CE-C615-4AA4-9112-EBF679C5EB14";
78
const RAIN_LEVEL_SUM_1H_CTYPE_ID = "10c88f40-7ec4-478c-8d5a-bd0c3cce14b7";
89
const RAIN_LEVEL_SUM_24H_CTYPE_ID = "ccc04890-565b-4376-b39a-3113341d9e0f";
910

@@ -12,6 +13,24 @@ module.exports = function(pHomebridge) {
1213
homebridge = pHomebridge;
1314
Characteristic = homebridge.hap.Characteristic;
1415
}
16+
17+
class RainLevelCharacteristic extends Characteristic {
18+
constructor(accessory) {
19+
super('Rain Level', RAIN_LEVEL_CTYPE_ID);
20+
this.setProps({
21+
format: Characteristic.Formats.FLOAT,
22+
unit: "mm",
23+
minValue: 0,
24+
maxValue: 1000,
25+
minStep: 0.001,
26+
perms: [
27+
Characteristic.Perms.READ,
28+
Characteristic.Perms.NOTIFY
29+
]
30+
});
31+
this.value = this.getDefaultValue();
32+
}
33+
}
1534

1635
class RainLevelSum1Characteristic extends Characteristic {
1736
constructor(accessory) {
@@ -54,6 +73,9 @@ module.exports = function(pHomebridge) {
5473
super(accessory.name, RAIN_LEVEL_STYPE_ID);
5574
this.accessory = accessory;
5675

76+
this.addCharacteristic(RainLevelCharacteristic)
77+
.on('get', this.getRainLevel.bind(this))
78+
.eventEnabled = true;
5779
this.addCharacteristic(RainLevelSum1Characteristic)
5880
.on('get', this.getRainLevelSum1.bind(this))
5981
.eventEnabled = true;
@@ -63,12 +85,20 @@ module.exports = function(pHomebridge) {
6385
}
6486

6587
updateCharacteristics() {
88+
this.getCharacteristic(RainLevelCharacteristic)
89+
.updateValue(this.accessory.rainLevel);
6690
this.getCharacteristic(RainLevelSum1Characteristic)
6791
.updateValue(this.accessory.rainLevelSum1);
6892
this.getCharacteristic(RainLevelSum24Characteristic)
6993
.updateValue(this.accessory.rainLevelSum24);
7094
}
7195

96+
getRainLevel(callback) {
97+
this.accessory.refreshData(function(err, data) {
98+
callback(err, this.accessory.rainLevel);
99+
}.bind(this));
100+
}
101+
72102
getRainLevelSum1(callback) {
73103
this.accessory.refreshData(function(err, data) {
74104
callback(err, this.accessory.rainLevelSum1);

0 commit comments

Comments
 (0)