mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[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:
parent
1f17e53bc2
commit
1b23f2beac
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user