Skip to content

Commit

Permalink
[squeezebox] Add I18N support for Thing status descriptions (#18344)
Browse files Browse the repository at this point in the history
* Add I18N support for thing status descriptions

Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur authored Mar 1, 2025
1 parent 8623016 commit 7268276
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ private void updateThingStatus() {
if (bridgeStatus == ThingStatus.OFFLINE) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
} else if (!this.connected) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE);
updateStatus(ThingStatus.OFFLINE);
} else if (bridgeStatus == ThingStatus.ONLINE && getThing().getStatus() != ThingStatus.ONLINE) {
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
updateStatus(ThingStatus.ONLINE);
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Bridge not found");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"@text/offline.conf-error.bridge-not-found");
}
}

Expand Down Expand Up @@ -485,18 +486,24 @@ private RawType downloadImage(String mac, String url) {
// Only get the image if this is my PlayerHandler instance
if (isMe(mac)) {
if (url != null && !url.isEmpty()) {
String sanitizedUrl = sanitizeUrl(url);
RawType image = IMAGE_CACHE.putIfAbsentAndGet(url, () -> {
logger.debug("Trying to download the content of URL {}", sanitizedUrl);
if (logger.isDebugEnabled()) {
logger.debug("Trying to download the content of URL {}", sanitizeUrl(url));
}
try {
return HttpUtil.downloadImage(url);
} catch (IllegalArgumentException e) {
logger.debug("IllegalArgumentException when downloading image from {}", sanitizedUrl, e);
if (logger.isDebugEnabled()) {
logger.debug("IllegalArgumentException when downloading image from {}", sanitizeUrl(url),
e);
}
return null;
}
});
if (image == null) {
logger.debug("Failed to download the content of URL {}", sanitizedUrl);
if (logger.isDebugEnabled()) {
logger.debug("Failed to download the content of URL {}", sanitizeUrl(url));
}
return null;
} else {
return image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ private void connect() {
this.password = config.password;

if (host.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, "host is not set");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
"@text/offline.conf-error.host-not-set");
return;
}
// Create URL for jsonrpc interface
Expand Down Expand Up @@ -486,7 +487,6 @@ public void run() {
}
} catch (IOException e) {
if (!terminate) {
logger.warn("failed to read line from squeeze server socket: {}", e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
scheduleReconnect();
}
Expand All @@ -503,9 +503,8 @@ public void run() {

// check for end of stream from readLine
if (endOfStream && !terminate) {
logger.info("end of stream received from socket during readLine");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"end of stream on socket read");
"@text/offline.comm-error.end-of-stream");
scheduleReconnect();
}
if (requestFavoritesJob != null && !requestFavoritesJob.isDone()) {
Expand Down Expand Up @@ -648,8 +647,9 @@ private void handleMixerMessage(String mac, String[] messageParts) {
});
break;
default:
logger.trace("Unhandled mixer message type '{}'", Arrays.toString(messageParts));

if (logger.isTraceEnabled()) {
logger.trace("Unhandled mixer message type '{}'", Arrays.toString(messageParts));
}
}
}

Expand All @@ -666,7 +666,9 @@ private void handleClientMessage(final String mac, String[] messageParts) {
} else if ("disconnect".equals(action) || "forget".equals(action)) {
connected = false;
} else {
logger.trace("Unhandled client message type '{}'", Arrays.toString(messageParts));
if (logger.isTraceEnabled()) {
logger.trace("Unhandled client message type '{}'", Arrays.toString(messageParts));
}
return;
}

Expand Down Expand Up @@ -876,7 +878,9 @@ private void handlePlaylistMessage(final String mac, String[] messageParts) {
return;
} else {
// Added so that actions (such as delete, index, jump, open) are not treated as "play"
logger.trace("Unhandled playlist message type '{}'", Arrays.toString(messageParts));
if (logger.isTraceEnabled()) {
logger.trace("Unhandled playlist message type '{}'", Arrays.toString(messageParts));
}
return;
}
final String value = mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,9 @@ channel-type.squeezebox.year.description = Release year of the current song

channel-type.config.squeezebox.favoritesList.quoteList.label = Quote Favorites
channel-type.config.squeezebox.favoritesList.quoteList.description = Wrap the right hand side of the favorites in quotes

# thing status descriptions

offline.conf-error.bridge-not-found = Bridge not found
offline.conf-error.host-not-set = host is not set
offline.comm-error.end-of-stream = end of stream on socket read

0 comments on commit 7268276

Please sign in to comment.