4949import org .openhab .core .model .items .ModelGroupItem ;
5050import org .openhab .core .model .items .ModelItem ;
5151import org .openhab .core .model .items .ModelNormalItem ;
52- import org .openhab .core .thing .Channel ;
53- import org .openhab .core .thing .ChannelUID ;
54- import org .openhab .core .thing .Thing ;
55- import org .openhab .core .thing .ThingRegistry ;
56- import org .openhab .core .thing .link .ItemChannelLink ;
57- import org .openhab .core .thing .link .ItemChannelLinkRegistry ;
5852import org .openhab .core .types .StateDescriptionFragment ;
5953import org .openhab .core .types .StateDescriptionFragmentBuilder ;
6054import org .openhab .core .types .StateDescriptionFragmentProvider ;
8074public class GenericItemProvider extends AbstractProvider <Item >
8175 implements ModelRepositoryChangeListener , ItemProvider , StateDescriptionFragmentProvider {
8276
83- public static final String USE_TAGS = "useTags" ;
84-
8577 private final Logger logger = LoggerFactory .getLogger (GenericItemProvider .class );
8678
8779 /** to keep track of all binding config readers */
@@ -97,20 +89,13 @@ public class GenericItemProvider extends AbstractProvider<Item>
9789
9890 private final Map <String , StateDescriptionFragment > stateDescriptionFragments = new ConcurrentHashMap <>();
9991
100- private final ThingRegistry thingRegistry ;
101- private final ItemChannelLinkRegistry itemChannelLinkRegistry ;
102-
10392 private Integer rank ;
10493
10594 @ Activate
10695 public GenericItemProvider (final @ Reference ModelRepository modelRepository ,
107- final @ Reference GenericMetadataProvider genericMetadataProvider ,
108- final @ Reference ThingRegistry thingRegistry ,
109- final @ Reference ItemChannelLinkRegistry itemChannelLinkRegistry , Map <String , Object > properties ) {
96+ final @ Reference GenericMetadataProvider genericMetadataProvider , Map <String , Object > properties ) {
11097 this .modelRepository = modelRepository ;
11198 this .genericMetaDataProvider = genericMetadataProvider ;
112- this .thingRegistry = thingRegistry ;
113- this .itemChannelLinkRegistry = itemChannelLinkRegistry ;
11499
115100 Object serviceRanking = properties .get (Constants .SERVICE_RANKING );
116101 if (serviceRanking instanceof Integer integerValue ) {
@@ -298,44 +283,7 @@ private void processBindingConfigsFromModel(String modelName, EventType type) {
298283 * Assign any tags that are defined directly in the item definition text
299284 */
300285 private void assignTags (ModelItem modelItem , ActiveItem item ) {
301- Collection <String > newTags = modelItem .getTags ();
302- if (!newTags .isEmpty ()) {
303- item .addTags (newTags );
304- logger .debug ("Item '{}' tags '{}' assigned" , item .getName (), newTags );
305- }
306- }
307-
308- /**
309- * Assign any tags that are defined in any linked channel's default tags
310- */
311- private Item assignDefaultTags (Item baseItem ) {
312- if (baseItem instanceof ActiveItem item ) {
313- for (ItemChannelLink link : itemChannelLinkRegistry .getLinks (item .getName ())) {
314- Configuration config = link .getConfiguration ();
315- if (Boolean .TRUE .equals (config .get (USE_TAGS ))) {
316- ChannelUID channelUID = link .getLinkedUID ();
317- Thing thing = thingRegistry .get (channelUID .getThingUID ());
318- if (thing != null ) {
319- Channel channel = thing .getChannel (channelUID .getId ());
320- if (channel != null ) {
321- Collection <String > newTags = channel .getDefaultTags ();
322- if (!newTags .isEmpty ()) {
323- Collection <String > oldTags = item .getTags ();
324- if (oldTags .isEmpty ()) {
325- item .addTags (newTags );
326- logger .debug ("Item '{}' tags '{}' assigned from channel '{}'." , item .getName (),
327- newTags , channel .getUID ());
328- } else if (!newTags .equals (oldTags )) {
329- logger .warn ("Item '{}' forbidden to assign tags from multiple sources." ,
330- item .getName ());
331- }
332- }
333- }
334- }
335- }
336- }
337- }
338- return baseItem ;
286+ item .addTags (modelItem .getTags ());
339287 }
340288
341289 private GroupItem applyGroupFunction (Item baseItem , ModelGroupItem modelGroupItem , ModelGroupFunction function ) {
@@ -455,8 +403,6 @@ public void modelChanged(String modelName, EventType type) {
455403 case MODIFIED :
456404 Map <String , Item > oldItems = toItemMap (itemsMap .get (modelName ));
457405 Map <String , Item > newItems = toItemMap (getItemsFromModel (modelName ));
458- processBindingConfigsFromModel (modelName , type );
459- itemsMap .put (modelName , newItems .values ().stream ().map (i -> assignDefaultTags (i )).toList ());
460406 for (Item newItem : newItems .values ()) {
461407 Item oldItem = oldItems .get (newItem .getName ());
462408 if (oldItem != null ) {
@@ -467,8 +413,7 @@ public void modelChanged(String modelName, EventType type) {
467413 notifyListenersAboutAddedElement (newItem );
468414 }
469415 }
470- // TODO did moving the following line up to #458 cause unexpected effects?
471- // processBindingConfigsFromModel(modelName, type);
416+ processBindingConfigsFromModel (modelName , type );
472417 for (Item oldItem : oldItems .values ()) {
473418 if (!newItems .containsKey (oldItem .getName ())) {
474419 notifyAndCleanup (oldItem );
0 commit comments