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.tapocontrol.internal.device;
15 import static org.openhab.binding.tapocontrol.internal.constants.TapoThingConstants.*;
16 import static org.openhab.binding.tapocontrol.internal.helpers.TapoUtils.*;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.tapocontrol.internal.structures.TapoDeviceInfo;
20 import org.openhab.core.library.types.OnOffType;
21 import org.openhab.core.library.unit.Units;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.RefreshType;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * TAPO Smart-Plug-Device.
32 * @author Christian Wild - Initial contribution
35 public class TapoSmartPlug extends TapoDevice {
36 private final Logger logger = LoggerFactory.getLogger(TapoSmartPlug.class);
41 * @param thing Thing object representing device
43 public TapoSmartPlug(Thing thing) {
48 * handle command sent to device
50 * @param channelUID channelUID command is sent to
51 * @param command command to be sent
54 public void handleCommand(ChannelUID channelUID, Command command) {
55 boolean refreshInfo = false;
56 String id = channelUID.getIdWithoutGroup();
59 if (command instanceof RefreshType) {
61 } else if (command instanceof OnOffType) {
62 Boolean targetState = command == OnOffType.ON ? Boolean.TRUE : Boolean.FALSE;
63 if (CHANNEL_OUTPUT.equals(id)) { // Command is sent to the device output
64 connector.sendDeviceCommand(DEVICE_PROPERTY_ON, targetState);
66 } else if (id.startsWith(CHANNEL_OUTPUT)) { // Command is sent to a child's device output
67 Integer index = Integer.valueOf(id.replace(CHANNEL_OUTPUT, ""));
68 connector.sendChildCommand(index, DEVICE_PROPERTY_ON, targetState);
72 logger.warn("({}) command type '{}' not supported for channel '{}'", uid, command, channelUID.getId());
77 queryDeviceInfo(true);
84 * @param TapoDeviceInfo
87 protected void devicePropertiesChanged(TapoDeviceInfo deviceInfo) {
88 super.devicePropertiesChanged(deviceInfo);
89 publishState(getChannelID(CHANNEL_GROUP_ACTUATOR, CHANNEL_OUTPUT), getOnOffType(deviceInfo.isOn()));
90 publishState(getChannelID(CHANNEL_GROUP_DEVICE, CHANNEL_WIFI_STRENGTH),
91 getDecimalType(deviceInfo.getSignalLevel()));
92 publishState(getChannelID(CHANNEL_GROUP_DEVICE, CHANNEL_ONTIME),
93 getTimeType(deviceInfo.getOnTime(), Units.SECOND));
94 publishState(getChannelID(CHANNEL_GROUP_DEVICE, CHANNEL_OVERHEAT), getOnOffType(deviceInfo.isOverheated()));