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 roomId = "";
37 private String deviceId = "";
38 private @Nullable String snapshotUrl;
39 private @Nullable String vignetteUrl;
40 private NAObjectMap<Person> persons = new NAObjectMap<>();
41 // Webhook does not provide the event generation time, so we'll use the event reception time
42 private ZonedDateTime time = ZonedDateTime.now();
44 public String getHomeId() {
48 public NAObjectMap<Person> getPersons() {
53 public EventType getEventType() {
54 return pushType.event();
58 public ZonedDateTime getTime() {
63 public @Nullable String getPersonId() {
64 return persons.size() > 0 ? persons.keySet().iterator().next() : null;
68 public @Nullable String getSnapshotUrl() {
72 public @Nullable String getVignetteUrl() {
76 public Set<String> getNAObjectList() {
77 Set<String> result = new LinkedHashSet<>();
78 result.add(getCameraId());
79 addNotBlank(result, homeId);
80 addNotBlank(result, deviceId);
81 addNotBlank(result, roomId);
82 addNotBlank(result, getCameraId());
83 result.addAll(getPersons().keySet());
87 private void addNotBlank(Set<String> collection, String value) {
88 if (!value.isBlank()) {
89 collection.add(value);