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;
58 if (command instanceof RefreshType) {
60 } else if (command == OnOffType.ON) {
61 connector.sendDeviceCommand(DEVICE_PROPERTY_ON, true);
63 } else if (command == OnOffType.OFF) {
64 connector.sendDeviceCommand(DEVICE_PROPERTY_ON, false);
67 logger.warn("({}) command type '{}' not supported for channel '{}'", uid, command.toString(),
73 queryDeviceInfo(true);
80 * @param TapoDeviceInfo
83 protected void devicePropertiesChanged(TapoDeviceInfo deviceInfo) {
84 super.devicePropertiesChanged(deviceInfo);
85 publishState(getChannelID(CHANNEL_GROUP_ACTUATOR, CHANNEL_OUTPUT), getOnOffType(deviceInfo.isOn()));
86 publishState(getChannelID(CHANNEL_GROUP_DEVICE, CHANNEL_WIFI_STRENGTH),
87 getDecimalType(deviceInfo.getSignalLevel()));
88 publishState(getChannelID(CHANNEL_GROUP_DEVICE, CHANNEL_ONTIME),
89 getTimeType(deviceInfo.getOnTime(), Units.SECOND));
90 publishState(getChannelID(CHANNEL_GROUP_DEVICE, CHANNEL_OVERHEAT), getOnOffType(deviceInfo.isOverheated()));