]> git.basschouten.com Git - openhab-addons.git/blob
69b942b668f069b4555d249a71bb8ef56283f842
[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.enocean.internal.profiles;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.enocean.internal.config.EnOceanProfileRockerSwitchActionConfig;
18 import org.openhab.core.thing.profiles.ProfileCallback;
19 import org.openhab.core.thing.profiles.ProfileContext;
20 import org.openhab.core.thing.profiles.TriggerProfile;
21 import org.openhab.core.types.State;
22
23 /**
24  * @author Daniel Weber - Initial contribution
25  */
26 @NonNullByDefault
27 public abstract class RockerSwitchActionBaseProfile implements TriggerProfile {
28
29     protected final ProfileCallback callback;
30     protected ProfileContext context;
31
32     protected @Nullable State previousState;
33
34     protected static final String ANY_DIR = "*";
35
36     public RockerSwitchActionBaseProfile(ProfileCallback callback, ProfileContext context) {
37         this.callback = callback;
38         this.context = context;
39     }
40
41     protected boolean isEventValid(String event) {
42         String[] directions = event.split("\\|");
43         if (directions.length != 2) {
44             return false;
45         }
46
47         EnOceanProfileRockerSwitchActionConfig config = context.getConfiguration()
48                 .as(EnOceanProfileRockerSwitchActionConfig.class);
49         if (!(config.channelAFilter.equals(ANY_DIR) || config.channelAFilter.equals(directions[0]))) {
50             return false;
51         } else if (!(config.channelBFilter.equals(ANY_DIR) || config.channelBFilter.equals(directions[1]))) {
52             return false;
53         }
54
55         return true;
56     }
57 }