]> git.basschouten.com Git - openhab-addons.git/blob
6b42a529b2dd3a4f5164c6299a6d168118fca6a3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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 import org.openhab.binding.amazonechocontrol.internal.jsons.JsonDevices.Device;
21
22 /**
23  * The {@link JsonBluetoothStates} encapsulate the GSON data of bluetooth state
24  *
25  * @author Michael Geramb - Initial contribution
26  */
27 @NonNullByDefault
28 public class JsonBluetoothStates {
29
30     public @Nullable BluetoothState findStateByDevice(@Nullable Device device) {
31         if (device == null) {
32             return null;
33         }
34         @Nullable
35         BluetoothState @Nullable [] bluetoothStates = this.bluetoothStates;
36         if (bluetoothStates == null) {
37             return null;
38         }
39         for (BluetoothState state : bluetoothStates) {
40             if (state != null && Objects.equals(state.deviceSerialNumber, device.serialNumber)) {
41                 return state;
42             }
43         }
44         return null;
45     }
46
47     public @Nullable BluetoothState @Nullable [] bluetoothStates;
48
49     public static class PairedDevice {
50         public @Nullable String address;
51         public boolean connected;
52         public @Nullable String deviceClass;
53         public @Nullable String friendlyName;
54         public @Nullable List<String> profiles;
55     }
56
57     public static class BluetoothState {
58         public @Nullable String deviceSerialNumber;
59         public @Nullable String deviceType;
60         public @Nullable String friendlyName;
61         public boolean gadgetPaired;
62         public boolean online;
63         public @Nullable List<PairedDevice> pairedDeviceList;
64
65         public List<PairedDevice> getPairedDeviceList() {
66             return Objects.requireNonNullElse(pairedDeviceList, List.of());
67         }
68     }
69 }