[freeboxos] Fix thing status handling when rebooting the player (#17238)

Fix #17227

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2024-08-13 13:11:20 +02:00 committed by GitHub
parent 1f17e53bc2
commit 1b23f2beac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 63 additions and 6 deletions

View File

@ -30,6 +30,7 @@ import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.binding.ThingHandlerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -50,6 +51,7 @@ public class ActivePlayerHandler extends PlayerHandler implements FreeDeviceIntf
public ActivePlayerHandler(Thing thing) {
super(thing);
statusDrivenByLanConnectivity = false;
eventChannelUID = new ChannelUID(getThing().getUID(), SYS_INFO, BOX_EVENT);
}
@ -69,9 +71,24 @@ public class ActivePlayerHandler extends PlayerHandler implements FreeDeviceIntf
@Override
protected void internalPoll() throws FreeboxException {
super.internalPoll();
if (thing.getStatus().equals(ThingStatus.ONLINE)) {
poll();
}
@Override
protected void internalForcePoll() throws FreeboxException {
super.internalForcePoll();
poll();
}
private void poll() throws FreeboxException {
if (reachable) {
Player player = getManager(PlayerManager.class).getDevice(getClientId());
updateStatus(player.reachable() ? ThingStatus.ONLINE : ThingStatus.OFFLINE);
logger.debug("{}: poll with player.reachable() = {}", thing.getUID(), player.reachable());
if (player.reachable()) {
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-player-not-reachable");
}
if (player.reachable()) {
Status status = getManager(PlayerManager.class).getPlayerStatus(getClientId());
if (status != null) {
@ -89,6 +106,9 @@ public class ActivePlayerHandler extends PlayerHandler implements FreeDeviceIntf
}
}
updateChannelQuantity(SYS_INFO, UPTIME, uptime, Units.SECOND);
} else {
logger.debug("{}: poll with reachable={}", thing.getUID(), reachable);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-player-not-reachable");
}
}

View File

@ -218,7 +218,7 @@ public abstract class ApiConsumerHandler extends BaseThingHandler implements Api
ThingStatusDetail detail = thing.getStatusInfo().getStatusDetail();
if (ThingStatusDetail.DUTY_CYCLE.equals(detail)) {
try {
internalPoll();
internalForcePoll();
} catch (FreeboxException ignore) {
// An exception is normal if the box is rebooting then let's try again later...
addJob("Initialize", this::initialize, 10, TimeUnit.SECONDS);

View File

@ -28,6 +28,7 @@ import org.openhab.binding.freeboxos.internal.api.rest.WebSocketManager;
import org.openhab.binding.freeboxos.internal.config.ApiConsumerConfiguration;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.binding.ThingHandlerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,6 +47,8 @@ public class HostHandler extends ApiConsumerHandler {
// We start in pull mode and switch to push after a first update...
protected boolean pushSubscribed = false;
protected boolean statusDrivenByLanConnectivity = true;
protected boolean reachable;
private int tryConfigureMediaSink = 1;
@ -93,7 +96,8 @@ public class HostHandler extends ApiConsumerHandler {
LanHost host = getLanHost();
updateConnectivityChannels(host);
logger.debug("Switching to push mode - refreshInterval will now be ignored for Connectivity data");
logger.debug("{}: switching to push mode - refreshInterval will now be ignored for Connectivity data",
thing.getUID());
pushSubscribed = getManager(WebSocketManager.class).registerListener(host.getMac(), this);
}
@ -114,10 +118,17 @@ public class HostHandler extends ApiConsumerHandler {
}
public void updateConnectivityChannels(LanHost host) {
logger.debug("{}: updateConnectivityChannels with host.reachable() = {}", thing.getUID(), host.reachable());
updateChannelOnOff(CONNECTIVITY, REACHABLE, host.reachable());
updateChannelDateTimeState(CONNECTIVITY, LAST_SEEN, host.getLastSeen());
updateChannelString(CONNECTIVITY, IP_ADDRESS, host.getIpv4());
updateStatus(host.reachable() ? ThingStatus.ONLINE : ThingStatus.OFFLINE);
if (statusDrivenByLanConnectivity) {
if (host.reachable()) {
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-host-not-reachable");
}
}
// We will check and configure audio sink only when the host reachability changed
if (reachable != host.reachable()) {
reachable = host.reachable();

View File

@ -66,7 +66,16 @@ public class RepeaterHandler extends HostHandler implements FreeDeviceIntf {
@Override
protected void internalPoll() throws FreeboxException {
super.internalPoll();
poll();
}
@Override
protected void internalForcePoll() throws FreeboxException {
super.internalForcePoll();
poll();
}
private void poll() throws FreeboxException {
if (!thing.getStatus().equals(ThingStatus.ONLINE)) {
return;
}

View File

@ -24,6 +24,7 @@ import org.openhab.binding.freeboxos.internal.api.rest.VmManager.VirtualMachine;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -75,7 +76,11 @@ public class VmHandler extends HostHandler {
boolean running = Status.RUNNING.equals(vm.status());
updateChannelOnOff(VM_STATUS, STATUS, running);
updateChannelOnOff(CONNECTIVITY, REACHABLE, running);
updateStatus(running ? ThingStatus.ONLINE : ThingStatus.OFFLINE);
if (running) {
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-vm-not-running");
}
}
@Override

View File

@ -57,7 +57,16 @@ public class WifiStationHandler extends HostHandler {
@Override
protected void internalPoll() throws FreeboxException {
super.internalPoll();
poll();
}
@Override
protected void internalForcePoll() throws FreeboxException {
super.internalForcePoll();
poll();
}
private void poll() throws FreeboxException {
MACAddress mac = getMac();
if (mac == null) {
throw new FreeboxException(

View File

@ -355,6 +355,9 @@ channel-type.freeboxos.wifi-status.description = Indicates whether the wifi netw
# messages
info-conf-pending = Please accept pairing request directly on your freebox
info-host-not-reachable = Host is not reachable
info-player-not-reachable = Player is not reachable
info-vm-not-running = VM is not running
# iconprovider