]> git.basschouten.com Git - openhab-addons.git/blob
308e1235c8f115ef9fe6454e8311e04f70d34d57
[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.teleinfo.internal.handler;
14
15 import java.util.Collection;
16 import java.util.Set;
17 import java.util.concurrent.CopyOnWriteArraySet;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.teleinfo.internal.TeleinfoDiscoveryService;
21 import org.openhab.binding.teleinfo.internal.data.Frame;
22 import org.openhab.core.thing.Bridge;
23 import org.openhab.core.thing.binding.BaseBridgeHandler;
24 import org.openhab.core.thing.binding.ThingHandlerService;
25
26 /**
27  * The {@link TeleinfoAbstractControllerHandler} class defines a skeleton for controller handlers.
28  *
29  * @author Nicolas SIBERIL - Initial contribution
30  */
31 @NonNullByDefault
32 public abstract class TeleinfoAbstractControllerHandler extends BaseBridgeHandler {
33
34     private Set<TeleinfoControllerHandlerListener> listeners = new CopyOnWriteArraySet<>();
35
36     protected TeleinfoAbstractControllerHandler(Bridge bridge) {
37         super(bridge);
38     }
39
40     public void addListener(final TeleinfoControllerHandlerListener listener) {
41         listeners.add(listener);
42     }
43
44     public void removeListener(final TeleinfoControllerHandlerListener listener) {
45         listeners.remove(listener);
46     }
47
48     protected void fireOnFrameReceivedEvent(final Frame frame) {
49         listeners.forEach(l -> l.onFrameReceived(frame));
50     }
51
52     @Override
53     public Collection<Class<? extends ThingHandlerService>> getServices() {
54         return Set.of(TeleinfoDiscoveryService.class);
55     }
56 }