]> git.basschouten.com Git - openhab-addons.git/commitdiff
Correcting false assumption (#15307)
authorGaël L'hopital <gael@lhopital.org>
Thu, 27 Jul 2023 06:14:27 +0000 (08:14 +0200)
committerGitHub <noreply@github.com>
Thu, 27 Jul 2023 06:14:27 +0000 (08:14 +0200)
Signed-off-by: clinique <gael@lhopital.org>
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeplugManager.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeplugHandler.java

index 0444f8783035843b80bfd66afbada8d142a729f7..659904882c22b5ffbb4fa4a630eac1f6abd766a1 100644 (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
+ * https://dev.freebox.fr/sdk/os/freeplug/
  *
  * @author Gaël L'hopital - Initial contribution
  */
@@ -43,9 +44,9 @@ public class FreeplugManager extends RestManager {
     }
 
     private enum Status {
-        UP,
-        DOWN,
-        UNKNOWN
+        UP, // The ethernet port is up
+        DOWN, // The ethernet port is down
+        UNKNOWN // The ethernet port state is unknown
     }
 
     public static record Freeplug(MACAddress id, String netId, // Id of the network holding the plug
index 9849ae5f42f759a9aa3e0d72c0c71f65da41600d..d85e4f30f43688c0f85f1a8254e5b9bb83e4cca8 100644 (file)
@@ -17,15 +17,14 @@ import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 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.NetRole;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.Channel;
@@ -35,8 +34,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * The {@link FreeplugHandler} is responsible for handling everything associated to a CPL gateway managed by the freebox
- * server
+ * The {@link FreeplugHandler} is responsible for handling everything associated to a
+ * powerline gateway managed by the freebox server
  *
  * @author Gaël L'hopital - Initial contribution
  */
@@ -51,17 +50,16 @@ public class FreeplugHandler extends ApiConsumerHandler {
     @Override
     void initializeProperties(Map<String, String> properties) throws FreeboxException {
         getManager(FreeplugManager.class).getPlug(getMac()).ifPresent(plug -> {
-            NetRole role = plug.netRole();
             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(ETHERNET_SPEED, String.format("%d Mb/s", plug.ethSpeed()));
             properties.put(LOCAL, Boolean.valueOf(plug.local()).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());
-                channels.removeIf(channel -> channel.getUID().getId().contains("rate"));
+                channels.removeIf(channel -> channel.getUID().getId().contains(RATE));
                 updateThing(editThing().withChannels(channels).build());
             }
         });
@@ -70,8 +68,7 @@ public class FreeplugHandler extends ApiConsumerHandler {
     @Override
     protected void internalPoll() throws FreeboxException {
         getManager(FreeplugManager.class).getPlug(getMac()).ifPresent(plug -> {
-            ZonedDateTime lastSeen = ZonedDateTime.now().minusSeconds(plug.inactive());
-            updateChannelDateTimeState(LAST_SEEN, lastSeen);
+            updateChannelDateTimeState(LAST_SEEN, ZonedDateTime.now().minusSeconds(plug.inactive()));
 
             updateChannelString(LINE_STATUS, plug.ethPortStatus());
             updateChannelOnOff(REACHABLE, plug.hasNetwork());
@@ -82,8 +79,8 @@ public class FreeplugHandler extends ApiConsumerHandler {
     }
 
     private void updateRateChannel(String channel, int rate) {
-        QuantityType<?> qtty = rate != -1 ? new QuantityType<>(rate, Units.MEGABIT_PER_SECOND) : null;
-        updateChannelQuantity(channel, qtty);
+        // According to https://dev.freebox.fr/bugs/task/35895
+        updateChannelQuantity(channel, new QuantityType<>(rate > 0 ? rate : 9, Units.MEGABIT_PER_SECOND));
     }
 
     public void reset() {
@@ -97,6 +94,6 @@ public class FreeplugHandler extends ApiConsumerHandler {
 
     @Override
     public Collection<Class<? extends ThingHandlerService>> getServices() {
-        return Collections.singleton(FreeplugActions.class);
+        return Set.of(FreeplugActions.class);
     }
 }