Fix Essentia G standby mode wake-up (#14321)

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein 2023-02-03 22:53:27 -06:00 committed by GitHub
parent 03f17019d1
commit a8267bc4fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -43,15 +43,13 @@ public abstract class NuvoConnector {
private static final String QUERY = "?";
private static final String VER_STR_E6 = "#VER\"NV-E6G";
private static final String VER_STR_GC = "#VER\"NV-I8G";
private static final String ALL_OFF = "#ALLOFF";
private static final String ALLOFF = "#ALLOFF";
private static final String MUTE = "#MUTE";
private static final String PAGE = "#PAGE";
private static final String RESTART = "#RESTART\"NuVoNet\"";
private static final String PING = "#PING";
private static final String PING_RESPONSE = "PING";
private static final byte[] WAKE_STR = "\r".getBytes(StandardCharsets.US_ASCII);
private static final Pattern SRC_PATTERN = Pattern.compile("^#S(\\d{1})(.*)$");
private static final Pattern ZONE_PATTERN = Pattern.compile("^#Z(\\d{1,2}),(.*)$");
private static final Pattern ZONE_SOURCE_PATTERN = Pattern.compile("^#Z(\\d{1,2})S(\\d{1})(.*)$");
@ -88,6 +86,7 @@ public abstract class NuvoConnector {
private List<NuvoMessageEventListener> listeners = new ArrayList<>();
private boolean isEssentia = true;
private boolean isStandbyMode = true;
private boolean isAnyOhNuvoNet = false;
/**
@ -275,7 +274,7 @@ public abstract class NuvoConnector {
*
* @throws NuvoException - In case of any problem
*/
public void sendCommand(@Nullable String command) throws NuvoException {
public void sendCommand(String command) throws NuvoException {
String messageStr = BEGIN_CMD + command + END_CMD;
logger.debug("sending command: {}", messageStr);
@ -285,11 +284,12 @@ public abstract class NuvoConnector {
throw new NuvoException("Send command \"" + messageStr + "\" failed: output stream is null");
}
try {
// Essentia G needs time to wake up when in standby mode
// I don't want to track that in the binding, so just do this always
if (this.isEssentia) {
dataOut.write(WAKE_STR);
dataOut.flush();
// The Essentia G needs to be awake before processing ON commands when in standby mode
// Repeat the command being sent to force it awake
// Sending carriage returns as described in the documentation was not working
if (isEssentia && isStandbyMode
&& (command.endsWith(ON) || NuvoCommand.PAGE_ON.getValue().equals(command))) {
messageStr += messageStr;
}
dataOut.write(messageStr.getBytes(StandardCharsets.US_ASCII));
dataOut.flush();
@ -353,7 +353,8 @@ public abstract class NuvoConnector {
return;
}
if (message.equals(ALL_OFF)) {
if (message.equals(ALLOFF)) {
isStandbyMode = true;
dispatchKeyValue(TYPE_ALLOFF, BLANK);
return;
}
@ -405,6 +406,9 @@ public abstract class NuvoConnector {
matcher = ZONE_PATTERN.matcher(message);
if (matcher.find()) {
dispatchKeyValue(TYPE_ZONE_UPDATE, matcher.group(1), BLANK, matcher.group(2));
if (message.contains(ON)) {
isStandbyMode = false;
}
return;
}

View File

@ -378,7 +378,7 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
return Collections.singletonList(NuvoThingActions.class);
}
public void handleRawCommand(@Nullable String command) {
public void handleRawCommand(String command) {
synchronized (sequenceLock) {
try {
connector.sendCommand(command);