2 * Copyright (c) 2010-2023 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.List;
16 import java.util.Optional;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler;
20 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
21 import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
22 import org.openhab.binding.netatmo.internal.handler.channelhelper.EventChannelHelper;
23 import org.openhab.binding.netatmo.internal.providers.NetatmoDescriptionProvider;
24 import org.openhab.binding.netatmo.internal.servlet.WebhookServlet;
27 * {@link HomeSecurityThingCapability} is the ancestor of capabilities hosted by a security home
28 * e.g. person and camera capabilities
30 * @author Gaƫl L'hopital - Initial contribution
34 public class HomeSecurityThingCapability extends Capability {
35 protected final NetatmoDescriptionProvider descriptionProvider;
36 protected final EventChannelHelper eventHelper;
38 private Optional<WebhookServlet> webhook = Optional.empty();
39 protected Optional<SecurityCapability> securityCapability = Optional.empty();
40 protected Optional<HomeCapability> homeCapability = Optional.empty();
42 public HomeSecurityThingCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider,
43 List<ChannelHelper> channelHelpers) {
45 this.descriptionProvider = descriptionProvider;
46 this.eventHelper = (EventChannelHelper) channelHelpers.stream().filter(c -> c instanceof EventChannelHelper)
47 .findFirst().orElseThrow(() -> new IllegalArgumentException(
48 "HomeSecurityThingCapability must find an EventChannelHelper, please file a bug report."));
49 eventHelper.setModuleType(moduleType);
53 public void initialize() {
55 securityCapability = handler.getHomeCapability(SecurityCapability.class);
56 homeCapability = handler.getHomeCapability(HomeCapability.class);
57 ApiBridgeHandler accountHandler = handler.getAccountHandler();
58 if (accountHandler != null) {
59 webhook = accountHandler.getWebHookServlet();
60 webhook.ifPresent(servlet -> servlet.registerDataListener(handler.getId(), this));
65 public void dispose() {
66 webhook.ifPresent(servlet -> servlet.unregisterDataListener(handler.getId()));