[resol] correct handling of system date/time field (#10811)
* correct handling of system date/time field to close #10684 Signed-off-by: Raphael Mack <ramack@raphael-mack.de> * further fix Signed-off-by: Raphael Mack <ramack@raphael-mack.de>
This commit is contained in:
parent
10f5ca8578
commit
72e3729ca7
@ -65,10 +65,20 @@ public class ResolThingHandler extends ResolBaseThingHandler {
|
|||||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
|
||||||
DateTimeType.DATE_PATTERN_WITH_TZ_AND_MS_GENERAL);
|
DateTimeType.DATE_PATTERN_WITH_TZ_AND_MS_GENERAL);
|
||||||
|
|
||||||
|
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||||
|
|
||||||
|
private static final SimpleDateFormat WEEK_FORMAT = new SimpleDateFormat("E, HH:mm");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
synchronized (DATE_FORMAT) {
|
synchronized (DATE_FORMAT) {
|
||||||
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
}
|
}
|
||||||
|
synchronized (TIME_FORMAT) {
|
||||||
|
TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
synchronized (WEEK_FORMAT) {
|
||||||
|
WEEK_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResolThingHandler(Thing thing, ResolStateDescriptionOptionProvider stateDescriptionProvider) {
|
public ResolThingHandler(Thing thing, ResolStateDescriptionOptionProvider stateDescriptionProvider) {
|
||||||
@ -134,7 +144,11 @@ public class ResolThingHandler extends ResolBaseThingHandler {
|
|||||||
channelTypeUID = new ChannelTypeUID(ResolBindingConstants.BINDING_ID,
|
channelTypeUID = new ChannelTypeUID(ResolBindingConstants.BINDING_ID,
|
||||||
pfv.getPacketFieldSpec().getUnit().getUnitCodeText());
|
pfv.getPacketFieldSpec().getUnit().getUnitCodeText());
|
||||||
} else if (pfv.getPacketFieldSpec().getType() == SpecificationFile.Type.DateTime) {
|
} else if (pfv.getPacketFieldSpec().getType() == SpecificationFile.Type.DateTime) {
|
||||||
channelTypeUID = new ChannelTypeUID(ResolBindingConstants.BINDING_ID, "DateTime");
|
channelTypeUID = new ChannelTypeUID(ResolBindingConstants.BINDING_ID, "datetime");
|
||||||
|
} else if (pfv.getPacketFieldSpec().getType() == SpecificationFile.Type.WeekTime) {
|
||||||
|
channelTypeUID = new ChannelTypeUID(ResolBindingConstants.BINDING_ID, "weektime");
|
||||||
|
} else if (pfv.getPacketFieldSpec().getType() == SpecificationFile.Type.Time) {
|
||||||
|
channelTypeUID = new ChannelTypeUID(ResolBindingConstants.BINDING_ID, "time");
|
||||||
} else {
|
} else {
|
||||||
/* used for enums and the numeric types without unit */
|
/* used for enums and the numeric types without unit */
|
||||||
channelTypeUID = new ChannelTypeUID(ResolBindingConstants.BINDING_ID, "None");
|
channelTypeUID = new ChannelTypeUID(ResolBindingConstants.BINDING_ID, "None");
|
||||||
@ -144,10 +158,10 @@ 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 WeekTime:
|
|
||||||
case Number:
|
case Number:
|
||||||
acceptedItemType = ResolChannelTypeProvider.itemTypeForUnit(pfv.getPacketFieldSpec().getUnit());
|
acceptedItemType = ResolChannelTypeProvider.itemTypeForUnit(pfv.getPacketFieldSpec().getUnit());
|
||||||
break;
|
break;
|
||||||
@ -178,6 +192,21 @@ public class ResolThingHandler extends ResolBaseThingHandler {
|
|||||||
Channel channel = ChannelBuilder.create(channelUID, "Number").withType(channelTypeUID)
|
Channel channel = ChannelBuilder.create(channelUID, "Number").withType(channelTypeUID)
|
||||||
.withLabel(pfv.getName(lang)).build();
|
.withLabel(pfv.getName(lang)).build();
|
||||||
|
|
||||||
|
thingBuilder.withChannel(channel).withLabel(thing.getLabel());
|
||||||
|
updateThing(thingBuilder.build());
|
||||||
|
} else if ("DateTime".equals(acceptedItemType)) {
|
||||||
|
/* a date channel */
|
||||||
|
Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withType(channelTypeUID)
|
||||||
|
.withLabel(pfv.getName(lang)).build();
|
||||||
|
|
||||||
|
thingBuilder.withChannel(channel).withLabel(thing.getLabel());
|
||||||
|
updateThing(thingBuilder.build());
|
||||||
|
|
||||||
|
} else if ("String".equals(acceptedItemType)) {
|
||||||
|
/* a string channel */
|
||||||
|
Channel channel = ChannelBuilder.create(channelUID, "String").withType(channelTypeUID)
|
||||||
|
.withLabel(pfv.getName(lang)).build();
|
||||||
|
|
||||||
thingBuilder.withChannel(channel).withLabel(thing.getLabel());
|
thingBuilder.withChannel(channel).withLabel(thing.getLabel());
|
||||||
updateThing(thingBuilder.build());
|
updateThing(thingBuilder.build());
|
||||||
} else if (pfv.getRawValueDouble() != null) {
|
} else if (pfv.getRawValueDouble() != null) {
|
||||||
@ -185,6 +214,13 @@ public class ResolThingHandler extends ResolBaseThingHandler {
|
|||||||
Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withType(channelTypeUID)
|
Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withType(channelTypeUID)
|
||||||
.withLabel(pfv.getName(lang)).build();
|
.withLabel(pfv.getName(lang)).build();
|
||||||
|
|
||||||
|
thingBuilder.withChannel(channel).withLabel(thing.getLabel());
|
||||||
|
updateThing(thingBuilder.build());
|
||||||
|
} else {
|
||||||
|
/* a string channel */
|
||||||
|
Channel channel = ChannelBuilder.create(channelUID, "String").withType(channelTypeUID)
|
||||||
|
.withLabel(pfv.getName(lang)).build();
|
||||||
|
|
||||||
thingBuilder.withChannel(channel).withLabel(thing.getLabel());
|
thingBuilder.withChannel(channel).withLabel(thing.getLabel());
|
||||||
updateThing(thingBuilder.build());
|
updateThing(thingBuilder.build());
|
||||||
}
|
}
|
||||||
@ -229,19 +265,33 @@ public class ResolThingHandler extends ResolBaseThingHandler {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
|
case Time:
|
||||||
|
synchronized (TIME_FORMAT) {
|
||||||
|
this.updateState(channelId, new StringType(TIME_FORMAT.format(pfv.getRawValueDate())));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WeekTime:
|
||||||
|
synchronized (WEEK_FORMAT) {
|
||||||
|
DateTimeType d = new DateTimeType(WEEK_FORMAT.format(pfv.getRawValueDate()));
|
||||||
|
this.updateState(channelId, d);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case DateTime:
|
case DateTime:
|
||||||
synchronized (DATE_FORMAT) {
|
synchronized (DATE_FORMAT) {
|
||||||
DateTimeType d = new DateTimeType(DATE_FORMAT.format(pfv.getRawValueDate()));
|
DateTimeType d = new DateTimeType(DATE_FORMAT.format(pfv.getRawValueDate()));
|
||||||
this.updateState(channelId, d);
|
this.updateState(channelId, d);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WeekTime:
|
|
||||||
case Time:
|
|
||||||
default:
|
default:
|
||||||
Bridge b = getBridge();
|
Bridge b = getBridge();
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
String value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(),
|
ResolBridgeHandler handler = (ResolBridgeHandler) b.getHandler();
|
||||||
((ResolBridgeHandler) b).getLocale());
|
String value;
|
||||||
|
if (handler != null) {
|
||||||
|
value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(), handler.getLocale());
|
||||||
|
} else {
|
||||||
|
value = pfv.formatTextValue(pfv.getPacketFieldSpec().getUnit(), Locale.getDefault());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
QuantityType<?> q = new QuantityType<>(value);
|
QuantityType<?> q = new QuantityType<>(value);
|
||||||
this.updateState(channelId, q);
|
this.updateState(channelId, q);
|
||||||
|
|||||||
@ -144,6 +144,29 @@
|
|||||||
|
|
||||||
</thing-type>
|
</thing-type>
|
||||||
|
|
||||||
|
<channel-type id="weektime">
|
||||||
|
<item-type>DateTime</item-type>
|
||||||
|
<label>Time</label>
|
||||||
|
<description>Time and day of week.</description>
|
||||||
|
<category>Time</category>
|
||||||
|
<state readOnly="true"/>
|
||||||
|
</channel-type>
|
||||||
|
|
||||||
|
<channel-type id="time">
|
||||||
|
<item-type>String</item-type>
|
||||||
|
<label>Time</label>
|
||||||
|
<category>Time</category>
|
||||||
|
<state readOnly="true"/>
|
||||||
|
</channel-type>
|
||||||
|
|
||||||
|
<channel-type id="datetime">
|
||||||
|
<item-type>DateTime</item-type>
|
||||||
|
<label>Time</label>
|
||||||
|
<description>Time and date.</description>
|
||||||
|
<category>Time</category>
|
||||||
|
<state readOnly="true"/>
|
||||||
|
</channel-type>
|
||||||
|
|
||||||
<channel-type id="None">
|
<channel-type id="None">
|
||||||
<item-type>Number</item-type>
|
<item-type>Number</item-type>
|
||||||
<label>Any</label>
|
<label>Any</label>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user