]> git.basschouten.com Git - openhab-addons.git/blob
9a20deaa3e260101010fac47161f7d926c972323
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.loxone.internal.controls;
14
15 import static org.openhab.binding.loxone.internal.LxBindingConstants.*;
16
17 import org.openhab.binding.loxone.internal.types.LxUuid;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.thing.type.ChannelTypeUID;
20 import org.openhab.core.types.State;
21 import org.openhab.core.types.UnDefType;
22
23 /**
24  * An InfoOnlyDigital type of control on Loxone Miniserver.
25  * <p>
26  * According to Loxone API documentation, this control covers digital virtual states only. This control does not send
27  * any commands to the Miniserver. It can be used to read a formatted representation of a digital virtual state.
28  *
29  * @author Pawel Pieczul - initial contribution
30  *
31  */
32 class LxControlInfoOnlyDigital extends LxControl {
33
34     static class Factory extends LxControlInstance {
35         @Override
36         LxControl create(LxUuid uuid) {
37             return new LxControlInfoOnlyDigital(uuid);
38         }
39
40         @Override
41         String getType() {
42             return "infoonlydigital";
43         }
44     }
45
46     /**
47      * InfoOnlyDigital has one state that can be on/off
48      */
49     private static final String STATE_ACTIVE = "active";
50
51     private LxControlInfoOnlyDigital(LxUuid uuid) {
52         super(uuid);
53     }
54
55     @Override
56     public void initialize(LxControlConfig config) {
57         super.initialize(config);
58         addChannel("Switch", new ChannelTypeUID(BINDING_ID, MINISERVER_CHANNEL_TYPE_RO_SWITCH), defaultChannelLabel,
59                 "Digital virtual state", tags, null, this::getChannelState);
60     }
61
62     private State getChannelState() {
63         Double value = getStateDoubleValue(STATE_ACTIVE);
64         if (value != null) {
65             if (value == 0) {
66                 return OnOffType.OFF;
67             } else if (value == 1.0) {
68                 return OnOffType.ON;
69             } else {
70                 return UnDefType.UNDEF;
71             }
72         }
73         return null;
74     }
75 }