]> git.basschouten.com Git - openhab-addons.git/blob
4d2c8c915b1aadf74fd7575960ee28dca427dc68
[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.Optional;
17 import java.util.stream.Stream;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.netatmo.internal.api.data.EventSubType;
22 import org.openhab.binding.netatmo.internal.api.data.EventType;
23
24 import com.google.gson.annotations.SerializedName;
25
26 /**
27  * The {@link Event} holds information transferred by the webhook.
28  *
29  * @author GaĆ«l L'hopital - Initial contribution
30  *
31  */
32
33 @NonNullByDefault
34 public abstract class Event extends NAObject {
35     protected EventType type = EventType.UNKNOWN;
36     @SerializedName(value = "camera_id", alternate = { "module_id" })
37     private String cameraId = "";
38     protected String subType = "";
39
40     public abstract ZonedDateTime getTime();
41
42     public abstract @Nullable String getSnapshotUrl();
43
44     public abstract @Nullable String getPersonId();
45
46     public EventType getEventType() {
47         return type;
48     }
49
50     public String getCameraId() {
51         return cameraId;
52     }
53
54     @Override
55     public @Nullable String getName() {
56         String localMessage = super.getName();
57         return localMessage != null ? localMessage.replace("<b>", "").replace("</b>", "") : "";
58     }
59
60     public Optional<EventSubType> getSubTypeDescription() {
61         return Stream.of(EventSubType.values())
62                 .filter(v -> v.types.contains(getEventType()) && v.subType.equals(subType)).findFirst();
63     }
64 }