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.satel.internal.action;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.satel.internal.handler.SatelEventLogHandler;
21 import org.openhab.core.automation.annotation.ActionInput;
22 import org.openhab.core.automation.annotation.ActionOutput;
23 import org.openhab.core.automation.annotation.RuleAction;
24 import org.openhab.core.thing.binding.ThingActions;
25 import org.openhab.core.thing.binding.ThingActionsScope;
26 import org.openhab.core.thing.binding.ThingHandler;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Automation action handler service for reading Satel event log.
33 * @author Krzysztof Goworek - Initial contribution
34 * @see SatelEventLogHandler
36 @ThingActionsScope(name = "satel")
38 public class SatelEventLogActions implements ThingActions {
40 private final Logger logger = LoggerFactory.getLogger(getClass());
42 private @Nullable SatelEventLogHandler handler;
45 public void setThingHandler(@Nullable ThingHandler handler) {
46 if (handler instanceof SatelEventLogHandler) {
47 this.handler = (SatelEventLogHandler) handler;
52 public @Nullable ThingHandler getThingHandler() {
56 @RuleAction(label = "@text/actionReadEventLabel", description = "@text/actionReadEventDesc")
57 public @ActionOutput(name = "index", type = "java.lang.Integer", label = "@text/actionOutputIndexLabel", description = "@text/actionOutputIndexDesc") @ActionOutput(name = "prev_index", type = "java.lang.Integer", label = "@text/actionOutputPrevIndexLabel", description = "@text/actionOutputPrevIndexDesc") @ActionOutput(name = "timestamp", type = "java.time.ZonedDateTime", label = "@text/actionOutputTimestampLabel", description = "@text/actionOutputTimestampDesc") @ActionOutput(name = "description", type = "java.lang.String", label = "@text/actionOutputDescriptionLabel", description = "@text/actionOutputDescriptionDesc") @ActionOutput(name = "details", type = "java.lang.String", label = "@text/actionOutputDetailsLabel", description = "@text/actionOutputDetailsDesc") Map<String, Object> readEvent(
58 @ActionInput(name = "index", label = "@text/actionInputIndexLabel", description = "@text/actionInputIndexDesc") @Nullable Number index) {
59 logger.debug("satel.readEvent called with input: index={}", index);
61 Map<String, Object> result = new HashMap<>();
62 SatelEventLogHandler handler = this.handler;
63 if (handler != null) {
64 handler.readEvent(index == null ? -1 : index.intValue()).ifPresent(event -> {
65 result.put("index", event.getIndex());
66 result.put("prev_index", event.getPrevIndex());
67 result.put("timestamp", event.getTimestamp());
68 result.put("description", event.getDescription());
69 result.put("details", event.getDetails());
75 public static Map<String, Object> readEvent(ThingActions actions, @Nullable Number index) {
76 return ((SatelEventLogActions) actions).readEvent(index);