2 * Copyright (c) 2010-2024 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.tplinksmarthome.internal.handler;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.automation.annotation.ActionInput;
20 import org.openhab.core.automation.annotation.ActionOutput;
21 import org.openhab.core.automation.annotation.RuleAction;
22 import org.openhab.core.thing.binding.ThingActions;
23 import org.openhab.core.thing.binding.ThingActionsScope;
24 import org.openhab.core.thing.binding.ThingHandler;
25 import org.openhab.core.thing.binding.ThingHandlerService;
26 import org.osgi.service.component.annotations.Component;
27 import org.osgi.service.component.annotations.ServiceScope;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * TP-Link Smart Home Rule Actions.
34 * @author Hilbrand Bouwkamp - Initial contribution
36 @Component(scope = ServiceScope.PROTOTYPE, service = TPLinkSmartHomeActions.class)
37 @ThingActionsScope(name = "tplinksmarthome")
39 public class TPLinkSmartHomeActions implements ThingActions, ThingHandlerService {
41 private final Logger logger = LoggerFactory.getLogger(TPLinkSmartHomeActions.class);
43 private @Nullable SmartHomeHandler handler;
45 @RuleAction(label = "@text/actions.tplinksmarthome.send.label", description = "@text/actions.tplinksmarthome.send.description")
46 @ActionOutput(name = "response", label = "@text/actions.tplinksmarthome.send.response.label", description = "@text/actions.tplinksmarthome.send.response.description", type = "java.lang.String")
48 @ActionInput(name = "command", label = "@text/actions.tplinksmarthome.send.command.label", description = "@text/actions.tplinksmarthome.send.command.description", type = "java.lang.String", required = true) final String command)
50 if (handler instanceof SmartHomeHandler) {
51 return handler.getConnection().sendCommand(command);
53 logger.warn("Could not send command to tplink device because handler not set.");
58 public static String send(final ThingActions actions, final String command) throws IOException {
59 return ((TPLinkSmartHomeActions) actions).send(command);
63 public void setThingHandler(final ThingHandler handler) {
64 if (handler instanceof SmartHomeHandler smartHomeHandler) {
65 this.handler = smartHomeHandler;
70 public @Nullable ThingHandler getThingHandler() {