[squeezebox] Map server connection state to thing status. (#10778)
If a player goes offline (it e.g. lost power or network connection), mark it as such in the thing status. Signed-off-by: Danny Baumann <dannybaumann@web.de>
This commit is contained in:
parent
6403e03cea
commit
ba2a33947d
|
@ -211,4 +211,8 @@ public class SqueezeBoxPlayerDiscoveryParticipant extends AbstractDiscoveryServi
|
||||||
@Override
|
@Override
|
||||||
public void buttonsChangeEvent(String mac, String likeCommand, String unlikeCommand) {
|
public void buttonsChangeEvent(String mac, String likeCommand, String unlikeCommand) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectedStateChangeEvent(String mac, boolean connected) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,4 +220,8 @@ public final class SqueezeBoxNotificationListener implements SqueezeBoxPlayerEve
|
||||||
@Override
|
@Override
|
||||||
public void buttonsChangeEvent(String mac, String likeCommand, String unlikeCommand) {
|
public void buttonsChangeEvent(String mac, String likeCommand, String unlikeCommand) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectedStateChangeEvent(String mac, boolean connected) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,4 +82,6 @@ public interface SqueezeBoxPlayerEventListener {
|
||||||
void sourceChangeEvent(String mac, String source);
|
void sourceChangeEvent(String mac, String source);
|
||||||
|
|
||||||
void buttonsChangeEvent(String mac, String likeCommand, String unlikeCommand);
|
void buttonsChangeEvent(String mac, String likeCommand, String unlikeCommand);
|
||||||
|
|
||||||
|
void connectedStateChangeEvent(String mac, boolean connected);
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ public class SqueezeBoxPlayerHandler extends BaseThingHandler implements Squeeze
|
||||||
|
|
||||||
private String likeCommand;
|
private String likeCommand;
|
||||||
private String unlikeCommand;
|
private String unlikeCommand;
|
||||||
|
private boolean connected = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates SqueezeBox Player Handler
|
* Creates SqueezeBox Player Handler
|
||||||
|
@ -141,24 +142,31 @@ public class SqueezeBoxPlayerHandler extends BaseThingHandler implements Squeeze
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
mac = getConfig().as(SqueezeBoxPlayerConfig.class).mac;
|
mac = getConfig().as(SqueezeBoxPlayerConfig.class).mac;
|
||||||
timeCounter();
|
timeCounter();
|
||||||
updateBridgeStatus();
|
updateThingStatus();
|
||||||
logger.debug("player thing {} initialized with mac {}", getThing().getUID(), mac);
|
logger.debug("player thing {} initialized with mac {}", getThing().getUID(), mac);
|
||||||
|
if (squeezeBoxServerHandler != null) {
|
||||||
|
// ensure we get an up-to-date connection state
|
||||||
|
squeezeBoxServerHandler.requestPlayers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
|
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
|
||||||
updateBridgeStatus();
|
updateThingStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBridgeStatus() {
|
private void updateThingStatus() {
|
||||||
Thing bridge = getBridge();
|
Thing bridge = getBridge();
|
||||||
if (bridge != null) {
|
if (bridge != null) {
|
||||||
squeezeBoxServerHandler = (SqueezeBoxServerHandler) bridge.getHandler();
|
squeezeBoxServerHandler = (SqueezeBoxServerHandler) bridge.getHandler();
|
||||||
ThingStatus bridgeStatus = bridge.getStatus();
|
ThingStatus bridgeStatus = bridge.getStatus();
|
||||||
if (bridgeStatus == ThingStatus.ONLINE && getThing().getStatus() != ThingStatus.ONLINE) {
|
|
||||||
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
|
if (bridgeStatus == ThingStatus.OFFLINE) {
|
||||||
} else if (bridgeStatus == ThingStatus.OFFLINE) {
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
|
} else if (!this.connected) {
|
||||||
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE);
|
||||||
|
} else if (bridgeStatus == ThingStatus.ONLINE && getThing().getStatus() != ThingStatus.ONLINE) {
|
||||||
|
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Bridge not found");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Bridge not found");
|
||||||
|
@ -527,6 +535,14 @@ public class SqueezeBoxPlayerHandler extends BaseThingHandler implements Squeeze
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectedStateChangeEvent(String mac, boolean connected) {
|
||||||
|
if (isMe(mac)) {
|
||||||
|
this.connected = connected;
|
||||||
|
updateThingStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFavoritesListEvent(List<Favorite> favorites) {
|
public void updateFavoritesListEvent(List<Favorite> favorites) {
|
||||||
logger.trace("Player {} updating favorites list with {} favorites", mac, favorites.size());
|
logger.trace("Player {} updating favorites list with {} favorites", mac, favorites.size());
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Arrays;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -535,6 +536,8 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePlayersList(String message) {
|
private void handlePlayersList(String message) {
|
||||||
|
final Set<String> connectedPlayers = new HashSet<>();
|
||||||
|
|
||||||
// Split out players
|
// Split out players
|
||||||
String[] playersList = message.split("playerindex\\S*\\s");
|
String[] playersList = message.split("playerindex\\S*\\s");
|
||||||
for (String playerParams : playersList) {
|
for (String playerParams : playersList) {
|
||||||
|
@ -571,6 +574,10 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
|
||||||
player.setName(parameter.substring(parameter.indexOf(":") + 1));
|
player.setName(parameter.substring(parameter.indexOf(":") + 1));
|
||||||
} else if (parameter.startsWith("model:")) {
|
} else if (parameter.startsWith("model:")) {
|
||||||
player.setModel(parameter.substring(parameter.indexOf(":") + 1));
|
player.setModel(parameter.substring(parameter.indexOf(":") + 1));
|
||||||
|
} else if (parameter.startsWith("connected:")) {
|
||||||
|
if ("1".equals(parameter.substring(parameter.indexOf(":") + 1))) {
|
||||||
|
connectedPlayers.add(macAddress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,6 +594,11 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
|
||||||
sendCommand(player.getMacAddress() + " status - 1 subscribe:10 tags:yagJlNKjc");
|
sendCommand(player.getMacAddress() + " status - 1 subscribe:10 tags:yagJlNKjc");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (final SqueezeBoxPlayer player : players.values()) {
|
||||||
|
final String mac = player.getMacAddress();
|
||||||
|
final boolean connected = connectedPlayers.contains(mac);
|
||||||
|
updatePlayer(listener -> listener.connectedStateChangeEvent(mac, connected));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePlayerUpdate(String message) {
|
private void handlePlayerUpdate(String message) {
|
||||||
|
@ -601,6 +613,9 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
|
||||||
// get the message type
|
// get the message type
|
||||||
String messageType = messageParts[1];
|
String messageType = messageParts[1];
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
|
case "client":
|
||||||
|
handleClientMessage(mac, messageParts);
|
||||||
|
break;
|
||||||
case "status":
|
case "status":
|
||||||
handleStatusMessage(mac, messageParts);
|
handleStatusMessage(mac, messageParts);
|
||||||
break;
|
break;
|
||||||
|
@ -662,6 +677,26 @@ public class SqueezeBoxServerHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleClientMessage(final String mac, String[] messageParts) {
|
||||||
|
if (messageParts.length < 3) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String action = messageParts[2];
|
||||||
|
final boolean connected;
|
||||||
|
|
||||||
|
if ("new".equals(action) || "reconnect".equals(action)) {
|
||||||
|
connected = true;
|
||||||
|
} else if ("disconnect".equals(action) || "forget".equals(action)) {
|
||||||
|
connected = false;
|
||||||
|
} else {
|
||||||
|
logger.trace("Unhandled client message type '{}'", Arrays.toString(messageParts));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePlayer(listener -> listener.connectedStateChangeEvent(mac, connected));
|
||||||
|
}
|
||||||
|
|
||||||
private void handleStatusMessage(final String mac, String[] messageParts) {
|
private void handleStatusMessage(final String mac, String[] messageParts) {
|
||||||
String remoteTitle = "", artist = "", album = "", genre = "", year = "";
|
String remoteTitle = "", artist = "", album = "", genre = "", year = "";
|
||||||
boolean coverart = false;
|
boolean coverart = false;
|
||||||
|
|
Loading…
Reference in New Issue