[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 <ramack@raphael-mack.de>
This commit is contained in:
Raphael Mack 2022-12-03 14:59:26 +01:00 committed by GitHub
parent 86e3b65816
commit d777aa46c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View File

@ -18,7 +18,7 @@
<dependency> <dependency>
<groupId>de.resol</groupId> <groupId>de.resol</groupId>
<artifactId>vbus</artifactId> <artifactId>vbus</artifactId>
<version>0.7.0</version> <version>0.10.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -67,7 +67,7 @@ public class ResolThingHandler extends ResolBaseThingHandler {
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm"); 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 { static {
synchronized (DATE_FORMAT) { synchronized (DATE_FORMAT) {
@ -158,13 +158,13 @@ public class ResolThingHandler extends ResolBaseThingHandler {
Thing thing = getThing(); Thing thing = getThing();
switch (pfv.getPacketFieldSpec().getType()) { switch (pfv.getPacketFieldSpec().getType()) {
case WeekTime:
case DateTime: case DateTime:
acceptedItemType = "DateTime"; acceptedItemType = "DateTime";
break; break;
case Number: case Number:
acceptedItemType = ResolChannelTypeProvider.itemTypeForUnit(pfv.getPacketFieldSpec().getUnit()); acceptedItemType = ResolChannelTypeProvider.itemTypeForUnit(pfv.getPacketFieldSpec().getUnit());
break; break;
case WeekTime:
case Time: case Time:
default: default:
acceptedItemType = "String"; acceptedItemType = "String";
@ -249,11 +249,12 @@ public class ResolThingHandler extends ResolBaseThingHandler {
this.updateState(channelId, q); this.updateState(channelId, q);
} else { } else {
try { 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); this.updateState(channelId, q);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.debug("unit of '{}' unknown in openHAB", str); 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); this.updateState(channelId, q);
} }
} }
@ -272,8 +273,7 @@ public class ResolThingHandler extends ResolBaseThingHandler {
break; break;
case WeekTime: case WeekTime:
synchronized (WEEK_FORMAT) { synchronized (WEEK_FORMAT) {
DateTimeType d = new DateTimeType(WEEK_FORMAT.format(pfv.getRawValueDate())); this.updateState(channelId, new StringType(WEEK_FORMAT.format(pfv.getRawValueDate())));
this.updateState(channelId, d);
} }
break; break;
case DateTime: case DateTime:
@ -287,13 +287,15 @@ public class ResolThingHandler extends ResolBaseThingHandler {
if (b != null) { if (b != null) {
ResolBridgeHandler handler = (ResolBridgeHandler) b.getHandler(); ResolBridgeHandler handler = (ResolBridgeHandler) b.getHandler();
String value; String value;
Locale loc;
if (handler != null) { if (handler != null) {
value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(), handler.getLocale()); loc = handler.getLocale();
} else { } else {
value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(), Locale.getDefault()); loc = Locale.getDefault();
} }
value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(), loc);
try { try {
QuantityType<?> q = new QuantityType<>(value); QuantityType<?> q = new QuantityType<>(value, loc);
this.updateState(channelId, q); this.updateState(channelId, q);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
this.updateState(channelId, new StringType(value)); this.updateState(channelId, new StringType(value));

View File

@ -145,7 +145,7 @@
</thing-type> </thing-type>
<channel-type id="weektime"> <channel-type id="weektime">
<item-type>DateTime</item-type> <item-type>String</item-type>
<label>Time</label> <label>Time</label>
<description>Time and day of week.</description> <description>Time and day of week.</description>
<category>Time</category> <category>Time</category>