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.api.dto;
15 import java.time.ZonedDateTime;
16 import java.util.LinkedHashSet;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.netatmo.internal.api.data.EventType;
22 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.TopologyChange;
23 import org.openhab.binding.netatmo.internal.deserialization.NAObjectMap;
24 import org.openhab.binding.netatmo.internal.deserialization.NAPushType;
27 * The {@link WebhookEvent} is responsible to hold
28 * data given back by the Netatmo API when calling the webhook
30 * @author Gaƫl L'hopital - Initial contribution
34 public class WebhookEvent extends Event {
35 private NAPushType pushType = NAPushType.UNKNOWN;
36 private String homeId = "";
37 private String roomId = "";
38 private String deviceId = "";
39 private @Nullable String snapshotUrl;
40 private @Nullable String vignetteUrl;
41 private TopologyChange change = TopologyChange.UNKNOWN;
42 private NAObjectMap<Person> persons = new NAObjectMap<>();
43 // Webhook does not provide the event generation time, so we'll use the event reception time
44 private ZonedDateTime time = ZonedDateTime.now();
46 public String getHomeId() {
50 public NAObjectMap<Person> getPersons() {
55 public EventType getEventType() {
56 return pushType.event();
60 public ZonedDateTime getTime() {
65 public @Nullable String getPersonId() {
66 return persons.size() > 0 ? persons.keySet().iterator().next() : null;
70 public @Nullable String getSnapshotUrl() {
74 public @Nullable String getVignetteUrl() {
78 public Set<String> getNAObjectList() {
79 Set<String> result = new LinkedHashSet<>();
80 result.add(getCameraId());
81 addNotBlank(result, homeId);
82 addNotBlank(result, deviceId);
83 addNotBlank(result, roomId);
84 addNotBlank(result, getCameraId());
85 result.addAll(getPersons().keySet());
89 private void addNotBlank(Set<String> collection, String value) {
90 if (!value.isBlank()) {
91 collection.add(value);
95 public TopologyChange getChange() {