From 370fecaa8adf574e04cd07a258397c67566848db Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sun, 10 Oct 2021 02:40:18 +0200 Subject: [PATCH] Fixed a bug where null device are returned on sync request --- .../hal/plugin/assistant/google/SmartHomeImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/SmartHomeImpl.java b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/SmartHomeImpl.java index cde8a85c..61f4b025 100644 --- a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/SmartHomeImpl.java +++ b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/SmartHomeImpl.java @@ -108,10 +108,8 @@ public class SmartHomeImpl extends SmartHomeApp implements OAuth2TokenRegistrati logger.log(Level.WARNING, "Unable to retrieve devices.", e); } - res.payload.agentUserId = userAgent; - res.payload.devices = new SyncResponse.Payload.Device[deviceList.size()]; - for (int i = 0; i < res.payload.devices.length; i++) { - HalAbstractDevice device = deviceList.get(i); + ArrayList responseDeviceList = new ArrayList<>(deviceList.size()); + for (HalAbstractDevice device : deviceList) { DeviceType type = DeviceType.getType(device); DeviceTrait[] traits = DeviceTraitFactory.getTraits(device); @@ -156,9 +154,13 @@ public class SmartHomeImpl extends SmartHomeApp implements OAuth2TokenRegistrati customDataJson.put("id", device.getId()); deviceBuilder.setCustomData(customDataJson); - res.payload.devices[i] = deviceBuilder.build(); + responseDeviceList.add(deviceBuilder.build()); } + res.payload.agentUserId = userAgent; + res.payload.devices = responseDeviceList.toArray( + new SyncResponse.Payload.Device[responseDeviceList.size()]); + return res; }