-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: version bump + history update added wind-sensor
- Loading branch information
Showing
6 changed files
with
335 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
'use strict'; | ||
|
||
var homebridge; | ||
var Characteristic; | ||
var NetatmoAccessory; | ||
var path = require('path'); | ||
|
||
module.exports = function(pHomebridge) { | ||
if (pHomebridge && !homebridge) { | ||
homebridge = pHomebridge; | ||
NetatmoAccessory = require("../lib/netatmo-accessory")(homebridge); | ||
Characteristic = homebridge.hap.Characteristic; | ||
} | ||
|
||
class EveatmoWindAccessory extends NetatmoAccessory { | ||
constructor(deviceData, netatmoDevice) { | ||
var accessoryConfig = { | ||
"id": deviceData._id, | ||
"model": "Eve Wind", | ||
"netatmoType": deviceData.type, | ||
"firmware": deviceData.firmware, | ||
"name": deviceData._name || "Eveatmo " + netatmoDevice.deviceType + " " + deviceData._id, | ||
"hasBattery": (deviceData.battery_vp) ? true : false, | ||
}; | ||
|
||
super(homebridge, accessoryConfig, netatmoDevice); | ||
this.buildServices(accessoryConfig); | ||
|
||
this.windStrength = 0.0; | ||
this.windAngle = 0; | ||
|
||
this.refreshData(function(err, data) {}); | ||
} | ||
|
||
buildServices(accessoryConfig) { | ||
var serviceDir = path.dirname(__dirname) + '/service'; | ||
try { | ||
var EveatmoWindService = require(serviceDir + '/eveatmo-wind')(homebridge); | ||
var serviceWind = new EveatmoWindService(this); | ||
serviceWind.isPrimaryService = true; | ||
this.addService(serviceWind); | ||
|
||
if (accessoryConfig.hasBattery) { | ||
var EveatmoBatteryService = require(serviceDir + '/eveatmo-battery')(homebridge); | ||
var serviceBattery = new EveatmoBatteryService(this); | ||
this.addService(serviceBattery); | ||
} | ||
|
||
} catch (err) { | ||
this.log.warn("Could not process service files for " + accessoryConfig.name); | ||
this.log.warn(err); | ||
this.log.warn(err.stack); | ||
} | ||
} | ||
|
||
notifyUpdate(deviceData) { | ||
var accessoryData = this.extractAccessoryData(deviceData); | ||
var weatherData = this.mapAccessoryDataToWeatherData(accessoryData); | ||
this.applyWeatherData(weatherData); | ||
} | ||
|
||
mapAccessoryDataToWeatherData(accessoryData) { | ||
var result = {}; | ||
var dashboardData = accessoryData.dashboard_data; | ||
if (dashboardData) { | ||
if (dashboardData.hasOwnProperty("WindStrength")) { | ||
result.windStrength = dashboardData.WindStrength; | ||
} | ||
if (dashboardData.hasOwnProperty("WindAngle")) { | ||
result.windAngle = dashboardData.WindAngle; | ||
} | ||
} | ||
|
||
result.batteryPercent = accessoryData.battery_percent; | ||
if (!result.batteryPercent) { | ||
result.batteryPercent = 100; | ||
} | ||
result.lowBattery = (result.batteryPercent <= 20) ? true : false; | ||
|
||
return result; | ||
} | ||
|
||
applyWeatherData(weatherData) { | ||
var dataChanged = false; | ||
|
||
if (weatherData.hasOwnProperty("windStrength") && this.windStrength != weatherData.windStrength) { | ||
this.windStrength = weatherData.windStrength; | ||
dataChanged = true; | ||
} | ||
if (weatherData.hasOwnProperty("windAngle") && this.windAngle != weatherData.windAngle) { | ||
this.windAngle = weatherData.windAngle; | ||
dataChanged = true; | ||
} | ||
|
||
if (weatherData.batteryPercent && this.batteryPercent != weatherData.batteryPercent) { | ||
this.batteryPercent = weatherData.batteryPercent; | ||
dataChanged = true; | ||
} | ||
if (weatherData.lowBattery && this.lowBattery != weatherData.lowBattery) { | ||
this.lowBattery = weatherData.lowBattery; | ||
dataChanged = true; | ||
} | ||
|
||
if (dataChanged) { | ||
this.getServices().forEach( | ||
function(svc) { | ||
var call = svc.updateCharacteristics && svc.updateCharacteristics(); | ||
} | ||
); | ||
} | ||
} | ||
} | ||
return EveatmoWindAccessory; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
'use strict'; | ||
|
||
var homebridge; | ||
var Characteristic; | ||
|
||
const WIND_MEASURE_STYPE_ID = "2AFB775E-79E5-4399-B3CD-398474CAE86C"; | ||
const WIND_STRENGTH_CTYPE_ID = "49C8AE5A-A3A5-41AB-BF1F-12D5654F9F41"; | ||
const WIND_ANGLE_CTYPE_ID = "46F1284C-1912-421B-82F5-EB75008B167E"; | ||
|
||
module.exports = function(pHomebridge) { | ||
if (pHomebridge && !homebridge) { | ||
homebridge = pHomebridge; | ||
Characteristic = homebridge.hap.Characteristic; | ||
} | ||
|
||
class WindStrengthCharacteristic extends Characteristic { | ||
constructor(accessory) { | ||
super('Wind Strength', WIND_STRENGTH_CTYPE_ID); | ||
this.setProps({ | ||
format: Characteristic.Formats.FLOAT, | ||
unit: "km/h", | ||
minValue: 0, | ||
maxValue: 100, | ||
minStep: 0.1, | ||
perms: [ | ||
Characteristic.Perms.READ, | ||
Characteristic.Perms.NOTIFY | ||
] | ||
}); | ||
this.value = this.getDefaultValue(); | ||
} | ||
} | ||
|
||
class WindAngleCharacteristic extends Characteristic { | ||
constructor(accessory) { | ||
super('Wind Angle', WIND_ANGLE_CTYPE_ID); | ||
this.setProps({ | ||
format: Characteristic.Formats.STRING, | ||
perms: [ | ||
Characteristic.Perms.READ, | ||
Characteristic.Perms.NOTIFY | ||
] | ||
}); | ||
this.value = this.getDefaultValue(); | ||
} | ||
} | ||
|
||
class WindService extends homebridge.hap.Service { | ||
constructor(accessory) { | ||
super(accessory.name + " Wind Sensor", WIND_MEASURE_STYPE_ID); | ||
this.accessory = accessory; | ||
|
||
this.addCharacteristic(WindStrengthCharacteristic) | ||
.on('get', this.getWindStrength.bind(this)) | ||
.eventEnabled = true; | ||
this.addCharacteristic(WindAngleCharacteristic) | ||
.on('get', this.getWindAngle.bind(this)) | ||
.eventEnabled = true; | ||
|
||
this.addOptionalCharacteristic(Characteristic.Name); | ||
} | ||
|
||
updateCharacteristics() { | ||
this.getCharacteristic(WindStrengthCharacteristic) | ||
.updateValue(this.accessory.windStrength); | ||
this.getCharacteristic(WindAngleCharacteristic) | ||
.updateValue(this.transformDirectionDegToString()); | ||
} | ||
|
||
getWindStrength(callback) { | ||
this.accessory.refreshData(function(err,data) { | ||
callback(err, this.accessory.windStrength); | ||
}.bind(this)); | ||
} | ||
|
||
getWindAngle(callback) { | ||
this.accessory.refreshData(function(err,data) { | ||
callback(err, this.transformDirectionDegToString()); | ||
}.bind(this)); | ||
} | ||
|
||
transformDirectionDegToString() { | ||
var a = this.accessory.windAngle; | ||
if (a >= 348.75 || a < 11.25) { | ||
return 'N'; | ||
} else if (a >= 11.25 && a < 33.75) { | ||
return 'NNE'; | ||
} else if (a >= 33.75 && a < 56.25) { | ||
return 'NE'; | ||
} else if (a >= 56.25 && a < 78.75) { | ||
return 'ENE'; | ||
} else if (a >= 78.75 && a < 101.25) { | ||
return 'E'; | ||
} else if (a >= 101.25 && a < 123.75) { | ||
return 'ESE'; | ||
} else if (a >= 123.75 && a < 146.25) { | ||
return 'SE'; | ||
} else if (a >= 146.25 && a < 168.75) { | ||
return 'SSE'; | ||
} else if (a >= 168.75 && a < 191.25) { | ||
return 'S'; | ||
} else if (a >= 191.25 && a < 213.75) { | ||
return 'SSW'; | ||
} else if (a >= 213.75 && a < 236.25) { | ||
return 'SW'; | ||
} else if (a >= 236.25 && a < 258.75) { | ||
return 'WSW'; | ||
} else if (a >= 258.75 && a < 281.25) { | ||
return 'W'; | ||
} else if (a >= 281.25 && a < 303.75) { | ||
return 'WNW'; | ||
} else if (a >= 303.75 && a < 326.25) { | ||
return 'NW'; | ||
} else if (a >= 326.25 && a < 348.75) { | ||
return 'NNW'; | ||
} | ||
} | ||
} | ||
|
||
return WindService; | ||
}; |