]> git.basschouten.com Git - openhab-addons.git/commitdiff
[deconz] add ontime feature (#9914)
authorJ-N-K <J-N-K@users.noreply.github.com>
Sun, 24 Jan 2021 15:27:56 +0000 (16:27 +0100)
committerGitHub <noreply@github.com>
Sun, 24 Jan 2021 15:27:56 +0000 (16:27 +0100)
* add ontime

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
* Update bundles/org.openhab.binding.deconz/README.md

Co-authored-by: Fabian Wolter <github@fabian-wolter.de>
Co-authored-by: Fabian Wolter <github@fabian-wolter.de>
bundles/org.openhab.binding.deconz/README.md
bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java
bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/LightState.java
bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java
bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml

index 5ab188f5876a1743a6108967220660a8a096d4a7..ef762dfa51ecd077bc5ffcf3633d06a4c0626875 100644 (file)
@@ -170,6 +170,7 @@ Other devices support
 | effect            | String                   |     R/W     | Effect selection. Allowed commands are set dynamically                                  | `colorlight`                                    |
 | effectSpeed       | Number                   |     W       | Effect Speed                          | `colorlight`                                    |
 | lock              | Switch                   |     R/W     | Lock (ON) or unlock (OFF) the doorlock| `doorlock`                                      |                 
+| ontime            | Number:Time              |     W       | Timespan for which the light is turned on | all lights |
 | position          | Rollershutter            |     R/W     | Position of the blind                 | `windowcovering`                                |
 | heatsetpoint      | Number:Temperature       |     R/W     | Target Temperature in °C              | `thermostat`                                    |
 | valve             | Number:Dimensionless     |     R       | Valve position in %                   | `thermostat`                                    |
index 3d5cbc664dc8f06a26879a30c4cad8bdf7d45f2f..595f1716282f60fe371e7786e066fbffe9a033e0 100644 (file)
@@ -118,6 +118,7 @@ public class BindingConstants {
     public static final String CHANNEL_EFFECT = "effect";
     public static final String CHANNEL_EFFECT_SPEED = "effectSpeed";
     public static final String CHANNEL_SCENE = "scene";
+    public static final String CHANNEL_ONTIME = "ontime";
 
     // channel uids
     public static final ChannelTypeUID CHANNEL_EFFECT_TYPE_UID = new ChannelTypeUID(BINDING_ID, CHANNEL_EFFECT);
index cfcdd4f70db239533ce9ea91b9f85ba9b5bca0b1..5e9753bdbb8c6f0e660cf3b428cb5db55c12b2ba 100644 (file)
@@ -36,6 +36,7 @@ public class LightState {
     public @Nullable String colormode;
     public @Nullable String effect;
     public @Nullable Integer effectSpeed;
+    public @Nullable Integer ontime;
 
     // depending on the type of light
     public @Nullable Integer hue;
@@ -68,6 +69,7 @@ public class LightState {
         colormode = null;
         effect = null;
         effectSpeed = null;
+        ontime = null;
 
         hue = null;
         sat = null;
@@ -85,7 +87,7 @@ public class LightState {
     public String toString() {
         return "LightState{" + "reachable=" + reachable + ", on=" + on + ", bri=" + bri + ", alert='" + alert + '\''
                 + ", colormode='" + colormode + '\'' + ", effect='" + effect + '\'' + ", effectSpeed=" + effectSpeed
-                + ", hue=" + hue + ", sat=" + sat + ", ct=" + ct + ", xy=" + Arrays.toString(xy) + ", transitiontime="
-                + transitiontime + '}';
+                + ", ontime=" + ontime + ", hue=" + hue + ", sat=" + sat + ", ct=" + ct + ", xy=" + Arrays.toString(xy)
+                + ", transitiontime=" + transitiontime + '}';
     }
 }
index aaebcf0d0e4dafc4b73ec7916c0185bd36dd3081..81cce17040ed8338d309508deb009430c53119b1 100644 (file)
@@ -29,6 +29,7 @@ import org.openhab.binding.deconz.internal.dto.LightMessage;
 import org.openhab.binding.deconz.internal.dto.LightState;
 import org.openhab.binding.deconz.internal.types.ResourceType;
 import org.openhab.core.library.types.*;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingStatus;
@@ -78,6 +79,7 @@ public class LightThingHandler extends DeconzBaseThingHandler {
      */
     private LightState lightStateCache = new LightState();
     private LightState lastCommand = new LightState();
+    private int onTime = 0; // in 0.1s
     private String colorMode = "";
 
     // set defaults, we can override them later if we receive better values
@@ -124,6 +126,19 @@ public class LightThingHandler extends DeconzBaseThingHandler {
 
     @Override
     public void handleCommand(ChannelUID channelUID, Command command) {
+        if (channelUID.getId().equals(CHANNEL_ONTIME)) {
+            if (command instanceof QuantityType<?>) {
+                QuantityType<?> onTimeSeconds = ((QuantityType<?>) command).toUnit(Units.SECOND);
+                if (onTimeSeconds != null) {
+                    onTime = 10 * onTimeSeconds.intValue();
+                } else {
+                    logger.warn("Channel '{}' received command '{}', could not be converted to seconds.", channelUID,
+                            command);
+                }
+            }
+            return;
+        }
+
         if (command instanceof RefreshType) {
             valueUpdated(channelUID.getId(), lightStateCache);
             return;
@@ -255,6 +270,8 @@ public class LightThingHandler extends DeconzBaseThingHandler {
             // if light shall be off, no other commands are allowed, so reset the new light state
             newLightState.clear();
             newLightState.on = false;
+        } else if (newOn != null && newOn) {
+            newLightState.ontime = onTime;
         }
 
         sendCommand(newLightState, command, channelUID, () -> {
index d9fa43f26efc0bfefcf05c90d3b2b68bb1893331..4339cae2241fc8977cedab7cdbdb4cf6356245fb 100644 (file)
@@ -44,6 +44,7 @@
                <description>A light that can be turned on or off.</description>
                <channels>
                        <channel typeId="onoff" id="switch"/>
+                       <channel typeId="ontime" id="ontime"/>
                </channels>
 
                <representation-property>uid</representation-property>
@@ -60,6 +61,7 @@
                <category>Lightbulb</category>
                <channels>
                        <channel typeId="brightness" id="brightness"/>
+                       <channel typeId="ontime" id="ontime"/>
                        <channel id="alert" typeId="alert"></channel>
                </channels>
 
@@ -78,6 +80,7 @@
                <channels>
                        <channel typeId="brightness" id="brightness"/>
                        <channel typeId="ct" id="color_temperature"/>
+                       <channel typeId="ontime" id="ontime"/>
                        <channel id="alert" typeId="alert"></channel>
                </channels>
 
@@ -95,6 +98,7 @@
                <category>Lightbulb</category>
                <channels>
                        <channel typeId="color" id="color"/>
+                       <channel typeId="ontime" id="ontime"/>
                        <channel id="alert" typeId="alert"></channel>
                </channels>
 
                <channels>
                        <channel typeId="color" id="color"/>
                        <channel typeId="ct" id="color_temperature"/>
+                       <channel typeId="ontime" id="ontime"/>
                        <channel id="alert" typeId="alert"></channel>
                </channels>
 
                <state pattern="%d K" min="15" max="100000" step="100"/>
        </channel-type>
 
+       <channel-type id="ontime">
+               <item-type>Number:Time</item-type>
+               <label>On Time</label>
+               <description>Time that the light stays on before switched off automatically (0=forever)</description>
+       </channel-type>
+
        <channel-type id="effect">
                <item-type>String</item-type>
                <label>Effect Channel</label>