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

View File

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