2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.freeboxos.internal.api.rest;
15 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
20 import org.openhab.binding.freeboxos.internal.api.Response;
22 import inet.ipaddr.IPAddress;
25 * The {@link ConnectionManager} is the Java class used to handle api requests related to connection
27 * https://dev.freebox.fr/sdk/os/system/#
29 * @author Gaƫl L'hopital - Initial contribution
32 public class ConnectionManager extends ConfigurableRest<ConnectionManager.Status, ConnectionManager.StatusResponse> {
33 private static final String PATH = "connection";
35 protected static class StatusResponse extends Response<Status> {
38 private class FtthStatusResponse extends Response<FtthStatus> {
41 private class XdslStatusResponse extends Response<XdslInfos> {
67 public static record Status(State state, Type type, Media media, @Nullable List<Integer> ipv4PortRange,
68 @Nullable IPAddress ipv4, // This can be null if state is not up
69 @Nullable IPAddress ipv6, // This can be null if state is not up
70 long rateUp, // current upload rate in byte/s
71 long rateDown, // current download rate in byte/s
72 long bandwidthUp, // available upload bandwidth in bit/s
73 long bandwidthDown, // available download bandwidth in bit/s
74 long bytesUp, // total uploaded bytes since last connection
75 long bytesDown // total downloaded bytes since last connection
79 public static record FtthStatus(boolean sfpPresent, boolean sfpAlimOk, boolean sfpHasPowerReport,
80 boolean sfpHasSignal, boolean link, String sfpSerial, String sfpModel, String sfpVendor, //
81 int sfpPwrTx, // scaled by 100 (in dBm)
82 int sfpPwrRx // scaled by 100 (in dBm)
84 public double getReceivedDBM() {
85 return 1d * sfpPwrRx / 100;
88 public double getTransmitDBM() {
89 return 1d * sfpPwrTx / 100;
93 public static record XdslStats( //
94 int maxrate, // ATM max rate in kbit/s
95 int rate, // ATM rate in kbit/s
98 int snr10, // in dB/10
99 int attn10, // in dB/10
100 int fec, int crc, int hec, int es, int ses, boolean phyr, boolean ginp, boolean nitro, //
101 int rxmt, // only available when phyr is on
102 int rxmtCorr, // only available when phyr is on
103 int rxmtUncorr, // only available when phyr is on
104 int rtxTx, // only available when ginp is on
105 int rtxC, // only available when ginp is on
106 int rtxUc// only available when ginp is on
110 private enum SynchroState {
111 DOWN, // unsynchronized
112 TRAINING, // synchronizing step 1/4
113 STARTED, // synchronizing step 2/4
114 CHAN_ANALYSIS, // synchronizing step 3/4
115 MSG_EXCHANGE, // synchronizing step 4/4
117 DISABLED, // Disabled
121 private enum Modulation {
127 public static record XdslStatus(SynchroState status, String protocol, Modulation modulation, long uptime) {
131 public static record XdslInfos(XdslStatus status, XdslStats down, XdslStats up) {
135 public ConnectionManager(FreeboxOsSession session) throws FreeboxException {
136 super(session, LoginManager.Permission.NONE, StatusResponse.class, session.getUriBuilder().path(PATH), null);
139 public FtthStatus getFtthStatus() throws FreeboxException {
140 return super.getSingle(FtthStatusResponse.class, "ftth");
143 public XdslInfos getXdslStatus() throws FreeboxException {
144 return super.getSingle(XdslStatusResponse.class, "xdsl");