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.Clip2ThingHandler;
18 import org.openhab.core.automation.annotation.ActionInput;
19 import org.openhab.core.automation.annotation.RuleAction;
20 import org.openhab.core.library.types.QuantityType;
21 import org.openhab.core.library.unit.MetricPrefix;
22 import org.openhab.core.library.unit.Units;
23 import org.openhab.core.thing.binding.ThingActions;
24 import org.openhab.core.thing.binding.ThingActionsScope;
25 import org.openhab.core.thing.binding.ThingHandler;
26 import org.openhab.core.types.Command;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Implementation of the {@link ThingActions} interface used for sending 'dynamics' commands to Hue API v2 devices,
34 * @author Andrew Fiddian-Green - Initial contribution
36 @ThingActionsScope(name = "hue")
38 public class DynamicsActions implements ThingActions {
40 private final Logger logger = LoggerFactory.getLogger(DynamicsActions.class);
42 private @Nullable Clip2ThingHandler handler;
44 public static void dynamicCommand(ThingActions actions, @Nullable String channelId, @Nullable Command command,
45 @Nullable Long durationMs) {
46 ((DynamicsActions) actions).dynamicCommand(channelId, command, durationMs);
49 @RuleAction(label = "@text/dynamics.action.label", description = "@text/dynamics.action.description")
50 public void dynamicCommand(
51 @ActionInput(name = "channelId", label = "@text/dynamics.channel.label", description = "@text/dynamics.channel.description") @Nullable String channelId,
52 @ActionInput(name = "command", label = "@text/dynamics.command.label", description = "@text/dynamics.command.description") @Nullable Command command,
53 @ActionInput(name = "durationMs", label = "@text/dynamics.duration.label", description = "@text/dynamics.duration.description") @Nullable Long durationMs) {
55 Clip2ThingHandler handler = this.handler;
56 if (handler == null) {
57 logger.warn("ThingHandler is null.");
60 if (channelId == null) {
61 logger.debug("Channel ID is null.");
64 if (command == null) {
65 logger.debug("Command is null.");
68 if (durationMs == null || durationMs.longValue() <= 0) {
69 logger.debug("Duration is null, zero or negative.");
72 handler.handleDynamicsCommand(channelId, command,
73 new QuantityType<>(durationMs.longValue(), MetricPrefix.MILLI(Units.SECOND)));
74 logger.debug("Dynamic command '{}' sent to channelId '{}' with duration {}ms.", command, channelId, durationMs);
78 public @Nullable ThingHandler getThingHandler() {
83 public void setThingHandler(@Nullable ThingHandler handler) {
84 this.handler = (Clip2ThingHandler) handler;