mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
[freeboxos] Mark unknown freeplug mac as OFFLINE (#20611)
* Check if the freeplug mac is known by REST api. Signed-off-by: gael@lhopital.org <gael@lhopital.org>
This commit is contained in:
+3
-3
@@ -15,9 +15,9 @@ package org.openhab.binding.freeboxos.internal.api.rest;
|
||||
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.THING_FREEPLUG;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.freeboxos.internal.api.FreeboxException;
|
||||
import org.openhab.binding.freeboxos.internal.api.Response;
|
||||
|
||||
@@ -73,8 +73,8 @@ public class FreeplugManager extends RestManager {
|
||||
return get(Networks.class).stream().map(Network::members).flatMap(List::stream).toList();
|
||||
}
|
||||
|
||||
public Optional<Freeplug> getPlug(MACAddress mac) throws FreeboxException {
|
||||
return getPlugs().stream().filter(plug -> plug.id.equals(mac)).findFirst();
|
||||
public @Nullable Freeplug getPlug(MACAddress mac) throws FreeboxException {
|
||||
return getPlugs().stream().filter(plug -> plug.id.equals(mac)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public void reboot(MACAddress mac) throws FreeboxException {
|
||||
|
||||
+30
-23
@@ -25,10 +25,13 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.freeboxos.internal.action.FreeplugActions;
|
||||
import org.openhab.binding.freeboxos.internal.api.FreeboxException;
|
||||
import org.openhab.binding.freeboxos.internal.api.rest.FreeplugManager;
|
||||
import org.openhab.binding.freeboxos.internal.api.rest.FreeplugManager.Freeplug;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.unit.Units;
|
||||
import org.openhab.core.thing.Channel;
|
||||
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;
|
||||
@@ -47,17 +50,21 @@ public class FreeplugHandler extends ApiConsumerHandler {
|
||||
|
||||
public FreeplugHandler(Thing thing) {
|
||||
super(thing);
|
||||
statusDrivenByBridge = false;
|
||||
}
|
||||
|
||||
private MACAddress getCheckMac() throws FreeboxException {
|
||||
MACAddress mac = getMac();
|
||||
if (mac == null) {
|
||||
throw new FreeboxException("MAC address is undefined for the thing " + thing.getUID());
|
||||
}
|
||||
return mac;
|
||||
}
|
||||
|
||||
@Override
|
||||
void initializeProperties(Map<String, String> properties) throws FreeboxException {
|
||||
MACAddress mac = getMac();
|
||||
if (mac == null) {
|
||||
throw new FreeboxException(
|
||||
"initializeProperties is not possible because MAC address is undefined for the thing "
|
||||
+ thing.getUID());
|
||||
}
|
||||
getManager(FreeplugManager.class).getPlug(mac).ifPresent(plug -> {
|
||||
MACAddress mac = getCheckMac();
|
||||
if (getManager(FreeplugManager.class).getPlug(mac) instanceof Freeplug plug) {
|
||||
properties.put(Thing.PROPERTY_MODEL_ID, plug.model());
|
||||
properties.put(ROLE, plug.netRole().name());
|
||||
properties.put(NET_ID, plug.netId());
|
||||
@@ -73,17 +80,15 @@ public class FreeplugHandler extends ApiConsumerHandler {
|
||||
updateThing(editThing().withChannels(channels).build());
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
throw new FreeboxException("Freeplug is absent");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void internalPoll() throws FreeboxException {
|
||||
MACAddress mac = getMac();
|
||||
if (mac == null) {
|
||||
throw new FreeboxException(
|
||||
"internalPoll is not possible because MAC address is undefined for the thing " + thing.getUID());
|
||||
}
|
||||
getManager(FreeplugManager.class).getPlug(mac).ifPresent(plug -> {
|
||||
MACAddress mac = getCheckMac();
|
||||
if (getManager(FreeplugManager.class).getPlug(mac) instanceof Freeplug plug) {
|
||||
updateChannelDateTimeState(LAST_SEEN, Instant.now().minusSeconds(plug.inactive()));
|
||||
|
||||
updateChannelString(LINE_STATUS, plug.ethPortStatus());
|
||||
@@ -91,7 +96,14 @@ public class FreeplugHandler extends ApiConsumerHandler {
|
||||
|
||||
updateRateChannel(RATE + "-down", plug.rxRate());
|
||||
updateRateChannel(RATE + "-up", plug.txRate());
|
||||
});
|
||||
if (plug.hasNetwork()) {
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
} else {
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-plug-not-reachable");
|
||||
}
|
||||
} else {
|
||||
throw new FreeboxException("Freeplug is absent");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRateChannel(String channel, int rate) {
|
||||
@@ -100,17 +112,12 @@ public class FreeplugHandler extends ApiConsumerHandler {
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
MACAddress mac = getMac();
|
||||
if (mac == null) {
|
||||
logger.warn("Freeplug restart is not possible because MAC address is undefined for the thing {}",
|
||||
thing.getUID());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
MACAddress mac = getCheckMac();
|
||||
getManager(FreeplugManager.class).reboot(mac);
|
||||
logger.debug("Freeplug {} succesfully restarted", mac);
|
||||
logger.debug("Freeplug {} successfully restarted", mac);
|
||||
} catch (FreeboxException e) {
|
||||
logger.warn("Error restarting freeplug {}: {}", mac, e.getMessage());
|
||||
logger.warn("Error restarting freeplug {}: {}", thing.getUID(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -424,6 +424,7 @@ channel-type.freeboxos.xdsl-status.state.option.DISABLED = Disabled
|
||||
|
||||
info-conf-pending = Please accept pairing request directly on your freebox
|
||||
info-host-not-reachable = Host is not reachable
|
||||
info-plug-not-reachable = Freeplug is not reachable
|
||||
info-player-not-reachable = Player is not reachable
|
||||
info-vm-not-running = VM is not running
|
||||
|
||||
|
||||
Reference in New Issue
Block a user