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