|
| 1 | +/* |
| 2 | + * Copyright (c) 2010-2025 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.keba.internal.handler; |
| 14 | + |
| 15 | +import org.eclipse.jdt.annotation.NonNullByDefault; |
| 16 | +import org.eclipse.jdt.annotation.Nullable; |
| 17 | +import org.openhab.binding.keba.internal.KebaBindingConstants; |
| 18 | +import org.openhab.core.automation.annotation.ActionInput; |
| 19 | +import org.openhab.core.automation.annotation.RuleAction; |
| 20 | +import org.openhab.core.thing.binding.ThingActions; |
| 21 | +import org.openhab.core.thing.binding.ThingActionsScope; |
| 22 | +import org.openhab.core.thing.binding.ThingHandler; |
| 23 | +import org.osgi.service.component.annotations.Component; |
| 24 | +import org.osgi.service.component.annotations.ServiceScope; |
| 25 | +import org.slf4j.Logger; |
| 26 | +import org.slf4j.LoggerFactory; |
| 27 | + |
| 28 | +/** |
| 29 | + * The {@link KeContactActions} is responsible for handling actions, which |
| 30 | + * are sent to the binding. |
| 31 | + * |
| 32 | + * @author Simon Spielmann - Initial contribution |
| 33 | + */ |
| 34 | +@Component(scope = ServiceScope.PROTOTYPE, service = KeContactActions.class) |
| 35 | +@ThingActionsScope(name = KebaBindingConstants.BINDING_ID) |
| 36 | +@NonNullByDefault |
| 37 | +public class KeContactActions implements ThingActions { |
| 38 | + private final Logger logger = LoggerFactory.getLogger(KeContactActions.class); |
| 39 | + private @Nullable KeContactHandler handler; |
| 40 | + |
| 41 | + @Override |
| 42 | + public void setThingHandler(ThingHandler handler) { |
| 43 | + this.handler = (KeContactHandler) handler; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public @Nullable ThingHandler getThingHandler() { |
| 48 | + return handler; |
| 49 | + } |
| 50 | + |
| 51 | + @RuleAction(label = "@text/actionLabel", description = "@text/actionDesc") |
| 52 | + public void setDisplay( |
| 53 | + @ActionInput(name = "text", label = "@text/actionInputTextLabel", description = "@text/actionInputTextDesc") @Nullable String text, |
| 54 | + @ActionInput(name = "durationMin", label = "@text/actionInputDurationMinLabel", description = "@text/actionInputDurationMinDesc") int durationMin, |
| 55 | + @ActionInput(name = "durationMax", label = "@text/actionInputDurationMaxLabel", description = "@text/actionInputDurationMaxDesc") int durationMax) { |
| 56 | + if (handler == null) { |
| 57 | + logger.warn("KeContact Action service ThingHandler is null!"); |
| 58 | + return; |
| 59 | + } |
| 60 | + handler.setDisplay(text, durationMin, durationMax); |
| 61 | + } |
| 62 | + |
| 63 | + public static void setDisplay(ThingActions actions, @Nullable String text, int durationMin, int durationMax) { |
| 64 | + ((KeContactActions) actions).setDisplay(text, durationMin, durationMax); |
| 65 | + } |
| 66 | + |
| 67 | + @RuleAction(label = "@text/actionLabel", description = "@text/actionDesc") |
| 68 | + public void setDisplay( |
| 69 | + @ActionInput(name = "text", label = "@text/actionInputTextLabel", description = "@text/actionInputTextDesc") @Nullable String text) { |
| 70 | + if (handler == null) { |
| 71 | + logger.warn("KeContact Action service ThingHandler is null!"); |
| 72 | + return; |
| 73 | + } |
| 74 | + handler.setDisplay(text, -1, -1); |
| 75 | + } |
| 76 | + |
| 77 | + public static void setDisplay(ThingActions actions, @Nullable String text) { |
| 78 | + ((KeContactActions) actions).setDisplay(text); |
| 79 | + } |
| 80 | +} |
0 commit comments