2 * Copyright (c) 2010-2022 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.netatmo.internal.handler.capability;
15 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler;
19 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
20 import org.openhab.binding.netatmo.internal.webhook.NetatmoServlet;
23 * {@link EventCapability} is the base class for handlers
24 * subject to receive event notifications. This class registers to webhookservlet so
25 * it can be notified when an event arrives.
27 * @author Gaƫl L'hopital - Initial contribution
31 public class EventCapability extends Capability {
32 private Optional<NetatmoServlet> servlet = Optional.empty();
34 public EventCapability(CommonInterface handler) {
39 public void initialize() {
40 ApiBridgeHandler accountHandler = handler.getAccountHandler();
41 if (accountHandler != null) {
42 servlet = accountHandler.getServlet();
43 servlet.ifPresent(s -> s.registerDataListener(handler.getId(), this));
48 public void dispose() {
49 servlet.ifPresent(s -> s.unregisterDataListener(this));