From d777aa46c92710c3776731d5c848a10ce14c08e4 Mon Sep 17 00:00:00 2001 From: Raphael Mack Date: Sat, 3 Dec 2022 14:59:26 +0100 Subject: [PATCH] [resol] Fix handling of WeekTime fields on vbus (#13753) * correct handling of WeekTime fields from and update vbus library, fixes #13447 Signed-off-by: Raphael Mack --- bundles/org.openhab.binding.resol/pom.xml | 2 +- .../resol/handler/ResolThingHandler.java | 20 ++++++++++--------- .../resources/OH-INF/thing/thing-types.xml | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.resol/pom.xml b/bundles/org.openhab.binding.resol/pom.xml index f8d70625e7d2b..dc0586e480b1e 100644 --- a/bundles/org.openhab.binding.resol/pom.xml +++ b/bundles/org.openhab.binding.resol/pom.xml @@ -18,7 +18,7 @@ de.resol vbus - 0.7.0 + 0.10.0 compile diff --git a/bundles/org.openhab.binding.resol/src/main/java/org/openhab/binding/resol/handler/ResolThingHandler.java b/bundles/org.openhab.binding.resol/src/main/java/org/openhab/binding/resol/handler/ResolThingHandler.java index 095c0ac34d224..22c24311b6b74 100644 --- a/bundles/org.openhab.binding.resol/src/main/java/org/openhab/binding/resol/handler/ResolThingHandler.java +++ b/bundles/org.openhab.binding.resol/src/main/java/org/openhab/binding/resol/handler/ResolThingHandler.java @@ -67,7 +67,7 @@ public class ResolThingHandler extends ResolBaseThingHandler { private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm"); - private static final SimpleDateFormat WEEK_FORMAT = new SimpleDateFormat("E, HH:mm"); + private static final SimpleDateFormat WEEK_FORMAT = new SimpleDateFormat("EEE,HH:mm"); static { synchronized (DATE_FORMAT) { @@ -158,13 +158,13 @@ protected void packetReceived(Specification spec, Language lang, Packet packet) Thing thing = getThing(); switch (pfv.getPacketFieldSpec().getType()) { - case WeekTime: case DateTime: acceptedItemType = "DateTime"; break; case Number: acceptedItemType = ResolChannelTypeProvider.itemTypeForUnit(pfv.getPacketFieldSpec().getUnit()); break; + case WeekTime: case Time: default: acceptedItemType = "String"; @@ -249,11 +249,12 @@ protected void packetReceived(Specification spec, Language lang, Packet packet) this.updateState(channelId, q); } else { try { - QuantityType q = new QuantityType<>(str); + QuantityType q = new QuantityType<>(str, Locale + .getDefault()); /* vbus library returns the value in default locale */ this.updateState(channelId, q); } catch (IllegalArgumentException e) { logger.debug("unit of '{}' unknown in openHAB", str); - QuantityType q = new QuantityType<>(dd.toString()); + QuantityType q = new QuantityType<>(dd, Units.ONE); this.updateState(channelId, q); } } @@ -272,8 +273,7 @@ protected void packetReceived(Specification spec, Language lang, Packet packet) break; case WeekTime: synchronized (WEEK_FORMAT) { - DateTimeType d = new DateTimeType(WEEK_FORMAT.format(pfv.getRawValueDate())); - this.updateState(channelId, d); + this.updateState(channelId, new StringType(WEEK_FORMAT.format(pfv.getRawValueDate()))); } break; case DateTime: @@ -287,13 +287,15 @@ protected void packetReceived(Specification spec, Language lang, Packet packet) if (b != null) { ResolBridgeHandler handler = (ResolBridgeHandler) b.getHandler(); String value; + Locale loc; if (handler != null) { - value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(), handler.getLocale()); + loc = handler.getLocale(); } else { - value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(), Locale.getDefault()); + loc = Locale.getDefault(); } + value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(), loc); try { - QuantityType q = new QuantityType<>(value); + QuantityType q = new QuantityType<>(value, loc); this.updateState(channelId, q); } catch (IllegalArgumentException e) { this.updateState(channelId, new StringType(value)); diff --git a/bundles/org.openhab.binding.resol/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.resol/src/main/resources/OH-INF/thing/thing-types.xml index 1099e9c426971..35a065bdbf358 100644 --- a/bundles/org.openhab.binding.resol/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.resol/src/main/resources/OH-INF/thing/thing-types.xml @@ -145,7 +145,7 @@ - DateTime + String Time and day of week. Time