2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.loxone.internal.controls;
15 import static org.openhab.binding.loxone.internal.LxBindingConstants.*;
17 import java.math.BigDecimal;
19 import org.openhab.binding.loxone.internal.types.LxUuid;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.type.ChannelTypeUID;
24 import org.openhab.core.types.State;
25 import org.openhab.core.types.StateDescriptionFragmentBuilder;
28 * A timed switch type of control on Loxone Miniserver.
30 * According to Loxone API documentation, a switch control is:
32 * <li>a virtual input of switch type
33 * <li>a push button function block
36 * @author Stephan Brunner - initial contribution
39 class LxControlTimedSwitch extends LxControlPushbutton {
41 static class Factory extends LxControlInstance {
43 LxControl create(LxUuid uuid) {
44 return new LxControlTimedSwitch(uuid);
54 * deactivationDelay - countdown until the output is deactivated.
55 * 0 = the output is turned off
56 * -1 = the output is permanently on
57 * otherwise it will count down from deactivationDelayTotal
59 private static final String STATE_DEACTIVATION_DELAY = "deactivationdelay";
61 private LxControlTimedSwitch(LxUuid uuid) {
66 public void initialize(LxControlConfig config) {
67 super.initialize(config);
68 ChannelUID id = addChannel("Number", new ChannelTypeUID(BINDING_ID, MINISERVER_CHANNEL_TYPE_RO_NUMBER),
69 defaultChannelLabel + " / Deactivation Delay", "Deactivation Delay", null, null,
70 this::getDeactivationState);
71 addChannelStateDescriptionFragment(id,
72 StateDescriptionFragmentBuilder.create().withMinimum(new BigDecimal(-1)).withReadOnly(true).build());
75 private State getDeactivationState() {
76 Double deactivationValue = getStateDoubleValue(STATE_DEACTIVATION_DELAY);
77 if (deactivationValue != null) {
78 if (deactivationValue.equals(-1.0)) {
79 // we don't show the special value of -1 to the user, this means switch is on and delay is zero
80 deactivationValue = 0.0;
82 return new DecimalType(deactivationValue);
88 OnOffType getSwitchState() {
90 * 0 = the output is turned off
91 * -1 = the output is permanently on
92 * otherwise it will count down from deactivationDelayTotal
94 Double value = getStateDoubleValue(STATE_DEACTIVATION_DELAY);
96 if (value == -1.0 || value > 0.0) { // mapping
98 } else if (value == 0) {