Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.common.AbstractUID;
import org.openhab.core.items.GroupItem;
import org.openhab.core.items.ItemUtil;
import org.openhab.core.model.yaml.YamlElement;
import org.openhab.core.model.yaml.YamlElementName;
import org.openhab.core.model.yaml.internal.util.YamlElementUtils;
Expand Down Expand Up @@ -88,9 +89,10 @@ public boolean isValid(@Nullable List<@NonNull String> errors, @Nullable List<@N
return false;
}
boolean ok = true;
if (!ID_PATTERN.matcher(name).matches()) {
addToList(errors, "invalid item: name \"%s\" not matching the expected syntax %s".formatted(name,
ID_PATTERN.pattern()));
if (!ItemUtil.isValidItemName(name)) {
addToList(errors,
"invalid item \"%s\": \"name\" must begin with a letter or underscore followed by alphanumeric characters and underscores, and must not contain any other symbols."
.formatted(name));
ok = false;
}
List<String> subErrors = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public void testIsValid() throws IOException {
item.name = "$name";
assertFalse(item.isValid(null, null));
item.name = "my-name";
assertFalse(item.isValid(null, null));
item.name = "my_name";
assertTrue(item.isValid(null, null));

item.type = "Group";
Expand Down Expand Up @@ -123,10 +125,10 @@ public void testEquals() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name-2";
item1.name = "item_name";
item2.name = "item_name_2";
assertFalse(item1.equals(item2));
item2.name = "item-name";
item2.name = "item_name";
assertTrue(item1.equals(item2));
assertEquals(item1.hashCode(), item2.hashCode());

Expand Down Expand Up @@ -206,8 +208,8 @@ public void testEqualsWithLabel() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "String";
item2.type = "String";

Expand Down Expand Up @@ -235,8 +237,8 @@ public void testEqualsWithIcon() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "Number";
item2.type = "Number";

Expand Down Expand Up @@ -264,8 +266,8 @@ public void testEqualsWithFormat() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "Number";
item2.type = "Number";

Expand Down Expand Up @@ -293,8 +295,8 @@ public void testEqualsWithUnit() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "Number";
item2.type = "Number";

Expand Down Expand Up @@ -322,8 +324,8 @@ public void testEqualsWithAutoupdate() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "Number";
item2.type = "Number";

Expand Down Expand Up @@ -364,8 +366,8 @@ public void testEqualsWithGroups() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "Number";
item2.type = "Number";

Expand Down Expand Up @@ -406,8 +408,8 @@ public void testEqualsWithTags() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "Number";
item2.type = "Number";

Expand Down Expand Up @@ -449,8 +451,8 @@ public void testEqualsWithChannels() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "Number";
item2.type = "Number";

Expand Down Expand Up @@ -499,8 +501,8 @@ public void testEqualsWithMetadata() throws IOException {
YamlItemDTO item1 = new YamlItemDTO();
YamlItemDTO item2 = new YamlItemDTO();

item1.name = "item-name";
item2.name = "item-name";
item1.name = "item_name";
item2.name = "item_name";
item1.type = "Number";
item2.type = "Number";

Expand Down