Skip to content

Commit

Permalink
[amazonechocontrol] Broken last voice command on Fire TV Cube (#592)
Browse files Browse the repository at this point in the history
* fixed: missing Content-Length header (BodyPublisher.ofByteArrays JDK 17 issue)

Signed-off-by: Tom Blum [email protected]

* fixed: commited line endings

Signed-off-by: Tom Blum [email protected]

* removed: logger

Signed-off-by: Tom Blum [email protected]

* fixed: boken last voice command on Fire TV Cube

Signed-off-by: Tom Blum <[email protected]>

* fixed: spotless aso

Signed-off-by: Tom Blum <[email protected]>

* review

Signed-off-by: Jan N. Klug <[email protected]>

---------

Signed-off-by: Tom Blum [email protected]
Signed-off-by: Tom Blum <[email protected]>
Signed-off-by: Jan N. Klug <[email protected]>
Co-authored-by: Jan N. Klug <[email protected]>
  • Loading branch information
Trinitus01 and J-N-K authored Oct 13, 2024
1 parent 97ea751 commit 5e77661
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -115,6 +116,7 @@ public class AccountHandler extends BaseBridgeHandler implements PushConnection.
private final Map<String, EchoHandler> echoHandlers = new ConcurrentHashMap<>();
private final Set<SmartHomeDeviceHandler> smartHomeDeviceHandlers = new CopyOnWriteArraySet<>();
private final Set<FlashBriefingProfileHandler> flashBriefingProfileHandlers = new CopyOnWriteArraySet<>();
private final Set<String> deviceSerialNumbers = new CopyOnWriteArraySet<>();

private final Object synchronizeConnection = new Object();
private Map<String, DeviceTO> serialNumberDeviceMapping = new HashMap<>();
Expand Down Expand Up @@ -593,7 +595,8 @@ private EnabledFeedTO copyFeed(EnabledFeedTO feed) {
public void onPushCommandReceived(PushCommandTO pushCommand) {
logger.debug("Processing {}", pushCommand);
String payload = pushCommand.payload;
switch (pushCommand.command) {
String command = pushCommand.command;
switch (command) {
case "PUSH_ACTIVITY":
// currently unused, seems to be removed, log a warning if it re-appears
logger.warn("Activity detected: {}", pushCommand);
Expand Down Expand Up @@ -624,15 +627,15 @@ public void onPushCommandReceived(PushCommandTO pushCommand) {
if (echoHandler == null) {
return;
}
echoHandler.handlePushCommand(pushCommand.command, payload);
if ("PUSH_EQUALIZER_STATE_CHANGE".equals(pushCommand.command)
|| "PUSH_VOLUME_CHANGE".equals(pushCommand.command)) {
echoHandler.handlePushCommand(command, payload);
if ("PUSH_EQUALIZER_STATE_CHANGE".equals(command) || "PUSH_VOLUME_CHANGE".equals(command)) {
deviceSerialNumbers.add(dopplerId.deviceSerialNumber);
ScheduledFuture<?> refreshActivityJob = this.refreshActivityJob;
if (refreshActivityJob != null) {
refreshActivityJob.cancel(false);
}
this.refreshActivityJob = scheduler.schedule(
() -> handlePushActivity(dopplerId.deviceSerialNumber, pushCommand.timeStamp),
() -> handlePushActivity(deviceSerialNumbers, pushCommand.timeStamp),
handlerConfig.activityRequestDelay, TimeUnit.SECONDS);
}
}
Expand Down Expand Up @@ -670,15 +673,24 @@ private List<CustomerHistoryRecordTO> getCustomerActivity(@Nullable Long timesta
return connection.getActivities(startTimestamp, endTimestamp);
}

private void handlePushActivity(String deviceSerialNumber, @Nullable Long timestamp) {
private void handlePushActivity(Set<String> deviceSerialNumbers, @Nullable Long timestamp) {
List<CustomerHistoryRecordTO> activityRecords = getCustomerActivity(timestamp);
EchoHandler echoHandler = echoHandlers.get(deviceSerialNumber);
if (echoHandler == null) {
logger.warn("Could not find thing handler for serialnumber {}", deviceSerialNumber);
return;

Iterator<String> iterator = deviceSerialNumbers.iterator();
while (iterator.hasNext()) {
try {
String deviceSerialNumber = iterator.next();
EchoHandler echoHandler = echoHandlers.get(deviceSerialNumber);
if (echoHandler == null) {
logger.warn("Could not find thing handler for serialnumber {}", deviceSerialNumber);
return;
}
activityRecords.stream().filter(r -> r.recordKey.endsWith(deviceSerialNumber))
.forEach(echoHandler::handlePushActivity);
} finally {
iterator.remove();
}
}
activityRecords.stream().filter(r -> r.recordKey.endsWith(deviceSerialNumber))
.forEach(echoHandler::handlePushActivity);
}

private @Nullable SmartHomeBaseDevice findSmartHomeDeviceJson(SmartHomeDeviceHandler handler) {
Expand Down

0 comments on commit 5e77661

Please sign in to comment.