From 8f595b6f81c9d4a98fde4a2e3501e73bda859708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Wed, 14 Aug 2024 09:27:31 +0200 Subject: [PATCH] [freeboxos] Add FTTH and xDSL line status (#17219) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adding FTTH line status, initiating the addition of xDSL line status Signed-off-by: Gaƫl L'hopital --- .../internal/FreeboxOsBindingConstants.java | 13 +++- .../internal/api/rest/ConnectionManager.java | 72 ++++++++++++++++++- .../internal/handler/ServerHandler.java | 31 ++++++-- .../OH-INF/i18n/freeboxos.properties | 13 ++++ .../resources/OH-INF/thing/channel-types.xml | 42 +++++++++++ .../OH-INF/thing/server-channel-groups.xml | 28 ++++++++ .../OH-INF/thing/server-thing-type.xml | 12 ++++ .../resources/OH-INF/update/instructions.xml | 63 ++++++++++++++++ 8 files changed, 267 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/FreeboxOsBindingConstants.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/FreeboxOsBindingConstants.java index f9042be5c3bff..1493fcb07b72b 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/FreeboxOsBindingConstants.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/FreeboxOsBindingConstants.java @@ -86,7 +86,7 @@ public class FreeboxOsBindingConstants { public static final String LOCAL = "local"; public static final String FULL_DUPLEX = "fullDuplex"; - // List of all Group Channel ids + // List of all Channel Groups ids public static final String GROUP_SENSORS = "sensors"; public static final String GROUP_FANS = "fans"; public static final String GROUP_CONNECTION_STATUS = "connection-status"; @@ -99,6 +99,8 @@ public class FreeboxOsBindingConstants { public static final String GROUP_VM_STATUS = "vmstatus"; public static final String GROUP_WIFI = "wifi"; public static final String GROUP_REPEATER_MISC = "repeater-misc"; + public static final String GROUP_XDSL = "xdsl"; + public static final String GROUP_FTTH = "ftth"; // List of all Channel ids public static final String RSSI = "rssi"; @@ -157,6 +159,15 @@ public class FreeboxOsBindingConstants { public static final String LED = "led"; public static final String HOST_COUNT = "host-count"; + // FTTH channels ids + public static final String SFP_PRESENT = "sfp-present"; + public static final String SFP_ALIM = "sfp-alim-ok"; + public static final String SFP_POWER = "sfp-has-power"; + public static final String SFP_SIGNAL = "sfp-has-signal"; + public static final String SFP_LINK = "link"; + public static final String SFP_PWR_TX = "sfp-pwr-tx"; + public static final String SFP_PWR_RX = "sfp-pwr-rx"; + // Home channels public static final String KEYFOB_ENABLE = "enable"; public static final String NODE_BATTERY = "battery"; diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java index a97f7c5ddfa1e..29524c489697b 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java @@ -35,6 +35,12 @@ public class ConnectionManager extends ConfigurableRest { } + private class FtthStatusResponse extends Response { + } + + private class XdslStatusResponse extends Response { + } + private enum State { GOING_UP, UP, @@ -50,7 +56,7 @@ private enum Type { UNKNOWN } - private enum Media { + public enum Media { FTTH, ETHERNET, XDSL, @@ -70,7 +76,71 @@ public static record Status(State state, Type type, Media media, @Nullable List< ) { } + public static record FtthStatus(boolean sfpPresent, boolean sfpAlimOk, boolean sfpHasPowerReport, + boolean sfpHasSignal, boolean link, String sfpSerial, String sfpModel, String sfpVendor, // + int sfpPwrTx, // scaled by 100 (in dBm) + int sfpPwrRx // scaled by 100 (in dBm) + ) { + public double getReceivedDBM() { + return 1d * sfpPwrRx / 100; + } + + public double getTransmitDBM() { + return 1d * sfpPwrTx / 100; + } + } + + public static record XdslStats( // + int maxrate, // ATM max rate in kbit/s + int rate, // ATM rate in kbit/s + int snr, // in dB + int attn, // in dB + int snr10, // in dB/10 + int attn10, // in dB/10 + int fec, int crc, int hec, int es, int ses, boolean phyr, boolean ginp, boolean nitro, // + int rxmt, // only available when phyr is on + int rxmtCorr, // only available when phyr is on + int rxmtUncorr, // only available when phyr is on + int rtxTx, // only available when ginp is on + int rtxC, // only available when ginp is on + int rtxUc// only available when ginp is on + ) { + } + + private enum SynchroState { + DOWN, // unsynchronized + TRAINING, // synchronizing step 1/4 + STARTED, // synchronizing step 2/4 + CHAN_ANALYSIS, // synchronizing step 3/4 + MSG_EXCHANGE, // synchronizing step 4/4 + SHOWTIME, // Ready + DISABLED, // Disabled + UNKNOWN + } + + private enum Modulation { + ADSL, + VDSL, + UNKNOWN + } + + public static record XdslStatus(SynchroState status, String protocol, Modulation modulation, long uptime) { + + } + + public static record XdslInfos(XdslStatus status, XdslStats down, XdslStats up) { + + } + public ConnectionManager(FreeboxOsSession session) throws FreeboxException { super(session, LoginManager.Permission.NONE, StatusResponse.class, session.getUriBuilder().path(PATH), null); } + + public FtthStatus getFtthStatus() throws FreeboxException { + return super.getSingle(FtthStatusResponse.class, "ftth"); + } + + public XdslInfos getXdslStatus() throws FreeboxException { + return super.getSingle(XdslStatusResponse.class, "xdsl"); + } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java index 8b092d8fb0e2e..7259d3408e0da 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java @@ -28,6 +28,8 @@ import org.openhab.binding.freeboxos.internal.api.rest.AfpManager; import org.openhab.binding.freeboxos.internal.api.rest.AirMediaManager; import org.openhab.binding.freeboxos.internal.api.rest.ConnectionManager; +import org.openhab.binding.freeboxos.internal.api.rest.ConnectionManager.FtthStatus; +import org.openhab.binding.freeboxos.internal.api.rest.ConnectionManager.Media; import org.openhab.binding.freeboxos.internal.api.rest.ConnectionManager.Status; import org.openhab.binding.freeboxos.internal.api.rest.FtpManager; import org.openhab.binding.freeboxos.internal.api.rest.LanBrowserManager.Source; @@ -75,6 +77,7 @@ public ServerHandler(Thing thing) { void initializeProperties(Map properties) throws FreeboxException { LanConfig lanConfig = getManager(LanManager.class).getConfig(); Config config = getManager(SystemManager.class).getConfig(); + properties.put(Thing.PROPERTY_SERIAL_NUMBER, config.serial()); properties.put(Thing.PROPERTY_FIRMWARE_VERSION, config.firmwareVersion()); properties.put(Thing.PROPERTY_HARDWARE_VERSION, config.modelInfo().prettyName()); @@ -82,7 +85,13 @@ void initializeProperties(Map properties) throws FreeboxExceptio properties.put(Source.UPNP.name(), lanConfig.name()); List channels = new ArrayList<>(getThing().getChannels()); - int nbInit = channels.size(); + + // Remove channels of the not active media type + Status connectionConfig = getManager(ConnectionManager.class).getConfig(); + channels.removeIf(c -> (GROUP_FTTH.equals(c.getUID().getGroupId()) && connectionConfig.media() != Media.FTTH) + || (GROUP_XDSL.equals(c.getUID().getGroupId()) && connectionConfig.media() != Media.XDSL)); + + // Add temperature sensors config.sensors().forEach(sensor -> { ChannelUID sensorId = new ChannelUID(thing.getUID(), GROUP_SENSORS, sensor.id()); if (getThing().getChannel(sensorId) == null) { @@ -96,6 +105,8 @@ void initializeProperties(Map properties) throws FreeboxExceptio .withType(new ChannelTypeUID(BINDING_ID, "temperature")).build()); } }); + + // Add fans sensors config.fans().forEach(sensor -> { ChannelUID sensorId = new ChannelUID(thing.getUID(), GROUP_FANS, sensor.id()); if (getThing().getChannel(sensorId) == null) { @@ -104,9 +115,9 @@ void initializeProperties(Map properties) throws FreeboxExceptio .build()); } }); - if (nbInit != channels.size()) { - updateThing(editThing().withChannels(channels).build()); - } + + // And finally update the thing with appropriate channels + updateThing(editThing().withChannels(channels).build()); } @Override @@ -163,7 +174,6 @@ private void fetchConnectionStatus() throws FreeboxException { updateChannelString(GROUP_CONNECTION_STATUS, LINE_MEDIA, status.media()); updateChannelString(GROUP_CONNECTION_STATUS, IP_ADDRESS, status.ipv4()); updateChannelString(GROUP_CONNECTION_STATUS, IPV6_ADDRESS, status.ipv6()); - updateRateBandwidth(status.rateUp(), status.bandwidthUp(), "up"); updateRateBandwidth(status.rateDown(), status.bandwidthDown(), "down"); @@ -172,6 +182,17 @@ private void fetchConnectionStatus() throws FreeboxException { updateChannelQuantity(GROUP_CONNECTION_STATUS, BYTES_DOWN, new QuantityType<>(status.bytesDown(), OCTET), GIBIOCTET); } + if (anyChannelLinked(GROUP_FTTH, + Set.of(SFP_PRESENT, SFP_ALIM, SFP_POWER, SFP_SIGNAL, SFP_LINK, SFP_PWR_TX, SFP_PWR_RX))) { + FtthStatus ftthStatus = getManager(ConnectionManager.class).getFtthStatus(); + updateChannelOnOff(GROUP_FTTH, SFP_PRESENT, ftthStatus.sfpPresent()); + updateChannelOnOff(GROUP_FTTH, SFP_ALIM, ftthStatus.sfpAlimOk()); + updateChannelOnOff(GROUP_FTTH, SFP_POWER, ftthStatus.sfpHasPowerReport()); + updateChannelOnOff(GROUP_FTTH, SFP_SIGNAL, ftthStatus.sfpHasSignal()); + updateChannelOnOff(GROUP_FTTH, SFP_LINK, ftthStatus.link()); + updateChannelQuantity(GROUP_FTTH, SFP_PWR_TX, ftthStatus.getTransmitDBM(), Units.DECIBEL_MILLIWATTS); + updateChannelQuantity(GROUP_FTTH, SFP_PWR_RX, ftthStatus.getReceivedDBM(), Units.DECIBEL_MILLIWATTS); + } } private void updateRateBandwidth(long rate, long bandwidth, String orientation) { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/i18n/freeboxos.properties b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/i18n/freeboxos.properties index c03e3084de8b1..85e0ed9f830c7 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/i18n/freeboxos.properties +++ b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/i18n/freeboxos.properties @@ -155,6 +155,11 @@ channel-group-type.freeboxos.connectivity.channel.last-seen.label = Last Activit channel-group-type.freeboxos.display.label = Front Display Panel channel-group-type.freeboxos.fans.label = Fans channel-group-type.freeboxos.file-sharing.label = File Sharing +channel-group-type.freeboxos.ftth.label = FTTH Connection Status +channel-group-type.freeboxos.ftth.channel.sfp-pwr-rx.label = RX Power +channel-group-type.freeboxos.ftth.channel.sfp-pwr-rx.description = SFP Power in reception +channel-group-type.freeboxos.ftth.channel.sfp-pwr-tx.label = TX Power +channel-group-type.freeboxos.ftth.channel.sfp-pwr-tx.description = SFP Power in transmission channel-group-type.freeboxos.incoming.label = Incoming Call channel-group-type.freeboxos.incoming.description = Currently presented phone call channel-group-type.freeboxos.incoming.channel.name.label = Incoming Caller @@ -194,6 +199,7 @@ channel-group-type.freeboxos.wifi.channel.rate-down.label = Rx Rate channel-group-type.freeboxos.wifi.channel.rate-down.description = Current RX rate channel-group-type.freeboxos.wifi.channel.rate-up.label = Tx Rate channel-group-type.freeboxos.wifi.channel.rate-up.description = Current TX Rate +channel-group-type.freeboxos.xdsl.label = xDSL Connection Status # channel types @@ -306,6 +312,7 @@ channel-type.freeboxos.line-type.description = Type of network line connection channel-type.freeboxos.line-type.state.option.ETHERNET = FTTH/ethernet channel-type.freeboxos.line-type.state.option.RFC2684 = xDSL (unbundled) channel-type.freeboxos.line-type.state.option.PPPOATM = xDSL +channel-type.freeboxos.link.label = Link Is Active channel-type.freeboxos.name.label = Name channel-type.freeboxos.name.description = Called name for outgoing calls. Caller name for incoming calls channel-type.freeboxos.number.label = Incoming Call @@ -329,6 +336,11 @@ channel-type.freeboxos.samba-file-status.label = Windows File Sharing channel-type.freeboxos.samba-file-status.description = Status of Windows File Sharing (Samba) channel-type.freeboxos.samba-printer-status.label = Windows Printer Sharing channel-type.freeboxos.samba-printer-status.description = Status of Windows Printer Sharing +channel-type.freeboxos.sfp-alim-ok.label = Alimentation Ok +channel-type.freeboxos.sfp-has-power.label = Power Available +channel-type.freeboxos.sfp-has-signal.label = Signal Present +channel-type.freeboxos.sfp-present.label = SFP Present +channel-type.freeboxos.sfp-signal-level.label = Signal Level channel-type.freeboxos.shutter.label = Shutter Position channel-type.freeboxos.shutter.description = Read / Write position of the shutter channel-type.freeboxos.ssid.label = SSID @@ -348,6 +360,7 @@ channel-type.freeboxos.upnpav-status.label = UPnP AV Enabled channel-type.freeboxos.upnpav-status.description = Indicates whether UPnP AV is enabled channel-type.freeboxos.uptime.label = Uptime channel-type.freeboxos.uptime.description = Time since last reboot of the equipment +channel-type.freeboxos.uptime.state.pattern = %1$tdd %1$tHh %1$tMm %1$tSs channel-type.freeboxos.wifi-host.label = Access Point channel-type.freeboxos.wifi-status.label = Wifi Enabled channel-type.freeboxos.wifi-status.description = Indicates whether the wifi network is enabled diff --git a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/channel-types.xml b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/channel-types.xml index a600362214742..283b64aaa56e2 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/channel-types.xml +++ b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/channel-types.xml @@ -461,4 +461,46 @@ + + Switch + + Switch + + + + + Switch + + Switch + + + + + Switch + + Switch + + + + + Switch + + Switch + + + + + Switch + + Switch + + + + + Number:Power + + QualityOfService + + + diff --git a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-channel-groups.xml b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-channel-groups.xml index 50ed9b4a6f726..718522ab00879 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-channel-groups.xml +++ b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-channel-groups.xml @@ -52,6 +52,34 @@ + + + + + + + + + + + SFP Power in transmission + + + + SFP Power in reception + + + + + + + + + + + + + diff --git a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-thing-type.xml b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-thing-type.xml index 1e5538cf3e823..d7577dcbd32d5 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-thing-type.xml +++ b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-thing-type.xml @@ -20,8 +20,14 @@ + + + + 1 + + macAddress @@ -42,8 +48,14 @@ + + + + 1 + + macAddress diff --git a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/update/instructions.xml b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/update/instructions.xml index 770fa5fb0b754..6c55043af4c41 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/update/instructions.xml +++ b/bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/update/instructions.xml @@ -26,4 +26,67 @@ + + + + + freeboxos:sfp-present + + + freeboxos:sfp-alim-ok + + + freeboxos:sfp-has-power + + + freeboxos:sfp-has-signal + + + freeboxos:link + + + freeboxos:sfp-signal-level + + SFP Power in transmission + + + freeboxos:sfp-signal-level + + SFP Power in reception + + + + + + + + + + freeboxos:sfp-present + + + freeboxos:sfp-alim-ok + + + freeboxos:sfp-has-power + + + freeboxos:sfp-has-signal + + + freeboxos:link + + + freeboxos:sfp-signal-level + + SFP Power in transmission + + + freeboxos:sfp-signal-level + + SFP Power in reception + + + +