From f4e3e17032369c11c6f99c5ce84e70a1af4d271c Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 3 Jun 2022 15:59:28 +0200 Subject: [PATCH] Automatically turn lights on/off when brightness moves from/to 0 --- nymea-app/ui/components/BrightnessSlider.qml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/nymea-app/ui/components/BrightnessSlider.qml b/nymea-app/ui/components/BrightnessSlider.qml index 84a5a583..d9c783c7 100644 --- a/nymea-app/ui/components/BrightnessSlider.qml +++ b/nymea-app/ui/components/BrightnessSlider.qml @@ -46,6 +46,8 @@ Item { property int orientation: Qt.Horizontal + readonly property State powerState: thing ? thing.stateByName("power") : null + ActionQueue { id: actionQueue thing: root.thing @@ -96,13 +98,20 @@ Item { onPositionChanged: { var minCt = root.brightnessStateType.minValue; var maxCt = root.brightnessStateType.maxValue - var ct; + var brightness; if (root.orientation == Qt.Horizontal) { - ct = Math.min(maxCt, Math.max(minCt, (mouseX * (maxCt - minCt) / (width - dragHandle.width)) + minCt)) + brightness = Math.min(maxCt, Math.max(minCt, (mouseX * (maxCt - minCt) / (width - dragHandle.width)) + minCt)) } else { - ct = Math.min(maxCt, Math.max(minCt, ((height - mouseY) * (maxCt - minCt) / (height - dragHandle.height)) + minCt)) + brightness = Math.min(maxCt, Math.max(minCt, ((height - mouseY) * (maxCt - minCt) / (height - dragHandle.height)) + minCt)) } - actionQueue.sendValue(ct); + if (brightness > 0 && root.powerState && root.powerState.value === false) { + root.thing.executeAction("power", [{paramName: "power", value: true}]) + } + if (brightness === 0 && root.powerState && root.powerState.value === true) { + root.thing.executeAction("power", [{paramName: "power", value: false}]) + } + + actionQueue.sendValue(brightness); } } }