]> git.basschouten.com Git - openhab-addons.git/commitdiff
Fix Essentia G standby mode wake-up (#14321)
authormlobstein <michael.lobstein@gmail.com>
Sat, 4 Feb 2023 04:53:27 +0000 (22:53 -0600)
committerGitHub <noreply@github.com>
Sat, 4 Feb 2023 04:53:27 +0000 (05:53 +0100)
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/communication/NuvoConnector.java
bundles/org.openhab.binding.nuvo/src/main/java/org/openhab/binding/nuvo/internal/handler/NuvoHandler.java

index f8da60b440519750caedff5444d76fbc748e7354..6ce667192c7b78e74810d947e26f3f1e396b74f5 100644 (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;
         }
 
index f74cd282aac5478da18ead96ea3d97eac9275168..cdb907b4c59822d43c8ac75156fee0a29c1178d2 100644 (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);