[deconz] add ontime feature (#9914)

* 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>
This commit is contained in:
J-N-K 2021-01-24 16:27:56 +01:00 committed by GitHub
parent 3f13392180
commit 1c0da8367e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 2 deletions

View 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` |

View 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);

View 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 + '}';
}
}

View 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, () -> {

View 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>
@ -113,6 +117,7 @@
<channels>
<channel typeId="color" id="color"/>
<channel typeId="ct" id="color_temperature"/>
<channel typeId="ontime" id="ontime"/>
<channel id="alert" typeId="alert"></channel>
</channels>
@ -181,6 +186,12 @@
<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>