]> git.basschouten.com Git - openhab-addons.git/blob
a989bdcbec252523e0a40748c929200d2ac642eb
[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.amazonechocontrol.internal.jsons;
14
15 import java.util.List;
16 import java.util.Objects;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 import com.google.gson.Gson;
22 import com.google.gson.JsonSyntaxException;
23
24 /**
25  * The {@link JsonActivities} encapsulate the GSON data of the push command for push activity
26  *
27  * @author Michael Geramb - Initial contribution
28  */
29 @NonNullByDefault
30 public class JsonActivities {
31
32     public @Nullable List<Activity> activities;
33
34     public static class Activity {
35         public @Nullable String activityStatus;
36         public @Nullable Long creationTimestamp;
37         public @Nullable String description;
38         public @Nullable Object domainAttributes;
39         public @Nullable Object domainType;
40         public @Nullable Object feedbackAttributes;
41         public @Nullable String id;
42         public @Nullable String intentType;
43         public @Nullable String providerInfoDescription;
44         public @Nullable String registeredCustomerId;
45         public @Nullable Object sourceActiveUsers;
46         public @Nullable List<SourceDeviceId> sourceDeviceIds;
47         public @Nullable String utteranceId;
48         public @Nullable Long version;
49
50         public List<SourceDeviceId> getSourceDeviceIds() {
51             return Objects.requireNonNullElse(sourceDeviceIds, List.of());
52         }
53
54         public static class SourceDeviceId {
55             public @Nullable String deviceAccountId;
56             public @Nullable String deviceType;
57             public @Nullable String serialNumber;
58         }
59
60         public static class Description {
61             public @Nullable String summary;
62             public @Nullable String firstUtteranceId;
63             public @Nullable String firstStreamId;
64         }
65
66         public Description parseDescription() {
67             String description = this.description;
68             if (description == null || description.isEmpty() || !description.startsWith("{")
69                     || !description.endsWith("}")) {
70                 return new Description();
71             }
72             Gson gson = new Gson();
73             try {
74                 Description description1 = gson.fromJson(description, Description.class);
75                 return description1 != null ? description1 : new Description();
76             } catch (JsonSyntaxException e) {
77                 return new Description();
78             }
79         }
80     }
81 }