]> git.basschouten.com Git - openhab-addons.git/commitdiff
[freeboxos] Add unitHint on few channel types (#17259)
authorlolodomo <lg.hc@free.fr>
Tue, 20 Aug 2024 13:29:37 +0000 (15:29 +0200)
committerGitHub <noreply@github.com>
Tue, 20 Aug 2024 13:29:37 +0000 (15:29 +0200)
* [freeboxos] Add unitHint on few channel types

Also remove an unused channel type "bandwidth".
Also avoid unneeded unit conversion when updating channel state.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
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

index 5ba705ca7b9cae5410aa5d2e2b149c4f3327558f..36927250c99d99a3ed3d9f9d144cc5aeb769e916 100644 (file)
@@ -192,10 +192,8 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
             updateRateBandwidth(status.rateUp(), status.bandwidthUp(), "up");
             updateRateBandwidth(status.rateDown(), status.bandwidthDown(), "down");
 
-            updateChannelQuantity(GROUP_CONNECTION_STATUS, BYTES_UP, new QuantityType<>(status.bytesUp(), OCTET),
-                    GIBIOCTET);
-            updateChannelQuantity(GROUP_CONNECTION_STATUS, BYTES_DOWN, new QuantityType<>(status.bytesDown(), OCTET),
-                    GIBIOCTET);
+            updateChannelQuantity(GROUP_CONNECTION_STATUS, BYTES_UP, status.bytesUp(), OCTET);
+            updateChannelQuantity(GROUP_CONNECTION_STATUS, BYTES_DOWN, status.bytesDown(), OCTET);
         }
         if (anyChannelLinked(GROUP_FTTH,
                 Set.of(SFP_PRESENT, SFP_ALIM, SFP_POWER, SFP_SIGNAL, SFP_LINK, SFP_PWR_TX, SFP_PWR_RX))) {
@@ -218,14 +216,12 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
     }
 
     private void updateRateBandwidth(long rate, long bandwidth, String orientation) {
-        QuantityType<?> rateUp = new QuantityType<>(rate * 8, Units.BIT_PER_SECOND);
+        QuantityType<?> rateUp = new QuantityType<>(rate * 8, BIT_PER_SECOND);
         QuantityType<?> bandwidthUp = new QuantityType<>(bandwidth, BIT_PER_SECOND);
-        updateChannelQuantity(GROUP_CONNECTION_STATUS, RATE + "-" + orientation, rateUp, KILOBIT_PER_SECOND);
-        updateChannelQuantity(GROUP_CONNECTION_STATUS, BW + "-" + orientation, bandwidthUp, KILOBIT_PER_SECOND);
+        updateChannelQuantity(GROUP_CONNECTION_STATUS, RATE + "-" + orientation, rateUp);
+        updateChannelQuantity(GROUP_CONNECTION_STATUS, BW + "-" + orientation, bandwidthUp);
         updateChannelQuantity(GROUP_CONNECTION_STATUS, PCT_BW + "-" + orientation,
-                !bandwidthUp.equals(QuantityType.ZERO) ? rateUp.multiply(HUNDRED).divide(bandwidthUp)
-                        : QuantityType.ZERO,
-                Units.PERCENT);
+                !bandwidthUp.equals(QuantityType.ZERO) ? rateUp.divide(bandwidthUp) : QuantityType.ZERO, PERCENT);
     }
 
     @Override
index f8889950ce72743fc34ff961880c3edf708d9d98..663b4b942b0a26c0e8910d8d2040011c87fe08d6 100644 (file)
@@ -214,8 +214,6 @@ channel-type.freeboxos.alarm-volume.label = Alarm Volume
 channel-type.freeboxos.alternate-ring.label = Alternating Ring
 channel-type.freeboxos.bandwidth-usage.label = Bandwidth Usage
 channel-type.freeboxos.bandwidth-usage.description = Current bandwidth usage
-channel-type.freeboxos.bandwidth.label = Bandwidth
-channel-type.freeboxos.bandwidth.description = Available bandwidth
 channel-type.freeboxos.basic-shutter.label = Shutter
 channel-type.freeboxos.basic-shutter.description = Shutter command
 channel-type.freeboxos.box-event.label = Server Event
index 65c6dd67949d7d96a58991c59c55d4386465ad1f..4dee0b5198b70e5be5245959cf753057c1b9d9cd 100644 (file)
@@ -5,11 +5,11 @@
        xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
 
        <channel-type id="lcd-brightness" advanced="true">
-               <item-type>Number:Dimensionless</item-type>
+               <item-type unitHint="%">Number:Dimensionless</item-type>
                <label>Screen Brightness</label>
                <description>Brightness level of the screen in percent</description>
                <category>Light</category>
-               <state pattern="%d %unit%" min="0" max="100"/>
+               <state pattern="%d %%" min="0" max="100"/>
        </channel-type>
 
        <channel-type id="lcd-orientation" advanced="true">
        </channel-type>
 
        <channel-type id="bandwidth-usage">
-               <item-type>Number:Dimensionless</item-type>
+               <item-type unitHint="%">Number:Dimensionless</item-type>
                <label>Bandwidth Usage</label>
                <description>Current bandwidth usage</description>
-               <state readOnly="true" pattern="%.2f %unit%"/>
+               <state readOnly="true" pattern="%.0f %%"/>
        </channel-type>
 
        <channel-type id="transfer-rate">
-               <item-type>Number:DataTransferRate</item-type>
+               <item-type unitHint="Mbit/s">Number:DataTransferRate</item-type>
                <label>Transfer Rate</label>
                <description>Current transfer rate</description>
                <state readOnly="true" pattern="%.2f %unit%"/>
        </channel-type>
 
        <channel-type id="transfer-rate-bps" advanced="true">
-               <item-type>Number:DataTransferRate</item-type>
+               <item-type unitHint="bit/s">Number:DataTransferRate</item-type>
                <label>Transfer Rate</label>
                <description>Current transfer rate</description>
-               <state readOnly="true" pattern="%.2f bit/s"/>
+               <state readOnly="true" pattern="%.0f bit/s"/>
        </channel-type>
 
        <channel-type id="transfer-bytes" advanced="true">
-               <item-type>Number:DataAmount</item-type>
+               <item-type unitHint="GB">Number:DataAmount</item-type>
                <label>Transfered Bytes</label>
                <description>Total data transfered since last connection</description>
                <state readOnly="true" pattern="%.2f %unit%"/>
        </channel-type>
 
-       <channel-type id="bandwidth" advanced="true">
-               <item-type>Number:DataTransferRate</item-type>
-               <label>Bandwidth</label>
-               <description>Available bandwidth</description>
-               <state readOnly="true" pattern="%.2f %unit%"/>
-       </channel-type>
-
        <channel-type id="uptime" advanced="true">
                <item-type>Number:Time</item-type>
                <label>Uptime</label>
                <item-type unitHint="%">Number:Dimensionless</item-type>
                <label>Alarm Volume</label>
                <category>oh:freeboxos:sirene</category>
-               <state min="0" max="100" step="1" pattern="%d %unit%"/>
+               <state min="0" max="100" step="1" pattern="%d %%"/>
        </channel-type>
 
        <channel-type id="alarm-pin">