2 * Copyright (c) 2010-2021 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.hue.internal.action;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.hue.internal.handler.HueLightHandler;
18 import org.openhab.core.automation.annotation.ActionInput;
19 import org.openhab.core.automation.annotation.RuleAction;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.thing.binding.ThingActions;
22 import org.openhab.core.thing.binding.ThingActionsScope;
23 import org.openhab.core.thing.binding.ThingHandler;
24 import org.openhab.core.types.Command;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * The {@link LightActions} defines the thing actions for the hue binding.
31 * @author Jochen Leopold - Initial contribution
32 * @author Laurent Garnier - new method invokeMethodOf + interface ILightActions
34 @ThingActionsScope(name = "hue")
36 public class LightActions implements ThingActions {
37 private final Logger logger = LoggerFactory.getLogger(LightActions.class);
38 private @Nullable HueLightHandler handler;
41 public void setThingHandler(@Nullable ThingHandler handler) {
42 this.handler = (HueLightHandler) handler;
46 public @Nullable ThingHandler getThingHandler() {
50 @RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
51 public void fadingLightCommand(
52 @ActionInput(name = "channel", label = "@text/actionInputChannelLabel", description = "@text/actionInputChannelDesc") @Nullable String channel,
53 @ActionInput(name = "command", label = "@text/actionInputCommandLabel", description = "@text/actionInputCommandDesc") @Nullable Command command,
54 @ActionInput(name = "fadeTime", label = "@text/actionInputFadeTimeLabel", description = "@text/actionInputFadeTimeDesc") @Nullable DecimalType fadeTime) {
55 HueLightHandler lightHandler = handler;
56 if (lightHandler == null) {
57 logger.warn("Hue Action service ThingHandler is null!");
61 if (channel == null) {
62 logger.debug("skipping Hue fadingLightCommand to channel '{}' due to null value.", channel);
66 if (command == null) {
67 logger.debug("skipping Hue fadingLightCommand to command '{}' due to null value.", command);
70 if (fadeTime == null) {
71 logger.debug("skipping Hue fadingLightCommand to fadeTime '{}' due to null value.", fadeTime);
75 lightHandler.handleCommand(channel, command, fadeTime.longValue());
76 logger.debug("send LightAction to {} with {}ms of fadeTime", channel, fadeTime);
79 public static void fadingLightCommand(ThingActions actions, @Nullable String channel, @Nullable Command command,
80 @Nullable DecimalType fadeTime) {
81 ((LightActions) actions).fadingLightCommand(channel, command, fadeTime);