From 44088d626a9747f108fa04e2d64023c20145c237 Mon Sep 17 00:00:00 2001 From: Lars Finander Date: Mon, 31 Oct 2016 13:23:42 -0600 Subject: [PATCH] DVCSMP-2108 LIFX: Add devicewatch support -Fixed a color state issue introduced by previous PR -Fixed original LIFX setup state bug --- .../lifx-connect.src/lifx-connect.groovy | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/smartapps/smartthings/lifx-connect.src/lifx-connect.groovy b/smartapps/smartthings/lifx-connect.src/lifx-connect.groovy index 41f20ef..7a4afe7 100644 --- a/smartapps/smartthings/lifx-connect.src/lifx-connect.groovy +++ b/smartapps/smartthings/lifx-connect.src/lifx-connect.groovy @@ -381,38 +381,28 @@ def updateDevices() { selectors.add("${device.id}") if (!childDevice) { // log.info("Adding device ${device.id}: ${device.product}") - def data = [ - label: device.label, - level: Math.round((device.brightness ?: 1) * 100), - switch: device.power, - colorTemperature: device.color.kelvin - ] if (device.product.capabilities.has_color) { - data["color"] = colorUtil.hslToHex((device.color.hue / 3.6) as int, (device.color.saturation * 100) as int) - data["hue"] = device.color.hue / 3.6 - data["saturation"] = device.color.saturation * 100 - childDevice = addChildDevice(app.namespace, "LIFX Color Bulb", device.id, null, data) + childDevice = addChildDevice(app.namespace, "LIFX Color Bulb", device.id, null, ["label": device.label, "completedSetup": true]) } else { - childDevice = addChildDevice(app.namespace, "LIFX White Bulb", device.id, null, data) + childDevice = addChildDevice(app.namespace, "LIFX White Bulb", device.id, null, ["label": device.label, "completedSetup": true]) } - childDevice?.completedSetup = true - } else { - if (device.product.capabilities.has_color) { - sendEvent(name: "color", value: colorUtil.hslToHex((device.color.hue / 3.6) as int, (device.color.saturation * 100) as int)) - sendEvent(name: "hue", value: device.color.hue / 3.6) - sendEvent(name: "saturation", value: device.color.saturation * 100) - } - childDevice.sendEvent(name: "label", value: device.label) - childDevice.sendEvent(name: "level", value: Math.round((device.brightness ?: 1) * 100)) - childDevice.sendEvent(name: "switch.setLevel", value: Math.round((device.brightness ?: 1) * 100)) - childDevice.sendEvent(name: "switch", value: device.power) - childDevice.sendEvent(name: "colorTemperature", value: device.color.kelvin) - childDevice.sendEvent(name: "model", value: device.product.name) } + if (device.product.capabilities.has_color) { + childDevice.sendEvent(name: "color", value: colorUtil.hslToHex((device.color.hue / 3.6) as int, (device.color.saturation * 100) as int)) + childDevice.sendEvent(name: "hue", value: device.color.hue / 3.6) + childDevice.sendEvent(name: "saturation", value: device.color.saturation * 100) + } + childDevice.sendEvent(name: "label", value: device.label) + childDevice.sendEvent(name: "level", value: Math.round((device.brightness ?: 1) * 100)) + childDevice.sendEvent(name: "switch.setLevel", value: Math.round((device.brightness ?: 1) * 100)) + childDevice.sendEvent(name: "switch", value: device.power) + childDevice.sendEvent(name: "colorTemperature", value: device.color.kelvin) + childDevice.sendEvent(name: "model", value: device.product.name) + if (state.devices[device.id] == null) { // State missing, add it and set it to opposite status as current status to provoke event below - state.devices[device.id] = [online : !device.connected] + state.devices[device.id] = [online: !device.connected] } if (!state.devices[device.id]?.online && device.connected) {