]> git.basschouten.com Git - openhab-addons.git/blob
28470a1f5ab1223eebf1cc8aafac84b537886cb4
[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 java.io.IOException;
16
17 import org.openhab.binding.loxone.internal.types.LxUuid;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.types.Command;
20
21 /**
22  * A pushbutton type of control on Loxone Miniserver.
23  * <p>
24  * According to Loxone API documentation, a pushbutton control covers virtual input of type pushbutton
25  *
26  * @author Pawel Pieczul - initial contribution
27  *
28  */
29 class LxControlPushbutton extends LxControlSwitch {
30
31     static class Factory extends LxControlInstance {
32         @Override
33         LxControl create(LxUuid uuid) {
34             return new LxControlPushbutton(uuid);
35         }
36
37         @Override
38         String getType() {
39             return "pushbutton";
40         }
41     }
42
43     /**
44      * Command string used to set control's state to ON and OFF (tap)
45      */
46     private static final String CMD_PULSE = "Pulse";
47
48     LxControlPushbutton(LxUuid uuid) {
49         super(uuid);
50     }
51
52     @Override
53     void handleSwitchCommands(Command command) throws IOException {
54         if (command instanceof OnOffType onOffCommand) {
55             if (onOffCommand == OnOffType.ON) {
56                 sendAction(CMD_PULSE);
57             } else {
58                 off();
59             }
60         }
61     }
62 }