]> git.basschouten.com Git - openhab-addons.git/commitdiff
[squeezebox] Add sleep channel (#10196)
authorMark Hilbush <mark@hilbush.com>
Thu, 25 Feb 2021 21:56:02 +0000 (16:56 -0500)
committerGitHub <noreply@github.com>
Thu, 25 Feb 2021 21:56:02 +0000 (13:56 -0800)
Signed-off-by: Mark Hilbush <mark@hilbush.com>
bundles/org.openhab.binding.squeezebox/README.md
bundles/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/SqueezeBoxBindingConstants.java
bundles/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/handler/SqueezeBoxPlayerHandler.java
bundles/org.openhab.binding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/handler/SqueezeBoxServerHandler.java
bundles/org.openhab.binding.squeezebox/src/main/resources/OH-INF/thing/thing-types.xml

index f54efad10e2295b0fa3d29fca79567d8bcc04806..5f9da040347ab2ecc286ca003dcef6d465a1af62 100644 (file)
@@ -119,6 +119,7 @@ All devices support some of the following channels:
 | numberPlaylistTracks    | Number    | Number of playlist tracks                                                              |
 | playFavorite            | String    | ID of Favorite to play (channel's state options contains available favorites)          |
 | rate                    | Switch    | "Like" or "unlike" the currently playing song (if supported by the streaming service)  |
+| sleep                   | Number    | Power off the player in the specified number of minutes. Sending 0 cancels the timer   |
 
 ## Example .Items File
 
index 632797f280e2c49ca4d42f1e45194c803be30b64..dcd9771772a9eb039e2d8b1bd6398ececb2f25e6 100644 (file)
@@ -68,4 +68,5 @@ public class SqueezeBoxBindingConstants {
     public static final String CHANNEL_MODEL = "model";
     public static final String CHANNEL_FAVORITES_PLAY = "playFavorite";
     public static final String CHANNEL_RATE = "rate";
+    public static final String CHANNEL_SLEEP = "sleep";
 }
index a29082516b334280de325420fe7f5acbce8f016e..aa02f8e479e9303538ac455f664bca6a21f0ff70 100644 (file)
@@ -16,6 +16,7 @@ import static org.openhab.binding.squeezebox.internal.SqueezeBoxBindingConstants
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -308,6 +309,16 @@ public class SqueezeBoxPlayerHandler extends BaseThingHandler implements Squeeze
                     squeezeBoxServerHandler.rate(mac, unlikeCommand);
                 }
                 break;
+            case CHANNEL_SLEEP:
+                if (command instanceof DecimalType) {
+                    Duration sleepDuration = Duration.ofMinutes(((DecimalType) command).longValue());
+                    if (sleepDuration.isNegative() || sleepDuration.compareTo(Duration.ofDays(1)) > 0) {
+                        logger.debug("Sleep timer of {} minutes must be >= 0 and <= 1 day", sleepDuration.toMinutes());
+                        return;
+                    }
+                    squeezeBoxServerHandler.sleep(mac, sleepDuration);
+                }
+                break;
             default:
                 break;
         }
index fcc20b29a67a91fd70d8b0da2cdb35d1a38cbdc4..a8e8c1d92657b470292df95d2f3c5eb03ca446ea 100644 (file)
@@ -301,6 +301,10 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
         }
     }
 
+    public void sleep(String mac, Duration sleepDuration) {
+        sendCommand(mac + " sleep " + String.valueOf(sleepDuration.toSeconds()));
+    }
+
     /**
      * Send a generic command to a given player
      *
index 24816a8060e8f97529732e6e3b109ddde20bae45..d0e872e68d9319058c05a8432ed66124bacfdfed 100644 (file)
@@ -84,6 +84,7 @@
                        <channel id="numberPlaylistTracks" typeId="numberPlaylistTracks"/>
                        <channel id="playFavorite" typeId="playFavorite"/>
                        <channel id="rate" typeId="rate"/>
+                       <channel id="sleep" typeId="sleep"/>
                </channels>
 
                <properties>
                <label>Like or Unlike Song</label>
                <description>Likes or unlikes the current song (if the service supports it)</description>
        </channel-type>
+       <channel-type id="sleep">
+               <item-type>Number</item-type>
+               <label>Sleep</label>
+               <description>Power off player in specified number of minutes</description>
+               <state pattern="%d"></state>
+       </channel-type>
 </thing:thing-descriptions>