]> git.basschouten.com Git - openhab-addons.git/blob
b9bd34d1acd87c0513d231aa9096f5e60b915d54
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.hue.internal.action;
14
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;
27
28 /**
29  * The {@link LightActions} defines {@link ThingActions} for the Hue lights.
30  *
31  * @author Jochen Leopold - Initial contribution
32  */
33 @ThingActionsScope(name = "hue")
34 @NonNullByDefault
35 public class LightActions implements ThingActions {
36     private final Logger logger = LoggerFactory.getLogger(LightActions.class);
37     private @Nullable HueLightActionsHandler handler;
38
39     @Override
40     public void setThingHandler(@Nullable ThingHandler handler) {
41         this.handler = (HueLightActionsHandler) handler;
42     }
43
44     @Override
45     public @Nullable ThingHandler getThingHandler() {
46         return handler;
47     }
48
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!");
57             return;
58         }
59
60         if (channel == null) {
61             logger.debug("skipping Hue fadingLightCommand to channel '{}' due to null value.", channel);
62             return;
63         }
64         if (command == null) {
65             logger.debug("skipping Hue fadingLightCommand to command '{}' due to null value.", command);
66             return;
67         }
68         if (fadeTime == null) {
69             logger.debug("skipping Hue fadingLightCommand to fadeTime '{}' due to null value.", fadeTime);
70             return;
71         }
72
73         lightActionsHandler.handleCommand(channel, command, fadeTime.longValue());
74         logger.debug("send fadingLightCommand to channel '{}' with fadeTime of {}ms.", channel, fadeTime);
75     }
76
77     public static void fadingLightCommand(ThingActions actions, @Nullable String channel, @Nullable Command command,
78             @Nullable DecimalType fadeTime) {
79         ((LightActions) actions).fadingLightCommand(channel, command, fadeTime);
80     }
81 }