Skip to content

Commit 062b3b7

Browse files
committed
work in progress
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent bfa5c40 commit 062b3b7

6 files changed

Lines changed: 23 additions & 15 deletions

File tree

bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/ItemChannelLinkRegistry.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package org.openhab.core.thing.link;
1414

15+
import static org.openhab.core.service.StartLevelService.STARTLEVEL_COMPLETE;
16+
1517
import java.util.Collection;
1618
import java.util.HashMap;
1719
import java.util.HashSet;
@@ -47,6 +49,8 @@
4749
import org.openhab.core.thing.ThingUID;
4850
import org.openhab.core.thing.UID;
4951
import org.openhab.core.thing.link.events.LinkEventFactory;
52+
import org.osgi.framework.BundleContext;
53+
import org.osgi.framework.ServiceRegistration;
5054
import org.osgi.service.component.annotations.Activate;
5155
import org.osgi.service.component.annotations.Component;
5256
import org.osgi.service.component.annotations.Modified;
@@ -77,19 +81,22 @@ public class ItemChannelLinkRegistry extends AbstractLinkRegistry<ItemChannelLin
7781
private final ThingRegistry thingRegistry;
7882
private final ItemRegistry itemRegistry;
7983
private final ItemBuilderFactory itemBuilderFactory;
84+
private final ServiceRegistration<?> eventRegistration;
8085

8186
private boolean useTagsGlobally = false;
8287
private int startlevel = 0;
8388

8489
@Activate
8590
public ItemChannelLinkRegistry(final @Nullable Map<String, @Nullable Object> configuration,
8691
final @Reference ThingRegistry thingRegistry, final @Reference ItemRegistry itemRegistry,
87-
final @Reference ItemBuilderFactory itemBuilderFactory) {
92+
final @Reference ItemBuilderFactory itemBuilderFactory, BundleContext bundleContext) {
8893
super(ItemChannelLinkProvider.class);
94+
8995
this.thingRegistry = thingRegistry;
9096
this.itemRegistry = itemRegistry;
9197
this.itemRegistry.addRegistryChangeListener(this);
9298
this.itemBuilderFactory = itemBuilderFactory;
99+
this.eventRegistration = bundleContext.registerService(EventSubscriber.class.getName(), this, null);
93100

94101
modified(configuration);
95102
}
@@ -102,6 +109,7 @@ protected void modified(@Nullable Map<String, @Nullable Object> configuration) {
102109

103110
@Override
104111
protected void deactivate() {
112+
eventRegistration.unregister();
105113
itemRegistry.removeRegistryChangeListener(this);
106114
super.deactivate();
107115
}
@@ -467,18 +475,18 @@ public Set<String> getSubscribedEventTypes() {
467475
}
468476

469477
/**
470-
* When start level reaches 100 then re-initialize all the channel default tags.
478+
* Re-initialize (one off) all the channel default tags when startup is complete.
471479
*/
472480
@Override
473481
public void receive(Event event) {
474-
if (event instanceof StartlevelEvent startLevelEvent) {
475-
int newStartLevel = startLevelEvent.getStartlevel();
476-
if (newStartLevel >= 100 && startlevel < 100) {
482+
if (event instanceof StartlevelEvent startlevelEvent) {
483+
int newStartlevel = startlevelEvent.getStartlevel();
484+
if (newStartlevel != startlevel && newStartlevel >= STARTLEVEL_COMPLETE) {
477485
for (ItemChannelLink link : getAll()) {
478486
assignChannelDefaultTags(link);
479487
}
480488
}
481-
startlevel = newStartLevel;
489+
startlevel = newStartlevel;
482490
}
483491
}
484492
}

itests/org.openhab.core.model.item.tests/itest.bndrun

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ Fragment-Host: org.openhab.core.model.item
124124
com.google.guava;version='[33.3.1,33.3.2)',\
125125
biz.aQute.tester.junit-platform;version='[7.1.0,7.1.1)',\
126126
org.osgi.service.cm;version='[1.6.0,1.6.1)',\
127+
org.openhab.core.model.rule.runtime;version='[5.1.0,5.1.1)',\
127128
org.ops4j.pax.logging.pax-logging-api;version='[2.2.8,2.2.9)',\
128129
com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.18.2,2.18.3)',\
129130
org.yaml.snakeyaml;version='[2.3.0,2.3.1)',\
130131
de.focus_shift.jollyday-core;version='[1.5.4,1.5.5)',\
131-
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)',\
132-
org.openhab.core.model.persistence.runtime;version='[5.1.0,5.1.1)'
132+
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)'

itests/org.openhab.core.model.rule.tests/itest.bndrun

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,4 @@ Fragment-Host: org.openhab.core.model.rule.runtime
131131
com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.18.2,2.18.3)',\
132132
org.yaml.snakeyaml;version='[2.3.0,2.3.1)',\
133133
de.focus_shift.jollyday-core;version='[1.5.4,1.5.5)',\
134-
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)',\
135-
org.openhab.core.model.persistence.runtime;version='[5.1.0,5.1.1)'
134+
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)'

itests/org.openhab.core.model.script.tests/itest.bndrun

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ Fragment-Host: org.openhab.core.model.script
130130
stax2-api;version='[4.2.2,4.2.3)',\
131131
com.google.guava;version='[33.3.1,33.3.2)',\
132132
biz.aQute.tester.junit-platform;version='[7.1.0,7.1.1)',\
133+
org.openhab.core.model.rule.runtime;version='[5.1.0,5.1.1)',\
133134
org.ops4j.pax.logging.pax-logging-api;version='[2.2.8,2.2.9)',\
134135
com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.18.2,2.18.3)',\
135136
org.yaml.snakeyaml;version='[2.3.0,2.3.1)',\
136137
de.focus_shift.jollyday-core;version='[1.5.4,1.5.5)',\
137-
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)',\
138-
org.openhab.core.model.persistence.runtime;version='[5.1.0,5.1.1)'
138+
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)'

itests/org.openhab.core.model.thing.tests/itest.bndrun

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ Fragment-Host: org.openhab.core.model.thing
133133
com.google.guava;version='[33.3.1,33.3.2)',\
134134
biz.aQute.tester.junit-platform;version='[7.1.0,7.1.1)',\
135135
org.osgi.service.cm;version='[1.6.0,1.6.1)',\
136+
org.openhab.core.model.rule.runtime;version='[5.1.0,5.1.1)',\
136137
org.ops4j.pax.logging.pax-logging-api;version='[2.2.8,2.2.9)',\
137138
com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.18.2,2.18.3)',\
138139
org.yaml.snakeyaml;version='[2.3.0,2.3.1)',\
139140
de.focus_shift.jollyday-core;version='[1.5.4,1.5.5)',\
140-
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)',\
141-
org.openhab.core.model.persistence.runtime;version='[5.1.0,5.1.1)'
141+
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)'

itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import org.openhab.core.thing.type.ChannelTypeUID;
8181
import org.openhab.core.types.Command;
8282
import org.openhab.core.types.TimeSeries;
83+
import org.osgi.framework.BundleContext;
8384

8485
/**
8586
*
@@ -93,7 +94,7 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest {
9394
private static class ItemChannelLinkRegistryAdvanced extends ItemChannelLinkRegistry {
9495
public ItemChannelLinkRegistryAdvanced(ThingRegistry thingRegistry, ItemRegistry itemRegistry,
9596
ItemBuilderFactory itemBuilderFactory) {
96-
super(null, thingRegistry, itemRegistry, itemBuilderFactory);
97+
super(null, thingRegistry, itemRegistry, itemBuilderFactory, mock(BundleContext.class));
9798
}
9899

99100
@Override

0 commit comments

Comments
 (0)