]> git.basschouten.com Git - openhab-addons.git/blob
9ce7389b95962c93922b16e5bb0fbc53f38d0509
[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.List;
17 import java.util.Optional;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.netatmo.internal.api.ApiResponse;
22 import org.openhab.binding.netatmo.internal.api.BodyResponse;
23 import org.openhab.binding.netatmo.internal.api.data.EventSubType;
24 import org.openhab.binding.netatmo.internal.api.data.EventType;
25 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.EventCategory;
26 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.VideoStatus;
27
28 /**
29  * The {@link HomeEvent} holds information transferred by the webhook about a home event.
30  *
31  * @author GaĆ«l L'hopital - Initial contribution
32  *
33  */
34
35 @NonNullByDefault
36 public class HomeEvent extends Event {
37     public class NAEventsDataResponse extends ApiResponse<BodyResponse<Home>> {
38     }
39
40     private ZonedDateTime time = ZonedDateTime.now();
41     private @Nullable String personId;
42     private EventCategory category = EventCategory.UNKNOWN;
43     private @Nullable Snapshot snapshot;
44     private @Nullable Snapshot vignette;
45     private @Nullable String videoId;
46     private VideoStatus videoStatus = VideoStatus.UNKNOWN;
47     private boolean isArrival;
48     private List<HomeEvent> subevents = List.of();
49
50     @Override
51     public ZonedDateTime getTime() {
52         return time;
53     }
54
55     @Override
56     public @Nullable String getPersonId() {
57         return personId;
58     }
59
60     public @Nullable String getVideoId() {
61         return videoId;
62     }
63
64     public VideoStatus getVideoStatus() {
65         return videoStatus;
66     }
67
68     @Override
69     public Optional<EventSubType> getSubTypeDescription() {
70         // Blend extra information provided by this kind of event in subcategories...
71         if (type == EventType.PERSON) {
72             subType = isArrival ? EventSubType.PERSON_ARRIVAL.subType : EventSubType.PERSON_SEEN.subType;
73         } else if (type == EventType.PERSON_HOME) {
74             subType = EventSubType.PERSON_ARRIVAL.subType;
75         } else if (type == EventType.PERSON_AWAY) {
76             subType = EventSubType.PERSON_DEPARTURE.subType;
77         } else if (type == EventType.HUMAN) {
78             subType = EventSubType.MOVEMENT_HUMAN.subType;
79         } else if (type == EventType.ANIMAL) {
80             subType = EventSubType.MOVEMENT_ANIMAL.subType;
81         } else {
82             if (category == EventCategory.ANIMAL) {
83                 subType = EventSubType.MOVEMENT_ANIMAL.subType;
84             } else if (category == EventCategory.HUMAN) {
85                 subType = EventSubType.MOVEMENT_HUMAN.subType;
86             } else if (category == EventCategory.VEHICLE) {
87                 subType = EventSubType.MOVEMENT_VEHICLE.subType;
88             }
89         }
90         // ... and let ancestor do his work
91         return super.getSubTypeDescription();
92     }
93
94     @Override
95     public @Nullable String getSnapshotUrl() {
96         Snapshot image = snapshot;
97         return image != null ? image.getUrl() : null;
98     }
99
100     public @Nullable String getVignetteUrl() {
101         Snapshot image = vignette;
102         return image != null ? image.getUrl() : null;
103     }
104
105     public List<HomeEvent> getSubevents() {
106         return subevents;
107     }
108
109     public @Nullable Snapshot getVignette() {
110         return vignette;
111     }
112 }