]> git.basschouten.com Git - openhab-addons.git/blob
9d492207ce0f054279d816ce4b3a328db31ffa37
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.api.data.NetatmoConstants.TopologyChange;
23 import org.openhab.binding.netatmo.internal.deserialization.NAObjectMap;
24 import org.openhab.binding.netatmo.internal.deserialization.NAPushType;
25
26 /**
27  * The {@link WebhookEvent} is responsible to hold
28  * data given back by the Netatmo API when calling the webhook
29  *
30  * @author GaĆ«l L'hopital - Initial contribution
31  *
32  */
33 @NonNullByDefault
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();
45
46     public String getHomeId() {
47         return homeId;
48     }
49
50     public NAObjectMap<Person> getPersons() {
51         return persons;
52     }
53
54     @Override
55     public EventType getEventType() {
56         return pushType.event();
57     }
58
59     @Override
60     public ZonedDateTime getTime() {
61         return time;
62     }
63
64     @Override
65     public @Nullable String getPersonId() {
66         return persons.size() > 0 ? persons.keySet().iterator().next() : null;
67     }
68
69     @Override
70     public @Nullable String getSnapshotUrl() {
71         return snapshotUrl;
72     }
73
74     public @Nullable String getVignetteUrl() {
75         return vignetteUrl;
76     }
77
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());
86         return result;
87     }
88
89     private void addNotBlank(Set<String> collection, String value) {
90         if (!value.isBlank()) {
91             collection.add(value);
92         }
93     }
94
95     public TopologyChange getChange() {
96         return change;
97     }
98 }