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.neohub.internal;
15 import static org.openhab.binding.neohub.internal.NeoHubBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.types.Command;
23 * The {@link NeoPlugHandler} is the OpenHAB Handler for NeoPlug devices Note:
24 * inherits almost all the functionality of a {@link NeoBaseHandler}
26 * @author Andrew Fiddian-Green - Initial contribution
30 public class NeoPlugHandler extends NeoBaseHandler {
32 public NeoPlugHandler(Thing thing) {
36 // =========== methods of NeoBaseHandler that are overridden ================
39 protected String toNeoHubBuildCommandString(String channelId, Command command) {
40 NeoBaseConfiguration config = this.config;
42 if (command instanceof OnOffType && channelId.equals(CHAN_PLUG_OUTPUT_STATE)) {
43 return String.format(CMD_CODE_TIMER, ((OnOffType) command).toString(), config.deviceNameInHub);
45 if (command instanceof OnOffType && channelId.equals(CHAN_PLUG_AUTO_MODE)) {
46 return String.format(CMD_CODE_MANUAL, invert((OnOffType) command).toString(), config.deviceNameInHub);
53 protected void toNeoHubSendCommandSet(String channelId, Command command) {
54 // if this is a manual command, switch to manual mode first..
55 if (channelId.equals(CHAN_PLUG_OUTPUT_STATE) && command instanceof OnOffType) {
56 toNeoHubSendCommand(CHAN_PLUG_AUTO_MODE, OnOffType.from(false));
58 // send the actual command to the hub
59 toNeoHubSendCommand(channelId, command);
63 protected void toOpenHabSendChannelValues(NeoHubAbstractDeviceData.AbstractRecord deviceRecord) {
64 boolean offline = deviceRecord.offline();
65 toOpenHabSendValueDebounced(CHAN_PLUG_AUTO_MODE, OnOffType.from(!deviceRecord.stateManual()), offline);
66 toOpenHabSendValueDebounced(CHAN_PLUG_OUTPUT_STATE, OnOffType.from(deviceRecord.isTimerOn()), offline);