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.io.hueemulation.internal.automation;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.automation.Action;
20 import org.openhab.core.automation.RuleRegistry;
21 import org.openhab.core.automation.handler.ActionHandler;
22 import org.openhab.core.automation.handler.BaseModuleHandler;
23 import org.openhab.core.config.core.Configuration;
26 * This action module type allows to remove a rule from the rule registry.
28 * This is very useful for rules that should execute only once etc.
30 * @author David Graeff - Initial contribution
33 public class RemoveRuleActionHandler extends BaseModuleHandler<Action> implements ActionHandler {
34 public static final String MODULE_TYPE_ID = "rules.RemoveRuleAction";
35 public static final String CALLBACK_CONTEXT_NAME = "CALLBACK";
36 public static final String MODULE_CONTEXT_NAME = "MODULE";
38 public static final String CFG_REMOVE_UID = "removeuid";
39 private final String ruleUID;
41 private RuleRegistry ruleRegistry;
43 @SuppressWarnings({ "null", "unused" })
44 public RemoveRuleActionHandler(final Action module, RuleRegistry ruleRegistry) {
46 this.ruleRegistry = ruleRegistry;
47 final Configuration config = module.getConfiguration();
48 if (config.getProperties().isEmpty()) {
49 throw new IllegalArgumentException("'Configuration' can not be empty.");
52 ruleUID = (String) config.get(CFG_REMOVE_UID);
53 if (ruleUID == null) {
54 throw new IllegalArgumentException("'ruleUIDs' property must not be null.");
59 public @Nullable Map<String, Object> execute(Map<String, Object> context) {
60 ruleRegistry.remove(ruleUID);