Skip to content

Commit

Permalink
Update WsAccessory.js
Browse files Browse the repository at this point in the history
Proof of concept for Eve history, see simont77/fakegato-history#75 (comment):
- Don't expose _AIr Pressure Sensor_ service when `noPressure` or `noHumidity` is set;
- Don't expose _Humidity Sensor_ service when `noHumidity` is set;
- Expose _Weather_ service when `noPressure` or `noHumidity` is set.
  • Loading branch information
ebaauw committed Sep 1, 2019
1 parent b0864be commit 6fea31a
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions lib/WsAccessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,50 @@ class WsAccessory extends homebridgeLib.AccessoryDelegate {

this.resource = context.location
this.wsServices = {
temperature: new WsService.Temperature(this),
humidity: new WsService.Humidity(this),
pressure: new WsService.AirPressure(this)
temperature: new WsService.Temperature(this)
}
if (this.platform.config.noHumidity) {
// Temperature
this.wsServices.weather = new WsService.Weather(
this, {},
this.wsServices.temperature.characteristicDelegate('temperature')
)
this.wsServices.history = new homebridgeLib.ServiceDelegate.History.Weather(
this, params,
this.wsServices.temperature.characteristicDelegate('temperature')
)
} else {
this.wsServices.humidity = new WsService.Humidity(this)
if (this.platform.config.noPressure) {
// Temperature/Humidity
this.wsServices.weather = new WsService.Weather(
this, {},
this.wsServices.temperature.characteristicDelegate('temperature'),
this.wsServices.humidity.characteristicDelegate('humidity')
)
this.wsServices.history = new homebridgeLib.ServiceDelegate.History.Weather(
this, params,
this.wsServices.temperature.characteristicDelegate('temperature'),
this.wsServices.humidity.characteristicDelegate('humidity')
)
} else {
// Temperature/Humidity/Pressure
this.wsServices.pressure = new WsService.AirPressure(this)
this.wsServices.history = new homebridgeLib.ServiceDelegate.History.Weather(
this, params,
this.wsServices.temperature.characteristicDelegate('temperature'),
this.wsServices.humidity.characteristicDelegate('humidity'),
this.wsServices.pressure.characteristicDelegate('pressure')
)
}
}
this.wsServices.history = new homebridgeLib.ServiceDelegate.History.Weather(
this, params,
this.wsServices.temperature.characteristicDelegate('temperature'),
this.wsServices.humidity.characteristicDelegate('humidity'),
this.wsServices.pressure.characteristicDelegate('pressure')
)
setImmediate(() => {
this.emit('initialised')
})
}

heartbeat (beat) {
const heartrate = this.wsServices.pressure.values.heartrate * 60
const heartrate = this.wsServices.temperature.values.heartrate * 60
if (beat % heartrate === 1) {
this.platform.openweathermap.get(this.resource).then((response) => {
this.debug('%j', response)
Expand All @@ -58,9 +85,11 @@ class WsAccessory extends homebridgeLib.AccessoryDelegate {
this.error('OpenWeatherMap error: %j', response)
return
}
this.wsServices.temperature.checkObservation(response)
this.wsServices.humidity.checkObservation(response)
this.wsServices.pressure.checkObservation(response)
for (const id in this.wsServices) {
if (typeof this.wsServices[id].checkObservation === 'function') {
this.wsServices[id].checkObservation(response)
}
}
}).catch((err) => {
this.error(err)
})
Expand Down

0 comments on commit 6fea31a

Please sign in to comment.