Skip to content

Commit

Permalink
Fix AutoUpdatePolicy for channel (#3888)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jlaur committed Dec 4, 2023
1 parent 9a9726b commit aa305d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Expand Up @@ -96,7 +96,7 @@ public static ChannelBuilder create(Channel channel) {
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);
Expand Down
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -184,12 +185,17 @@ public static ChannelBuilder createChannelBuilder(ChannelUID channelUID, Channel
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) {
Expand Down
Expand Up @@ -84,6 +84,7 @@ public void testChannelBuilderFromChannel() {
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)));
Expand Down

0 comments on commit aa305d9

Please sign in to comment.