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.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.HueLightActionsHandler;
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 {@link ThingActions} for the Hue lights.
31 * @author Jochen Leopold - Initial contribution
33 @ThingActionsScope(name = "hue")
35 public class LightActions implements ThingActions {
36 private final Logger logger = LoggerFactory.getLogger(LightActions.class);
37 private @Nullable HueLightActionsHandler handler;
40 public void setThingHandler(@Nullable ThingHandler handler) {
41 this.handler = (HueLightActionsHandler) handler;
45 public @Nullable ThingHandler getThingHandler() {
49 @RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
50 public void fadingLightCommand(
51 @ActionInput(name = "channel", label = "@text/actionInputChannelLabel", description = "@text/actionInputChannelDesc") @Nullable String channel,
52 @ActionInput(name = "command", label = "@text/actionInputCommandLabel", description = "@text/actionInputCommandDesc") @Nullable Command command,
53 @ActionInput(name = "fadeTime", label = "@text/actionInputFadeTimeLabel", description = "@text/actionInputFadeTimeDesc") @Nullable DecimalType fadeTime) {
54 HueLightActionsHandler lightActionsHandler = handler;
55 if (lightActionsHandler == null) {
56 logger.warn("Hue Action service ThingHandler is null!");
60 if (channel == null) {
61 logger.debug("skipping Hue fadingLightCommand to channel '{}' due to null value.", channel);
64 if (command == null) {
65 logger.debug("skipping Hue fadingLightCommand to command '{}' due to null value.", command);
68 if (fadeTime == null) {
69 logger.debug("skipping Hue fadingLightCommand to fadeTime '{}' due to null value.", fadeTime);
73 lightActionsHandler.handleCommand(channel, command, fadeTime.longValue());
74 logger.debug("send fadingLightCommand to channel '{}' with fadeTime of {}ms.", channel, fadeTime);
77 public static void fadingLightCommand(ThingActions actions, @Nullable String channel, @Nullable Command command,
78 @Nullable DecimalType fadeTime) {
79 ((LightActions) actions).fadingLightCommand(channel, command, fadeTime);