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.amazonechocontrol.internal.jsons;
15 import java.util.List;
16 import java.util.Objects;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
21 import com.google.gson.Gson;
22 import com.google.gson.JsonSyntaxException;
25 * The {@link JsonActivities} encapsulate the GSON data of the push command for push activity
27 * @author Michael Geramb - Initial contribution
30 public class JsonActivities {
32 public @Nullable List<Activity> activities;
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;
50 public List<SourceDeviceId> getSourceDeviceIds() {
51 return Objects.requireNonNullElse(sourceDeviceIds, List.of());
54 public static class SourceDeviceId {
55 public @Nullable String deviceAccountId;
56 public @Nullable String deviceType;
57 public @Nullable String serialNumber;
60 public static class Description {
61 public @Nullable String summary;
62 public @Nullable String firstUtteranceId;
63 public @Nullable String firstStreamId;
66 public Description parseDescription() {
67 String description = this.description;
68 if (description == null || description.isEmpty() || !description.startsWith("{")
69 || !description.endsWith("}")) {
70 return new Description();
72 Gson gson = new Gson();
74 Description description1 = gson.fromJson(description, Description.class);
75 return description1 != null ? description1 : new Description();
76 } catch (JsonSyntaxException e) {
77 return new Description();