import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Base64;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Random;
-import java.util.Scanner;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
}
public List<Device> getDeviceList() throws IOException, URISyntaxException, InterruptedException {
- String json = getDeviceListJson();
- JsonDevices devices = parseJson(json, JsonDevices.class);
- if (devices != null) {
- Device[] result = devices.devices;
- if (result != null) {
- return new ArrayList<>(Arrays.asList(result));
- }
- }
- return Collections.emptyList();
+ JsonDevices devices = Objects.requireNonNull(parseJson(getDeviceListJson(), JsonDevices.class));
+ logger.trace("Devices {}", devices.devices);
+
+ // @Nullable because of a limitation of the null-checker, we filter null-serialNumbers before
+ Set<@Nullable String> serialNumbers = ConcurrentHashMap.newKeySet();
+ return devices.devices.stream().filter(d -> d.serialNumber != null && serialNumbers.add(d.serialNumber))
+ .collect(Collectors.toList());
}
public String getDeviceListJson() throws IOException, URISyntaxException, InterruptedException {
@NonNullByDefault
public class AccountHandler extends BaseBridgeHandler implements IWebSocketCommandHandler, IAmazonThingHandler {
private final Logger logger = LoggerFactory.getLogger(AccountHandler.class);
- private Storage<String> stateStorage;
+ private final Storage<String> stateStorage;
private @Nullable Connection connection;
private @Nullable WebSocketConnection webSocketConnection;
if (devices != null) {
return devices;
}
- return Collections.emptyList();
+ return List.of();
}
public void setEnabledFlashBriefingsJson(String flashBriefingJson) {
*/
package org.openhab.binding.amazonechocontrol.internal.jsons;
+import java.util.Arrays;
+import java.util.List;
+
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
public @Nullable String softwareVersion;
public boolean online;
public @Nullable String @Nullable [] capabilities;
+
+ @Override
+ public String toString() {
+ return "Device{" + "accountName='" + accountName + '\'' + ", serialNumber='" + serialNumber + '\''
+ + ", deviceOwnerCustomerId='" + deviceOwnerCustomerId + '\'' + ", deviceAccountId='"
+ + deviceAccountId + '\'' + ", deviceFamily='" + deviceFamily + '\'' + ", deviceType='" + deviceType
+ + '\'' + ", softwareVersion='" + softwareVersion + '\'' + ", online=" + online + ", capabilities="
+ + Arrays.toString(capabilities) + '}';
+ }
}
- public @Nullable Device @Nullable [] devices;
+ public List<Device> devices = List.of();
}