Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

Commit

Permalink
fix: added lux from motion sensor
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
Stephan van Rooij committed Feb 4, 2018
1 parent c4866b7 commit 8b12167
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ function start () {
})
break
case 'motion':
publishDeviceData(device, `(${device.hasMotion() ? 'motion' : 'no_motion'})`)
publishDeviceData(device, `(${device.hasMotion() ? 'motion' : 'no_motion'})`, {lux: device.getLux()})
device.on('motion', () => {
publishDeviceData(device, 'motion')
publishDeviceData(device, 'motion', {lux: device.getLux()})
})
device.on('noMotion', () => {
publishDeviceData(device, 'no_motion', device.getSecondsSinceMotion())
publishDeviceData(device, 'no_motion', { secondsSinceMotion: device.getSecondsSinceMotion(), lux: device.getLux() })
})
break
case 'sensor':
Expand All @@ -140,7 +140,7 @@ function start () {
case 'cube':
publishDeviceData(device, 'unknown')
device.on('update', () => {
publishDeviceData(device, device.getStatus(), 0, device.getRotateDegrees())
publishDeviceData(device, device.getStatus(), {rotation: device.getRotateDegrees()})
})
break
}
Expand Down Expand Up @@ -187,15 +187,15 @@ function publishConnectionStatus () {
})
}

function publishDeviceData (device, newState, secSinceMotion = 0, rotation = null) {
function publishDeviceData (device, newState, extraData = {}) {
let data = {
val: newState, // Using val according to the MQTT Smarthome specs.
battery: device.getBatteryPercentage(),
name: getFriendlyName(device.getSid()),
ts: Date.now()
}
if (secSinceMotion > 0) { data.secondsSinceMotion = secSinceMotion }
if (rotation) { data.rotation = rotation }

Object.assign(data, extraData)
var topic = `${config.name}/status/${device.getType()}/${device.getSid()}`
log.info(`Publishing ${newState} to ${topic}`)
mqttClient.publish(topic,
Expand Down

0 comments on commit 8b12167

Please sign in to comment.