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;
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
*/
@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());
}
});
@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());
}
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() {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
- return Collections.singleton(FreeplugActions.class);
+ return Set.of(FreeplugActions.class);
}
}