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

Commit

Permalink
feat: Support for magic cube
Browse files Browse the repository at this point in the history
Added support for Xiaomi magic cube. Pull request #6
  • Loading branch information
svrooij authored Dec 12, 2017
2 parents b1b9363 + 87f9cf5 commit c99109c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ function start () {
publishDeviceData(device, `(${device.isLeaking() ? 'leaking' : 'not_leaking'})`)
})
break
case 'cube':
publishDeviceData(device, 'unknown')
device.on('update', () => {
publishDeviceData(device, device.getStatus(), 0, device.getRotateDegrees())
})
break
}
})

Expand Down Expand Up @@ -176,14 +182,15 @@ function publishConnectionStatus () {
})
}

function publishDeviceData (device, newState, secSinceMotion = 0) {
function publishDeviceData (device, newState, secSinceMotion = 0, rotation = null) {
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 }
var topic = `${config.name}/status/${device.getType()}/${device.getSid()}`
log.info(`Publishing ${newState} to ${topic}`)
mqttClient.publish(topic,
Expand Down

0 comments on commit c99109c

Please sign in to comment.