Correcting false assumption (#15307)

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2023-07-27 08:14:27 +02:00 committed by GitHub
parent ca8c843d05
commit 4eaba31f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View File

@ -25,6 +25,7 @@ import inet.ipaddr.mac.MACAddress;
/** /**
* The {@link FreeplugManager} is the Java class used to handle api requests related to freeplugs * The {@link FreeplugManager} is the Java class used to handle api requests related to freeplugs
* https://dev.freebox.fr/sdk/os/freeplug/
* *
* @author Gaël L'hopital - Initial contribution * @author Gaël L'hopital - Initial contribution
*/ */
@ -43,9 +44,9 @@ public class FreeplugManager extends RestManager {
} }
private enum Status { private enum Status {
UP, UP, // The ethernet port is up
DOWN, DOWN, // The ethernet port is down
UNKNOWN UNKNOWN // The ethernet port state is unknown
} }
public static record Freeplug(MACAddress id, String netId, // Id of the network holding the plug public static record Freeplug(MACAddress id, String netId, // Id of the network holding the plug

View File

@ -17,15 +17,14 @@ import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.freeboxos.internal.action.FreeplugActions; import org.openhab.binding.freeboxos.internal.action.FreeplugActions;
import org.openhab.binding.freeboxos.internal.api.FreeboxException; 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;
import org.openhab.binding.freeboxos.internal.api.rest.FreeplugManager.NetRole;
import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units; import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel; import org.openhab.core.thing.Channel;
@ -35,8 +34,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The {@link FreeplugHandler} is responsible for handling everything associated to a CPL gateway managed by the freebox * The {@link FreeplugHandler} is responsible for handling everything associated to a
* server * powerline gateway managed by the freebox server
* *
* @author Gaël L'hopital - Initial contribution * @author Gaël L'hopital - Initial contribution
*/ */
@ -51,17 +50,16 @@ public class FreeplugHandler extends ApiConsumerHandler {
@Override @Override
void initializeProperties(Map<String, String> properties) throws FreeboxException { void initializeProperties(Map<String, String> properties) throws FreeboxException {
getManager(FreeplugManager.class).getPlug(getMac()).ifPresent(plug -> { getManager(FreeplugManager.class).getPlug(getMac()).ifPresent(plug -> {
NetRole role = plug.netRole();
properties.put(Thing.PROPERTY_MODEL_ID, plug.model()); properties.put(Thing.PROPERTY_MODEL_ID, plug.model());
properties.put(ROLE, role.name()); properties.put(ROLE, plug.netRole().name());
properties.put(NET_ID, plug.netId()); properties.put(NET_ID, plug.netId());
properties.put(ETHERNET_SPEED, String.format("%d Mb/s", plug.ethSpeed())); properties.put(ETHERNET_SPEED, String.format("%d Mb/s", plug.ethSpeed()));
properties.put(LOCAL, Boolean.valueOf(plug.local()).toString()); properties.put(LOCAL, Boolean.valueOf(plug.local()).toString());
properties.put(FULL_DUPLEX, Boolean.valueOf(plug.ethFullDuplex()).toString()); properties.put(FULL_DUPLEX, Boolean.valueOf(plug.ethFullDuplex()).toString());
if (role.equals(NetRole.CCO)) { // Coordinator does not provide rate up or down if (plug.local()) { // Plug connected to the freebox does not provide rate up or down
List<Channel> channels = new ArrayList<>(getThing().getChannels()); List<Channel> channels = new ArrayList<>(getThing().getChannels());
channels.removeIf(channel -> channel.getUID().getId().contains("rate")); channels.removeIf(channel -> channel.getUID().getId().contains(RATE));
updateThing(editThing().withChannels(channels).build()); updateThing(editThing().withChannels(channels).build());
} }
}); });
@ -70,8 +68,7 @@ public class FreeplugHandler extends ApiConsumerHandler {
@Override @Override
protected void internalPoll() throws FreeboxException { protected void internalPoll() throws FreeboxException {
getManager(FreeplugManager.class).getPlug(getMac()).ifPresent(plug -> { getManager(FreeplugManager.class).getPlug(getMac()).ifPresent(plug -> {
ZonedDateTime lastSeen = ZonedDateTime.now().minusSeconds(plug.inactive()); updateChannelDateTimeState(LAST_SEEN, ZonedDateTime.now().minusSeconds(plug.inactive()));
updateChannelDateTimeState(LAST_SEEN, lastSeen);
updateChannelString(LINE_STATUS, plug.ethPortStatus()); updateChannelString(LINE_STATUS, plug.ethPortStatus());
updateChannelOnOff(REACHABLE, plug.hasNetwork()); updateChannelOnOff(REACHABLE, plug.hasNetwork());
@ -82,8 +79,8 @@ public class FreeplugHandler extends ApiConsumerHandler {
} }
private void updateRateChannel(String channel, int rate) { private void updateRateChannel(String channel, int rate) {
QuantityType<?> qtty = rate != -1 ? new QuantityType<>(rate, Units.MEGABIT_PER_SECOND) : null; // According to https://dev.freebox.fr/bugs/task/35895
updateChannelQuantity(channel, qtty); updateChannelQuantity(channel, new QuantityType<>(rate > 0 ? rate : 9, Units.MEGABIT_PER_SECOND));
} }
public void reset() { public void reset() {
@ -97,6 +94,6 @@ public class FreeplugHandler extends ApiConsumerHandler {
@Override @Override
public Collection<Class<? extends ThingHandlerService>> getServices() { public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(FreeplugActions.class); return Set.of(FreeplugActions.class);
} }
} }