]> git.basschouten.com Git - openhab-addons.git/blob
71ef8ff29c289fdc1a4d8380f73cdda29553d0ff
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.netatmo.internal.api.dto;
14
15 import java.time.ZonedDateTime;
16 import java.util.LinkedHashSet;
17 import java.util.Set;
18
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;
24
25 /**
26  * The {@link WebhookEvent} is responsible to hold
27  * data given back by the Netatmo API when calling the webhook
28  *
29  * @author GaĆ«l L'hopital - Initial contribution
30  *
31  */
32 @NonNullByDefault
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();
42
43     public String getHomeId() {
44         return homeId;
45     }
46
47     public NAObjectMap<Person> getPersons() {
48         return persons;
49     }
50
51     @Override
52     public EventType getEventType() {
53         return pushType.getEvent();
54     }
55
56     @Override
57     public ZonedDateTime getTime() {
58         return time;
59     }
60
61     @Override
62     public @Nullable String getPersonId() {
63         return persons.size() > 0 ? persons.keySet().iterator().next() : null;
64     }
65
66     @Override
67     public @Nullable String getSnapshotUrl() {
68         return snapshotUrl;
69     }
70
71     public @Nullable String getVignetteUrl() {
72         return vignetteUrl;
73     }
74
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());
82         return result;
83     }
84
85     private void addNotBlank(Set<String> collection, String value) {
86         if (!value.isBlank()) {
87             collection.add(value);
88         }
89     }
90 }