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.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;
38 private String deviceType;
39 private String deviceTechnology;
40 private String deviceModel;
42 NhcAction2(String id, String name, String deviceType, String deviceTechnology, String deviceModel,
43 @Nullable String location, ActionType type, NikoHomeControlCommunication nhcComm) {
44 super(id, name, type, location, nhcComm);
45 this.deviceType = deviceType;
46 this.deviceTechnology = deviceTechnology;
47 this.deviceModel = deviceModel;
51 * Get on/off state of action.
53 * true for on, false for off
55 * @return action on/off state
57 boolean booleanState() {
62 public int getState() {
63 return booleanState ? state : 0;
67 * Sets on/off state of action.
69 * @param state - boolean false for on, true for off
71 public void setBooleanState(boolean state) {
73 if (getType().equals(ActionType.DIMMER)) {
75 // only send stored brightness value if on
92 * Sets state of action. This version is used for Niko Home Control II.
94 * @param state - The allowed values depend on the action type.
95 * switch action: 0 or 100
96 * dimmer action: between 0 and 100
97 * rollershutter action: between 0 and 100
100 public void setState(int state) {
102 if (getType().equals(ActionType.DIMMER)) { // for dimmers, only send the update to the event
113 * Sends action to Niko Home Control. This version is used for Niko Home Control II, that has extra status options.
115 * @param command - The allowed values depend on the action type.
116 * switch action: On or Off
117 * dimmer action: between 0 and 100, On or Off
118 * rollershutter action: between 0 and 100, Up, Down or Stop
121 public void execute(String command) {
122 logger.debug("execute action {} of type {} for {}", command, type, id);
125 if ("flag".equals(deviceModel)) {
126 cmd = NHCON.equals(command) ? NHCTRUE : NHCFALSE;
131 nhcComm.executeAction(id, cmd);
135 * @return type as returned from Niko Home Control
137 public String getDeviceType() {
142 * @return technology as returned from Niko Home Control
144 public String getDeviceTechnology() {
145 return deviceTechnology;
149 * @return model as returned from Niko Home Control
151 public String getDeviceModel() {