]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tr064] fix incorrectly reported decibel values for DSL Noise Margin and Attenuation...
authorStefan Giehl <stefangiehl@gmail.com>
Sat, 16 Oct 2021 09:33:31 +0000 (11:33 +0200)
committerGitHub <noreply@github.com>
Sat, 16 Oct 2021 09:33:31 +0000 (11:33 +0200)
* [tr064] fix incorrectly reported decibel values for DSL Noise Margin and Attenuation

Signed-off-by: Stefan Giehl <stefangiehl@gmail.com>
* apply review feedback

Signed-off-by: Stefan Giehl <stefangiehl@gmail.com>
bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java
bundles/org.openhab.binding.tr064/src/main/resources/channels.xml

index e175b22273d0583a9f2565dcf2644b932ed069be..788bf20d785a6cd446ea44de5c00a65e63f962c6 100644 (file)
@@ -38,6 +38,7 @@ import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.types.StringType;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.types.Command;
 import org.openhab.core.types.State;
 import org.openhab.core.types.UnDefType;
@@ -200,6 +201,20 @@ public class SOAPValueConverter {
         return mappedSignalStrength;
     }
 
+    /**
+     * post processor for decibel values (which are served as deca decibel)
+     *
+     * @param state the channel value in deca decibel
+     * @param channelConfig channel config of the channel
+     * @return the state converted to decibel
+     */
+    @SuppressWarnings("unused")
+    private State processDecaDecibel(State state, Tr064ChannelConfig channelConfig) {
+        Float value = state.as(DecimalType.class).floatValue() / 10;
+
+        return new QuantityType(value, Units.DECIBEL);
+    }
+
     /**
      * post processor for answering machine new messages channel
      *
index afccf5454851cb6782f0059bbc03a67199933c8c..489391c7543d6b2ca8842de6002bdddf239374c1 100644 (file)
                <item type="Number:Dimensionless" unit="dB" statePattern="%.1f dB"/>
                <service deviceType="urn:dslforum-org:device:WANDevice:1"
                        serviceId="urn:WANDSLIfConfig-com:serviceId:WANDSLInterfaceConfig1"/>
-               <getAction name="GetInfo" argument="NewDownstreamNoiseMargin"/>
+               <getAction name="GetInfo" argument="NewDownstreamNoiseMargin" postProcessor="processDecaDecibel"/>
        </channel>
        <channel name="dslUpstreamNoiseMargin" label="DSL Upstream Noise Margin">
                <item type="Number:Dimensionless" unit="dB" statePattern="%.1f dB"/>
                <service deviceType="urn:dslforum-org:device:WANDevice:1"
                        serviceId="urn:WANDSLIfConfig-com:serviceId:WANDSLInterfaceConfig1"/>
-               <getAction name="GetInfo" argument="NewUpstreamNoiseMargin"/>
+               <getAction name="GetInfo" argument="NewUpstreamNoiseMargin" postProcessor="processDecaDecibel"/>
        </channel>
        <channel name="dslDownstreamAttenuation" label="DSL Downstream Attenuation">
                <item type="Number:Dimensionless" unit="dB" statePattern="%.1f dB"/>
                <service deviceType="urn:dslforum-org:device:WANDevice:1"
                        serviceId="urn:WANDSLIfConfig-com:serviceId:WANDSLInterfaceConfig1"/>
-               <getAction name="GetInfo" argument="NewDownstreamAttenuation"/>
+               <getAction name="GetInfo" argument="NewDownstreamAttenuation" postProcessor="processDecaDecibel"/>
        </channel>
        <channel name="dslUpstreamAttenuation" label="DSL Upstream Attenuation">
                <item type="Number:Dimensionless" unit="dB" statePattern="%.1f dB"/>
                <service deviceType="urn:dslforum-org:device:WANDevice:1"
                        serviceId="urn:WANDSLIfConfig-com:serviceId:WANDSLInterfaceConfig1"/>
-               <getAction name="GetInfo" argument="NewUpstreamAttenuation"/>
+               <getAction name="GetInfo" argument="NewUpstreamAttenuation" postProcessor="processDecaDecibel"/>
        </channel>
        <channel name="dslFECErrors" label="DSL FEC Errors">
                <item type="Number:Dimensionless"/>