Skip to content

Commit

Permalink
Remove state description when loading an item with a removed pattern (#…
Browse files Browse the repository at this point in the history
…4068)

* Remove state description when loading an item with a removed pattern

Fix openhab/openhab-webui#2251

Signed-off-by: Laurent Garnier <lg.hc@free.fr>

* Extended integration test testSquareBracketsInFormat

Signed-off-by: Laurent Garnier <lg.hc@free.fr>

---------

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored Jan 27, 2024
1 parent 5f8da67 commit a957122
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ private void processBindingConfigsFromModel(String modelName, EventType type) {
label = label.substring(0, label.indexOf("[")).trim();
stateDescriptionFragments.put(modelItem.getName(),
StateDescriptionFragmentBuilder.create().withPattern(format).build());
} else {
stateDescriptionFragments.remove(modelItem.getName());
}
activeItem.setLabel(label);
activeItem.setCategory(modelItem.getIcon());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.core.model.item.internal;

import static java.util.stream.Collectors.*;
import static java.util.stream.Collectors.joining;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
Expand Down Expand Up @@ -655,5 +655,28 @@ public void testSquareBracketsInFormat() {
StateDescription stateDescription = item.getStateDescription();
assertThat(stateDescription, is(notNullValue()));
assertThat(stateDescription.getPattern(), is("XPATH(/*[name()='liveStreams']/*[name()='stream']):%s"));

model = "Switch s \"Info [%s]\"";
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
item = itemRegistry.get("s");
assertThat(item, is(notNullValue()));
stateDescription = item.getStateDescription();
assertThat(stateDescription, is(notNullValue()));
assertThat(stateDescription.getPattern(), is("%s"));

model = "Switch s \"Info\"";
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
item = itemRegistry.get("s");
assertThat(item, is(notNullValue()));
stateDescription = item.getStateDescription();
assertThat(stateDescription, is(nullValue()));

model = "Switch s \"Info [%s]\"";
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
item = itemRegistry.get("s");
assertThat(item, is(notNullValue()));
stateDescription = item.getStateDescription();
assertThat(stateDescription, is(notNullValue()));
assertThat(stateDescription.getPattern(), is("%s"));
}
}

0 comments on commit a957122

Please sign in to comment.