From: J-N-K Date: Sun, 24 Jan 2021 15:27:56 +0000 (+0100) Subject: [deconz] add ontime feature (#9914) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=1c0da8367e8d2924c92fc1c091471ab36f28f99a;p=openhab-addons.git [deconz] add ontime feature (#9914) * add ontime Signed-off-by: Jan N. Klug * Update bundles/org.openhab.binding.deconz/README.md Co-authored-by: Fabian Wolter Co-authored-by: Fabian Wolter --- diff --git a/bundles/org.openhab.binding.deconz/README.md b/bundles/org.openhab.binding.deconz/README.md index 5ab188f587..ef762dfa51 100644 --- a/bundles/org.openhab.binding.deconz/README.md +++ b/bundles/org.openhab.binding.deconz/README.md @@ -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` | diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java index 3d5cbc664d..595f171628 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/BindingConstants.java @@ -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); diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/LightState.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/LightState.java index cfcdd4f70d..5e9753bdbb 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/LightState.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/dto/LightState.java @@ -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 + '}'; } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java index aaebcf0d0e..81cce17040 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/LightThingHandler.java @@ -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, () -> { diff --git a/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml b/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml index d9fa43f26e..4339cae224 100644 --- a/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml +++ b/bundles/org.openhab.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml @@ -44,6 +44,7 @@ A light that can be turned on or off. + uid @@ -60,6 +61,7 @@ Lightbulb + @@ -78,6 +80,7 @@ + @@ -95,6 +98,7 @@ Lightbulb + @@ -113,6 +117,7 @@ + @@ -181,6 +186,12 @@ + + Number:Time + + Time that the light stays on before switched off automatically (0=forever) + + String