Skip to content

RainLevelCharacteristic #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions accessory/eveatmo-rain-accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = function(pHomebridge) {
super(homebridge, accessoryConfig, netatmoDevice);
this.buildServices(accessoryConfig);

this.rainLevel = 0;
this.rainLevelSum1 = 0;
this.rainLevelSum24 = 0;

Expand Down Expand Up @@ -67,6 +68,9 @@ module.exports = function(pHomebridge) {
var result = {};
var dashboardData = accessoryData.dashboard_data;
if (dashboardData) {
if (dashboardData.hasOwnProperty("Rain")) {
result.rainLevel = Math.round(dashboardData.Rain * 1000) / 1000;
}
if (dashboardData.hasOwnProperty("sum_rain_1")) {
result.rainLevelSum1 = Math.round(dashboardData.sum_rain_1 * 1000) / 1000;
}
Expand All @@ -87,6 +91,10 @@ module.exports = function(pHomebridge) {
applyWeatherData(weatherData) {
var dataChanged = false;

if (weatherData.hasOwnProperty("rainLevel") && this.rainLevel != weatherData.rainLevel) {
this.rainLevel = weatherData.rainLevel;
dataChanged = true;
}
if (weatherData.hasOwnProperty("rainLevelSum1") && this.rainLevelSum1 != weatherData.rainLevelSum1) {
this.rainLevelSum1 = weatherData.rainLevelSum1;
dataChanged = true;
Expand Down
30 changes: 30 additions & 0 deletions service/eveatmo-rain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var homebridge;
var Characteristic;

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

Expand All @@ -12,6 +13,24 @@ module.exports = function(pHomebridge) {
homebridge = pHomebridge;
Characteristic = homebridge.hap.Characteristic;
}

class RainLevelCharacteristic extends Characteristic {
constructor(accessory) {
super('Rain Level', RAIN_LEVEL_CTYPE_ID);
this.setProps({
format: Characteristic.Formats.FLOAT,
unit: "mm",
minValue: 0,
maxValue: 1000,
minStep: 0.001,
perms: [
Characteristic.Perms.READ,
Characteristic.Perms.NOTIFY
]
});
this.value = this.getDefaultValue();
}
}

class RainLevelSum1Characteristic extends Characteristic {
constructor(accessory) {
Expand Down Expand Up @@ -54,6 +73,9 @@ module.exports = function(pHomebridge) {
super(accessory.name, RAIN_LEVEL_STYPE_ID);
this.accessory = accessory;

this.addCharacteristic(RainLevelCharacteristic)
.on('get', this.getRainLevel.bind(this))
.eventEnabled = true;
this.addCharacteristic(RainLevelSum1Characteristic)
.on('get', this.getRainLevelSum1.bind(this))
.eventEnabled = true;
Expand All @@ -63,12 +85,20 @@ module.exports = function(pHomebridge) {
}

updateCharacteristics() {
this.getCharacteristic(RainLevelCharacteristic)
.updateValue(this.accessory.rainLevel);
this.getCharacteristic(RainLevelSum1Characteristic)
.updateValue(this.accessory.rainLevelSum1);
this.getCharacteristic(RainLevelSum24Characteristic)
.updateValue(this.accessory.rainLevelSum24);
}

getRainLevel(callback) {
this.accessory.refreshData(function(err, data) {
callback(err, this.accessory.rainLevel);
}.bind(this));
}

getRainLevelSum1(callback) {
this.accessory.refreshData(function(err, data) {
callback(err, this.accessory.rainLevelSum1);
Expand Down