]> git.basschouten.com Git - openhab-addons.git/commitdiff
[freeboxos] Add FTTH and xDSL line status (#17219)
authorGaël L'hopital <gael@lhopital.org>
Wed, 14 Aug 2024 07:27:31 +0000 (09:27 +0200)
committerGitHub <noreply@github.com>
Wed, 14 Aug 2024 07:27:31 +0000 (09:27 +0200)
* Adding FTTH line status, initiating the addition of xDSL line status

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/FreeboxOsBindingConstants.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java
bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java
bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/i18n/freeboxos.properties
bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/channel-types.xml
bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-channel-groups.xml
bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/thing/server-thing-type.xml
bundles/org.openhab.binding.freeboxos/src/main/resources/OH-INF/update/instructions.xml

index f9042be5c3bff8653bd5e1db97212405160104dc..1493fcb07b72b9704d05dc6c88aea472b793369f 100644 (file)
@@ -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";
index a97f7c5ddfa1e7060b7abe4fdbbe2e610d8be01f..29524c489697b32df438c16040751f58366e8367 100644 (file)
@@ -35,6 +35,12 @@ public class ConnectionManager extends ConfigurableRest<ConnectionManager.Status
     protected static class StatusResponse extends Response<Status> {
     }
 
+    private class FtthStatusResponse extends Response<FtthStatus> {
+    }
+
+    private class XdslStatusResponse extends Response<XdslInfos> {
+    }
+
     private enum State {
         GOING_UP,
         UP,
@@ -50,7 +56,7 @@ public class ConnectionManager extends ConfigurableRest<ConnectionManager.Status
         UNKNOWN
     }
 
-    private enum Media {
+    public enum Media {
         FTTH,
         ETHERNET,
         XDSL,
@@ -70,7 +76,71 @@ public class ConnectionManager extends ConfigurableRest<ConnectionManager.Status
     ) {
     }
 
+    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");
+    }
 }
index 8b092d8fb0e2e04a22ff4aadeb871b3f9ec95111..7259d3408e0da9861c4b52b7e6690ddbaf9d161a 100644 (file)
@@ -28,6 +28,8 @@ import org.openhab.binding.freeboxos.internal.api.FreeboxException;
 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 class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
     void initializeProperties(Map<String, String> 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 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
         properties.put(Source.UPNP.name(), lanConfig.name());
 
         List<Channel> 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 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
                         .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 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
                         .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 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
             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 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
             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) {
index c03e3084de8b114cd9e468d57b5372cc5f085ff8..85e0ed9f830c70320978210f3cbf92d1ddef58e3 100644 (file)
@@ -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
index a600362214742c0693191a9e77932ee76f989d3e..283b64aaa56e24240a7dcb02d0ca5df341d467e8 100644 (file)
                <state pattern="%s"/>
        </channel-type>
 
+       <channel-type id="sfp-present">
+               <item-type>Switch</item-type>
+               <label>SFP Present</label>
+               <category>Switch</category>
+               <state readOnly="true"/>
+       </channel-type>
+
+       <channel-type id="sfp-alim-ok">
+               <item-type>Switch</item-type>
+               <label>Alimentation Ok</label>
+               <category>Switch</category>
+               <state readOnly="true"/>
+       </channel-type>
+
+       <channel-type id="sfp-has-power">
+               <item-type>Switch</item-type>
+               <label>Power Available</label>
+               <category>Switch</category>
+               <state readOnly="true"/>
+       </channel-type>
+
+       <channel-type id="sfp-has-signal">
+               <item-type>Switch</item-type>
+               <label>Signal Present</label>
+               <category>Switch</category>
+               <state readOnly="true"/>
+       </channel-type>
+
+       <channel-type id="link">
+               <item-type>Switch</item-type>
+               <label>Link Is Active</label>
+               <category>Switch</category>
+               <state readOnly="true"/>
+       </channel-type>
+
+       <channel-type id="sfp-signal-level">
+               <item-type unitHint="dBm">Number:Power</item-type>
+               <label>Signal Level</label>
+               <category>QualityOfService</category>
+               <state readOnly="true" pattern="%.2f dBm"/>
+       </channel-type>
+
 </thing:thing-descriptions>
index 50ed9b4a6f726f3998396905aeb334707ff1b78a..718522ab00879403838366845772ec38151205f6 100644 (file)
                </channels>
        </channel-group-type>
 
+       <channel-group-type id="ftth">
+               <label>FTTH Connection Status</label>
+               <channels>
+                       <channel id="sfp-present" typeId="sfp-present"/>
+                       <channel id="sfp-alim-ok" typeId="sfp-alim-ok"/>
+                       <channel id="sfp-has-power" typeId="sfp-has-power"/>
+                       <channel id="sfp-has-signal" typeId="sfp-has-signal"/>
+                       <channel id="link" typeId="link"/>
+                       <channel id="sfp-pwr-tx" typeId="sfp-signal-level">
+                               <label>TX Power</label>
+                               <description>SFP Power in transmission</description>
+                       </channel>
+                       <channel id="sfp-pwr-rx" typeId="sfp-signal-level">
+                               <label>RX Power</label>
+                               <description>SFP Power in reception</description>
+                       </channel>
+               </channels>
+       </channel-group-type>
+
+       <channel-group-type id="xdsl">
+               <label>xDSL Connection Status</label>
+               <channels>
+                       <channel id="status" typeId="status"/>
+                       <!-- to be completed -->
+               </channels>
+       </channel-group-type>
+
+
        <channel-group-type id="connection-status">
                <label>Connection Status Details</label>
                <channels>
index 1e5538cf3e823d9ab460f6306565d8211ebaf5d0..d7577dcbd32d56bb656d89584b033e5e2606a76e 100644 (file)
                        <channel-group typeId="sysinfo" id="sysinfo"/>
                        <channel-group typeId="actions" id="actions"/>
                        <channel-group typeId="connection-status" id="connection-status"/>
+                       <channel-group typeId="ftth" id="ftth"/>
+                       <channel-group typeId="xdsl" id="xdsl"/>
                </channel-groups>
 
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
+
                <representation-property>macAddress</representation-property>
 
                <config-description-ref uri="thing-type:freeboxos:server"/>
                        <channel-group typeId="sysinfo" id="sysinfo"/>
                        <channel-group typeId="actions" id="actions"/>
                        <channel-group typeId="connection-status" id="connection-status"/>
+                       <channel-group typeId="ftth" id="ftth"/>
+                       <channel-group typeId="xdsl" id="xdsl"/>
                </channel-groups>
 
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
+
                <representation-property>macAddress</representation-property>
 
                <config-description-ref uri="thing-type:freeboxos:server"/>
index 770fa5fb0b754914033db71472274ce7b52a92eb..6c55043af4c41094d71de36993413979c0ba7048 100644 (file)
 
        </thing-type>
 
+       <thing-type uid="freeboxos:delta">
+
+               <instruction-set targetVersion="1">
+                       <add-channel id="sfp-present" groupIds="ftth">
+                               <type>freeboxos:sfp-present</type>
+                       </add-channel>
+                       <add-channel id="sfp-alim-ok" groupIds="ftth">
+                               <type>freeboxos:sfp-alim-ok</type>
+                       </add-channel>
+                       <add-channel id="sfp-has-power" groupIds="ftth">
+                               <type>freeboxos:sfp-has-power</type>
+                       </add-channel>
+                       <add-channel id="sfp-has-signal" groupIds="ftth">
+                               <type>freeboxos:sfp-has-signal</type>
+                       </add-channel>
+                       <add-channel id="link" groupIds="ftth">
+                               <type>freeboxos:link</type>
+                       </add-channel>
+                       <add-channel id="sfp-pwr-tx" groupIds="ftth">
+                               <type>freeboxos:sfp-signal-level</type>
+                               <label>TX Power</label>
+                               <description>SFP Power in transmission</description>
+                       </add-channel>
+                       <add-channel id="sfp-pwr-rx" groupIds="ftth">
+                               <type>freeboxos:sfp-signal-level</type>
+                               <label>RX Power</label>
+                               <description>SFP Power in reception</description>
+                       </add-channel>
+               </instruction-set>
+
+       </thing-type>
+
+       <thing-type uid="freeboxos:revolution">
+
+               <instruction-set targetVersion="1">
+                       <add-channel id="sfp-present" groupIds="ftth">
+                               <type>freeboxos:sfp-present</type>
+                       </add-channel>
+                       <add-channel id="sfp-alim-ok" groupIds="ftth">
+                               <type>freeboxos:sfp-alim-ok</type>
+                       </add-channel>
+                       <add-channel id="sfp-has-power" groupIds="ftth">
+                               <type>freeboxos:sfp-has-power</type>
+                       </add-channel>
+                       <add-channel id="sfp-has-signal" groupIds="ftth">
+                               <type>freeboxos:sfp-has-signal</type>
+                       </add-channel>
+                       <add-channel id="link" groupIds="ftth">
+                               <type>freeboxos:link</type>
+                       </add-channel>
+                       <add-channel id="sfp-pwr-tx" groupIds="ftth">
+                               <type>freeboxos:sfp-signal-level</type>
+                               <label>TX Power</label>
+                               <description>SFP Power in transmission</description>
+                       </add-channel>
+                       <add-channel id="sfp-pwr-rx" groupIds="ftth">
+                               <type>freeboxos:sfp-signal-level</type>
+                               <label>RX Power</label>
+                               <description>SFP Power in reception</description>
+                       </add-channel>
+               </instruction-set>
+
+       </thing-type>
 </update:update-descriptions>