]> git.basschouten.com Git - openhab-addons.git/blob
ea12793589b5a7b84ee2ef0ef4c9e41af05e6859
[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.plugwise.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.plugwise.internal.listener.PlugwiseMessageListener;
18 import org.openhab.binding.plugwise.internal.protocol.Message;
19 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
20
21 /**
22  * A filtered message listener listens to either all messages or only those of a device that has a certain MAC address.
23  *
24  * @author Wouter Born - Initial contribution
25  */
26 @NonNullByDefault
27 public class PlugwiseFilteredMessageListener {
28
29     private final PlugwiseMessageListener listener;
30     private final @Nullable MACAddress macAddress;
31
32     public PlugwiseFilteredMessageListener(PlugwiseMessageListener listener) {
33         this(listener, null);
34     }
35
36     public PlugwiseFilteredMessageListener(PlugwiseMessageListener listener, @Nullable MACAddress macAddress) {
37         this.listener = listener;
38         this.macAddress = macAddress;
39     }
40
41     public PlugwiseMessageListener getListener() {
42         return listener;
43     }
44
45     public @Nullable MACAddress getMACAddress() {
46         return macAddress;
47     }
48
49     public boolean matches(Message message) {
50         MACAddress localMACAddress = macAddress;
51         return localMACAddress == null || localMACAddress.equals(message.getMACAddress());
52     }
53 }