Fix AutoUpdatePolicy for channel (#3888)

* Fix AutoUpdatePolicy for channel

Fixes #3887

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Simplify setting of auto update policy

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

---------

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
pull/3898/head
Jacob Laursen 2023-12-04 10:56:33 +01:00 committed by GitHub
parent 9a9726b8fe
commit aa305d90d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -96,7 +96,7 @@ public class ChannelBuilder {
ChannelBuilder channelBuilder = create(channel.getUID(), channel.getAcceptedItemType())
.withConfiguration(channel.getConfiguration()).withDefaultTags(channel.getDefaultTags())
.withKind(channel.getKind()).withProperties(channel.getProperties())
.withType(channel.getChannelTypeUID());
.withType(channel.getChannelTypeUID()).withAutoUpdatePolicy(channel.getAutoUpdatePolicy());
String label = channel.getLabel();
if (label != null) {
channelBuilder.withLabel(label);

View File

@ -26,6 +26,7 @@ import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingFactory;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.type.AutoUpdatePolicy;
import org.openhab.core.thing.type.ChannelDefinition;
import org.openhab.core.thing.type.ChannelGroupDefinition;
import org.openhab.core.thing.type.ChannelGroupType;
@ -184,12 +185,17 @@ public class ThingFactoryHelper {
label = channelType.getLabel();
}
AutoUpdatePolicy autoUpdatePolicy = channelDefinition.getAutoUpdatePolicy();
if (autoUpdatePolicy == null) {
autoUpdatePolicy = channelType.getAutoUpdatePolicy();
}
final ChannelBuilder channelBuilder = ChannelBuilder.create(channelUID, channelType.getItemType()) //
.withType(channelType.getUID()) //
.withDefaultTags(channelType.getTags()) //
.withKind(channelType.getKind()) //
.withLabel(label) //
.withAutoUpdatePolicy(channelType.getAutoUpdatePolicy());
.withAutoUpdatePolicy(autoUpdatePolicy);
String description = channelDefinition.getDescription();
if (description == null) {

View File

@ -84,6 +84,7 @@ public class ChannelBuilderTest {
assertThat(otherChannel.getDescription(), is(channel.getDescription()));
assertThat(otherChannel.getKind(), is(channel.getKind()));
assertThat(otherChannel.getLabel(), is(channel.getLabel()));
assertThat(otherChannel.getAutoUpdatePolicy(), is(channel.getAutoUpdatePolicy()));
assertThat(otherChannel.getProperties().size(), is(channel.getProperties().size()));
assertThat(otherChannel.getProperties().get(KEY1), is(channel.getProperties().get(KEY1)));
assertThat(otherChannel.getProperties().get(KEY2), is(channel.getProperties().get(KEY2)));