[kaleidescape] Add configuration option to auto load metadata channels without rules (#11231)

* Add configuration option to auto load metadata channels

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>

* Debug message

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein
2021-09-14 09:55:48 -05:00
committed by GitHub
parent f0df1a45cc
commit db935d3a3b
8 changed files with 101 additions and 53 deletions

View File

@@ -166,6 +166,7 @@ public class KaleidescapeBindingConstants {
public static final String GET_CONTENT_COLOR = "GET_CONTENT_COLOR";
public static final String SET_STATUS_CUE_PERIOD_1 = "SET_STATUS_CUE_PERIOD:1";
public static final String GET_TIME = "GET_TIME";
public static final String GET_CONTENT_DETAILS = "GET_CONTENT_DETAILS:";
public static final String LEAVE_STANDBY = "LEAVE_STANDBY";
public static final String ENTER_STANDBY = "ENTER_STANDBY";

View File

@@ -185,7 +185,7 @@ public abstract class KaleidescapeConnector {
*/
public void sendCommand(@Nullable String cmd, @Nullable String cachedMessage) throws KaleidescapeException {
// if sent a cachedMessage, just send out an event with the data so KaleidescapeMessageHandler will process it
if (cachedMessage != null) {
if (cmd != null && cachedMessage != null) {
logger.debug("Command: '{}' returning cached value: '{}'", cmd, cachedMessage);
// change GET_SOMETHING into SOMETHING and special case GET_PLAYING_TITLE_NAME into TITLE_NAME
dispatchKeyValue(cmd.replace("GET_", "").replace("PLAYING_TITLE_NAME", "TITLE_NAME"), cachedMessage, true);

View File

@@ -12,6 +12,8 @@
*/
package org.openhab.binding.kaleidescape.internal.communication;
import static org.openhab.binding.kaleidescape.internal.KaleidescapeBindingConstants.*;
import org.apache.commons.lang3.StringEscapeUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -23,7 +25,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
public class KaleidescapeFormatter {
public static String formatString(String input) {
if (!input.equals("")) {
if (!EMPTY.equals(input)) {
// convert || back to :
input = input.replace("||", ":");

View File

@@ -28,4 +28,6 @@ public class KaleidescapeThingConfiguration {
public @Nullable Integer updatePeriod;
public boolean volumeEnabled;
public Integer initialVolume = 0;
public boolean loadHighlightedDetails;
public boolean loadAlbumDetails;
}

View File

@@ -90,6 +90,8 @@ public class KaleidescapeHandler extends BaseThingHandler implements Kaleidescap
protected int volume = 0;
protected boolean volumeEnabled = false;
protected boolean isMuted = false;
protected boolean isLoadHighlightedDetails = false;
protected boolean isLoadAlbumDetails = false;
protected String friendlyName = EMPTY;
protected Object sequenceLock = new Object();
@@ -124,6 +126,8 @@ public class KaleidescapeHandler extends BaseThingHandler implements Kaleidescap
final String host = config.host;
final Integer port = config.port;
final Integer updatePeriod = config.updatePeriod;
this.isLoadHighlightedDetails = config.loadHighlightedDetails;
this.isLoadAlbumDetails = config.loadAlbumDetails;
if ((serialPort == null || serialPort.isEmpty()) && (host == null || host.isEmpty())) {
configError = "undefined serialPort and host configuration settings; please set one of them";
@@ -166,10 +170,10 @@ public class KaleidescapeHandler extends BaseThingHandler implements Kaleidescap
return;
}
updateStatus(ThingStatus.UNKNOWN);
scheduleReconnectJob();
schedulePollingJob();
updateStatus(ThingStatus.UNKNOWN);
}
@Override

View File

@@ -57,9 +57,19 @@ public enum KaleidescapeMessageHandler {
}
},
HIGHLIGHTED_SELECTION {
private final Logger logger = LoggerFactory.getLogger(KaleidescapeMessageHandler.class);
@Override
public void handleMessage(String message, KaleidescapeHandler handler) {
handler.updateChannel(KaleidescapeBindingConstants.HIGHLIGHTED_SELECTION, new StringType(message));
if (handler.isLoadHighlightedDetails) {
try {
handler.connector.sendCommand(GET_CONTENT_DETAILS + message + ":");
} catch (KaleidescapeException e) {
logger.debug("GET_CONTENT_DETAILS - exception loading content details for handle: {}", message);
}
}
}
},
DEVICE_POWER_STATE {
@@ -273,6 +283,15 @@ public enum KaleidescapeMessageHandler {
handler.updateChannel(MUSIC_ALBUM_HANDLE, new StringType(matcher.group(5)));
handler.updateChannel(MUSIC_NOWPLAY_HANDLE, new StringType(matcher.group(6)));
if (handler.isLoadAlbumDetails) {
try {
handler.connector.sendCommand(GET_CONTENT_DETAILS + matcher.group(5) + ":");
} catch (KaleidescapeException e) {
logger.debug("GET_CONTENT_DETAILS - exception loading album details for handle: {}",
matcher.group(5));
}
}
} else {
logger.debug("MUSIC_TITLE - no match on message: {}", message);
}

View File

@@ -42,5 +42,17 @@
<description>When the binding starts up, set the Inital Volume level to this value (Default 25).</description>
<default>25</default>
</parameter>
<parameter name="loadHighlightedDetails" type="boolean" required="false">
<label>Load Highlighted Details</label>
<description>When enabled the binding will automatically load the metadata channels when the selected item in the UI
(Movie or Album) changes.</description>
<default>false</default>
</parameter>
<parameter name="loadAlbumDetails" type="boolean" required="false">
<label>Load Album Details</label>
<description>When enabled the binding will automatically load the metadata channels for the currently playing Album.
Not applicable for Alto and Strato components.</description>
<default>false</default>
</parameter>
</config-description>
</config-description:config-descriptions>