diff --git a/lib/WsAccessory.js b/lib/WsAccessory.js index 36549c1..61003a2 100644 --- a/lib/WsAccessory.js +++ b/lib/WsAccessory.js @@ -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) @@ -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) })