]> git.basschouten.com Git - openhab-addons.git/commitdiff
[dsmr] Fix incorrect deriving of sub channel names when updating channels (#13076)
authorHilbrand Bouwkamp <hilbrand@h72.nl>
Mon, 4 Jul 2022 19:50:03 +0000 (21:50 +0200)
committerGitHub <noreply@github.com>
Mon, 4 Jul 2022 19:50:03 +0000 (21:50 +0200)
Subchannels were created by appending the key. However this was done inside a loop and if multiple updates were needed they would be appended to the channel name, instead of taking the channel name each time.
Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/handler/DSMRMeterHandler.java

index aabef9d2e77400b3ac631af889efa44dc6cae5fd..b1ade25b321656b5e6a79cca6330bcbdd9ab6f9e 100644 (file)
@@ -136,15 +136,13 @@ public class DSMRMeterHandler extends BaseThingHandler implements P1TelegramList
     private synchronized void updateState() {
         logger.trace("Update state for device: {}", getThing().getThingTypeUID().getId());
         if (!lastReceivedValues.isEmpty()) {
-            for (CosemObject cosemObject : lastReceivedValues) {
-                String channel = cosemObject.getType().name().toLowerCase();
-
-                for (Entry<String, ? extends State> entry : cosemObject.getCosemValues().entrySet()) {
-                    if (!entry.getKey().isEmpty()) {
-                        /* CosemObject has a specific sub channel */
-                        channel += "_" + entry.getKey();
-                    }
-                    State newState = entry.getValue();
+            for (final CosemObject cosemObject : lastReceivedValues) {
+                for (final Entry<String, ? extends State> entry : cosemObject.getCosemValues().entrySet()) {
+                    final String channel = cosemObject.getType().name().toLowerCase()
+                            /* CosemObject has a specific sub channel if key not empty */
+                            + (entry.getKey().isEmpty() ? "" : "_" + entry.getKey());
+
+                    final State newState = entry.getValue();
                     logger.debug("Updating state for channel {} to value {}", channel, newState);
                     updateState(channel, newState);
                 }