|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +varhomebridge; |
| 4 | +varCharacteristic; |
| 5 | + |
| 6 | +constATMOSPHERIC_PRESSURE_STYPE_ID="B77831FD-D66A-46A4-B66D-FD7EE8DFE3CE"; |
| 7 | +//Elgato |
| 8 | +constATMOSPHERIC_PRESSURE_CTYPE_ID="E863F10F-079E-48FF-8F27-9C2605A29F52"; |
| 9 | +//const ATMOSPHERIC_PRESSURE_CTYPE_ID = "28FDA6BC-9C2A-4DEA-AAFD-B49DB6D155AB"; |
| 10 | + |
| 11 | +/* |
| 12 | +const ATMOSPHERIC_PRESSURE_STYPE_ID = "B77831FD-D66A-46A4-B66D-FD7EE8DFE3CE"; |
| 13 | +const ATMOSPHERIC_PRESSURE_CTYPE_ID = "28FDA6BC-9C2A-4DEA-AAFD-B49DB6D155AB"; |
| 14 | +var EVE_WEATHER_SERVICE_STYPE_ID = 'E863F001-079E-48FF-8F27-9C2605A29F52'; |
| 15 | +var EVE_AIR_PRESSURE_CTYPE_ID = "E863F10F-079E-48FF-8F27-9C2605A29F52"; |
| 16 | +*/ |
| 17 | + |
| 18 | +module.exports=function(pHomebridge){ |
| 19 | +if(pHomebridge&&!homebridge){ |
| 20 | +homebridge=pHomebridge; |
| 21 | +Characteristic=homebridge.hap.Characteristic; |
| 22 | +} |
| 23 | + |
| 24 | +classAtmosphericPressureCharacteristicextendsCharacteristic{ |
| 25 | +constructor(accessory){ |
| 26 | +super('Atmospheric Pressure',ATMOSPHERIC_PRESSURE_CTYPE_ID); |
| 27 | +this.setProps({ |
| 28 | +format:Characteristic.Formats.UINT8, |
| 29 | +unit:"hPA", |
| 30 | +minValue:500, |
| 31 | +maxValue:2000, |
| 32 | +minStep:0.1, |
| 33 | +perms:[ |
| 34 | +Characteristic.Perms.READ, |
| 35 | +Characteristic.Perms.NOTIFY |
| 36 | +] |
| 37 | +}); |
| 38 | +this.value=this.getDefaultValue(); |
| 39 | +} |
| 40 | +} |
| 41 | + |
| 42 | +classAirPressureServiceextendshomebridge.hap.Service{ |
| 43 | +constructor(accessory){ |
| 44 | +super(accessory.name+" Air Pressure",ATMOSPHERIC_PRESSURE_STYPE_ID); |
| 45 | +this.accessory=accessory; |
| 46 | + |
| 47 | +this.addCharacteristic(AtmosphericPressureCharacteristic) |
| 48 | +.on('get',this.getAtmosphericPressure.bind(this)) |
| 49 | +.eventEnabled=true; |
| 50 | + |
| 51 | +// this.addOptionalCharacteristic(Characteristic.StatusActive); |
| 52 | +// this.addOptionalCharacteristic(Characteristic.StatusFault); |
| 53 | +this.addOptionalCharacteristic(Characteristic.Name); |
| 54 | + |
| 55 | +} |
| 56 | + |
| 57 | +updateCharacteristics(){ |
| 58 | +this.getCharacteristic(AtmosphericPressureCharacteristic) |
| 59 | +.updateValue(this.accessory.airPressure); |
| 60 | +} |
| 61 | + |
| 62 | +getAtmosphericPressure(callback){ |
| 63 | +this.accessory.refreshData(function(err,data){ |
| 64 | +callback(err,this.accessory.airPressure); |
| 65 | +}.bind(this)); |
| 66 | +} |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | +returnAirPressureService; |
| 71 | +} |