Skip to content

Commit

Permalink
[resol] Fix handling of WeekTime fields on vbus (#13753)
Browse files Browse the repository at this point in the history
* correct handling of WeekTime fields from and update vbus library, fixes #13447

Signed-off-by: Raphael Mack <[email protected]>
  • Loading branch information
ramack authored Dec 3, 2022
1 parent 86e3b65 commit d777aa4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.resol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>de.resol</groupId>
<artifactId>vbus</artifactId>
<version>0.7.0</version>
<version>0.10.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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:
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
</thing-type>

<channel-type id="weektime">
<item-type>DateTime</item-type>
<item-type>String</item-type>
<label>Time</label>
<description>Time and day of week.</description>
<category>Time</category>
Expand Down

0 comments on commit d777aa4

Please sign in to comment.