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.servlet.WebhookServlet;
23 * {@link EventCapability} is the base class for handlers subject to receive event notifications.
24 * This class registers to NetatmoServletService so it can be notified when an event arrives.
26 * @author Gaƫl L'hopital - Initial contribution
30 public class EventCapability extends Capability {
31 private Optional<WebhookServlet> webhook = Optional.empty();
33 public EventCapability(CommonInterface handler) {
38 public void initialize() {
39 ApiBridgeHandler accountHandler = handler.getAccountHandler();
40 if (accountHandler != null) {
41 webhook = accountHandler.getWebHookServlet();
42 webhook.ifPresent(servlet -> servlet.registerDataListener(handler.getId(), this));
47 public void dispose() {
48 webhook.ifPresent(servlet -> servlet.unregisterDataListener(handler.getId()));