2 * Copyright (c) 2010-2022 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.nikohomecontrol.internal.protocol.nhc2;
15 import static org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.nikohomecontrol.internal.protocol.NhcAction;
20 import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlCommunication;
21 import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlConstants.ActionType;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * The {@link NhcAction2} class represents the action Niko Home Control II communication object. It contains all fields
27 * representing a Niko Home Control action and has methods to trigger the action in Niko Home Control and receive action
30 * @author Mark Herwege - Initial Contribution
33 public class NhcAction2 extends NhcAction {
35 private final Logger logger = LoggerFactory.getLogger(NhcAction2.class);
37 private volatile boolean booleanState;
39 private String technology;
41 NhcAction2(String id, String name, String model, String technology, ActionType type, @Nullable String location,
42 NikoHomeControlCommunication nhcComm) {
43 super(id, name, type, location, nhcComm);
45 this.technology = technology;
49 * Get on/off state of action.
51 * true for on, false for off
53 * @return action on/off state
55 boolean booleanState() {
60 public int getState() {
61 return booleanState ? state : 0;
65 * Sets on/off state of action.
67 * @param state - boolean false for on, true for off
69 public void setBooleanState(boolean state) {
71 if (getType().equals(ActionType.DIMMER)) {
73 // only send stored brightness value if on
90 * Sets state of action. This version is used for Niko Home Control II.
92 * @param state - The allowed values depend on the action type.
93 * switch action: 0 or 100
94 * dimmer action: between 0 and 100
95 * rollershutter action: between 0 and 100
98 public void setState(int state) {
100 if (getType().equals(ActionType.DIMMER)) { // for dimmers, only send the update to the event
111 * Sends action to Niko Home Control. This version is used for Niko Home Control II, that has extra status options.
113 * @param command - The allowed values depend on the action type.
114 * switch action: On or Off
115 * dimmer action: between 0 and 100, On or Off
116 * rollershutter action: between 0 and 100, Up, Down or Stop
119 public void execute(String command) {
120 logger.debug("execute action {} of type {} for {}", command, type, id);
123 if ("flag".equals(model)) {
124 cmd = NHCON.equals(command) ? NHCTRUE : NHCFALSE;
129 nhcComm.executeAction(id, cmd);
133 * @return model as returned from Niko Home Control
135 public String getModel() {
140 * @return technology as returned from Niko Home Control
142 public String getTechnology() {