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.deserialization.NAObjectMap;
23 import org.openhab.binding.netatmo.internal.deserialization.NAPushType;
26 * The {@link WebhookEvent} is responsible to hold
27 * data given back by the Netatmo API when calling the webhook
29 * @author Gaƫl L'hopital - Initial contribution
33 public class WebhookEvent extends Event {
34 private NAPushType pushType = NAPushType.UNKNOWN;
35 private String homeId = "";
36 private String deviceId = "";
37 private @Nullable String snapshotUrl;
38 private @Nullable String vignetteUrl;
39 private NAObjectMap<Person> persons = new NAObjectMap<>();
40 // Webhook does not provide the event generation time, so we'll use the event reception time
41 private ZonedDateTime time = ZonedDateTime.now();
43 public String getHomeId() {
47 public NAObjectMap<Person> getPersons() {
52 public EventType getEventType() {
53 return pushType.getEvent();
57 public ZonedDateTime getTime() {
62 public @Nullable String getPersonId() {
63 return persons.size() > 0 ? persons.keySet().iterator().next() : null;
67 public @Nullable String getSnapshotUrl() {
71 public @Nullable String getVignetteUrl() {
75 public Set<String> getNAObjectList() {
76 Set<String> result = new LinkedHashSet<>();
77 result.add(getCameraId());
78 addNotBlank(result, homeId);
79 addNotBlank(result, deviceId);
80 addNotBlank(result, getCameraId());
81 result.addAll(getPersons().keySet());
85 private void addNotBlank(Set<String> collection, String value) {
86 if (!value.isBlank()) {
87 collection.add(value);