Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
#64 add remove listener for sensor devices
Browse files Browse the repository at this point in the history
  • Loading branch information
michbeck100 committed Mar 7, 2017
1 parent f176552 commit 8e276bc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions accessories/genericsensor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = (env) ->
.updateCharacteristic(Characteristic.CurrentTemperature, temperature)

@addBatteryStatus(device, @getService(Service.TemperatureSensor))
@addRemoveListener(device, @getService(Service.TemperatureSensor))

# some devices also measure humidity
if device.hasAttribute('humidity')
Expand All @@ -41,6 +42,7 @@ module.exports = (env) ->
.updateCharacteristic(Characteristic.CurrentRelativeHumidity, humidity)

@addBatteryStatus(device, @getService(Service.HumiditySensor))
@addRemoveListener(device, @getService(Service.HumiditySensor))

if device.hasAttribute('co2')
@addService(Service.CarbonDioxideSensor)
Expand All @@ -60,6 +62,8 @@ module.exports = (env) ->
@getService(Service.CarbonDioxideSensor)
.updateCharacteristic(Characteristic.CarbonDioxideLevel, co2)

@addRemoveListener(device, @getService(Service.CarbonDioxideSensor))


addBatteryStatus: (device, service) =>
if device.hasAttribute('lowBattery')
Expand All @@ -83,3 +87,8 @@ module.exports = (env) ->
if co2 > 1400
return Characteristic.CarbonDioxideDetected.CO2_LEVELS_ABNORMAL
return Characteristic.CarbonDioxideDetected.CO2_LEVELS_NORMAL

addRemoveListener: (device, service) =>
device.on 'remove', () =>
env.logger.debug 'removing device ' + device.name
@removeService(service)

0 comments on commit 8e276bc

Please sign in to comment.