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.List;
17 import java.util.Optional;
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;
29 * The {@link HomeEvent} holds information transferred by the webhook about a home event.
31 * @author Gaƫl L'hopital - Initial contribution
36 public class HomeEvent extends Event {
37 public class NAEventsDataResponse extends ApiResponse<BodyResponse<Home>> {
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();
51 public ZonedDateTime getTime() {
56 public @Nullable String getPersonId() {
60 public @Nullable String getVideoId() {
64 public VideoStatus getVideoStatus() {
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;
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;
90 // ... and let ancestor do his work
91 return super.getSubTypeDescription();
95 public @Nullable String getSnapshotUrl() {
96 Snapshot image = snapshot;
97 return image != null ? image.getUrl() : null;
100 public @Nullable String getVignetteUrl() {
101 Snapshot image = vignette;
102 return image != null ? image.getUrl() : null;
105 public List<HomeEvent> getSubevents() {
109 public @Nullable Snapshot getVignette() {