2 * Copyright (c) 2010-2022 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.Optional;
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;
28 * The {@link HomeEvent} holds information transferred by the webhook about a home event.
30 * @author Gaƫl L'hopital - Initial contribution
35 public class HomeEvent extends Event {
36 public class NAEventsDataResponse extends ApiResponse<BodyResponse<Home>> {
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;
48 public ZonedDateTime getTime() {
53 public @Nullable String getPersonId() {
57 public @Nullable String getVideoId() {
61 public VideoStatus getVideoStatus() {
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;
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;
87 // ... and let ancestor do his work
88 return super.getSubTypeDescription();
92 public @Nullable String getSnapshotUrl() {
93 Snapshot localSnap = snapshot;
94 return localSnap != null ? localSnap.getUrl() : null;