Skip to content

Commit

Permalink
Update WsService.js
Browse files Browse the repository at this point in the history
- Add old Eve _Weather_ service to expose history for only temperature or temperature/humidity, see simont77/fakegato-history#75 (comment);
- Move _Last Updated_ and _Heartrate_ charactertistics to _Temperature Sensor_ service.
  • Loading branch information
ebaauw committed Sep 1, 2019
1 parent 89a3cbc commit b0864be
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions lib/WsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,35 @@ function windDirection (degrees) {
}

class WsService extends homebridgeLib.ServiceDelegate {
static get Weather () { return Weather }

static get Temperature () { return Temperature }

static get Humidity () { return Humidity }

static get AirPressure () { return AirPressure }
}

class Weather extends WsService {
constructor (
wsAccessory, params = {}, temperatureDelegate
) {
params.name = wsAccessory.name + ' Weather'
params.Service = wsAccessory.Services.eve.Weather
super(wsAccessory, params)
this.addCharacteristicDelegate({
key: 'temperature',
Characteristic: this.Characteristics.eve.CurrentTemperature,
unit: '°C',
silent: true,
value: temperatureDelegate.value
})
temperatureDelegate.on('didSet', (value) => {
this.values.temperature = value
})
}
}

class Temperature extends WsService {
constructor (wsAccessory, params = {}) {
params.name = wsAccessory.name + ' Temperature'
Expand All @@ -39,10 +61,23 @@ class Temperature extends WsService {
Characteristic: this.Characteristics.hap.TemperatureDisplayUnits,
value: this.Characteristics.hap.TemperatureDisplayUnits.CELSIUS
})
this.addCharacteristicDelegate({
key: 'lastupdated',
Characteristic: this.Characteristics.my.LastUpdated,
value: 'n/a'
})
this.addCharacteristicDelegate({
key: 'heartrate',
Characteristic: this.Characteristics.my.Heartrate,
props: { unit: 'min', minValue: 10, maxValue: 120, minStep: 10 },
value: 10
})
}

checkObservation (observation) {
this.values.temperature = Math.round(observation.main.temp * 10) / 10
this.values.lastupdated = String(new Date(moment.unix(observation.dt)))
.substr(0, 24)
}
}

Expand Down Expand Up @@ -101,16 +136,6 @@ class AirPressure extends WsService {
key: 'windSpeed',
Characteristic: this.Characteristics.eve.WindSpeed
})
this.addCharacteristicDelegate({
key: 'lastupdated',
Characteristic: this.Characteristics.my.LastUpdated
})
this.addCharacteristicDelegate({
key: 'heartrate',
Characteristic: this.Characteristics.my.Heartrate,
props: { unit: 'min', minValue: 10, maxValue: 120, minStep: 10 },
value: 10
})
}

checkObservation (observation) {
Expand All @@ -121,8 +146,6 @@ class AirPressure extends WsService {
this.values.visibility = Math.round(observation.visibility / 1000)
this.values.wind = windDirection(observation.wind.deg)
this.values.windSpeed = Math.round(observation.wind.speed * 36) / 10
this.values.lastupdated = String(new Date(moment.unix(observation.dt)))
.substr(0, 24)
}
}

Expand Down

0 comments on commit b0864be

Please sign in to comment.