mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 13:21:53 +01:00
Support lists for metadata properties in items files (#4330)
Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
parent
6d174a91c2
commit
716045a174
@ -49,7 +49,7 @@ ModelBinding:
|
|||||||
;
|
;
|
||||||
|
|
||||||
ModelProperty:
|
ModelProperty:
|
||||||
key=ID '=' value=ValueType
|
key=ID '=' value+=ValueType (',' value+=ValueType)*
|
||||||
;
|
;
|
||||||
|
|
||||||
ValueType returns ecore::EJavaObject:
|
ValueType returns ecore::EJavaObject:
|
||||||
|
@ -349,7 +349,15 @@ public class GenericItemProvider extends AbstractProvider<Item>
|
|||||||
String config = binding.getConfiguration();
|
String config = binding.getConfiguration();
|
||||||
|
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
binding.getProperties().forEach(p -> configuration.put(p.getKey(), p.getValue()));
|
binding.getProperties().forEach(p -> {
|
||||||
|
Object value = p.getValue();
|
||||||
|
// Single valued lists get unwrapped to just their one value for
|
||||||
|
// backwards compatibility
|
||||||
|
if (value instanceof List listValue && listValue.size() == 1) {
|
||||||
|
value = listValue.get(0);
|
||||||
|
}
|
||||||
|
configuration.put(p.getKey(), value);
|
||||||
|
});
|
||||||
|
|
||||||
BindingConfigReader localReader = reader;
|
BindingConfigReader localReader = reader;
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
|
@ -623,6 +623,41 @@ public class GenericItemProviderTest extends JavaOSGiTest {
|
|||||||
assertThat(metadata3, is(nullValue()));
|
assertThat(metadata3, is(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMetadataPropertyTypes() {
|
||||||
|
String model = "Switch simple { namespace=\"value\"[string=\"string\", bool=false, int=2, stringList=\"string1\",\"string2\", boolList=false,true] } ";
|
||||||
|
|
||||||
|
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
|
||||||
|
Item item = itemRegistry.get("simple");
|
||||||
|
assertThat(item, is(notNullValue()));
|
||||||
|
|
||||||
|
Metadata res = metadataRegistry.get(new MetadataKey("namespace", "simple"));
|
||||||
|
assertThat(res, is(notNullValue()));
|
||||||
|
assertThat(res.getValue(), is("value"));
|
||||||
|
assertThat(res.getConfiguration(), is(notNullValue()));
|
||||||
|
var config = res.getConfiguration();
|
||||||
|
assertThat(config.size(), is(5));
|
||||||
|
assertThat(config.get("string"), is("string"));
|
||||||
|
assertThat(config.get("bool"), is(false));
|
||||||
|
assertThat(config.get("int"), is(new BigDecimal("2")));
|
||||||
|
|
||||||
|
var list = config.get("stringList");
|
||||||
|
assertThat(list, is(notNullValue()));
|
||||||
|
assertThat(list, instanceOf(List.class));
|
||||||
|
List<Object> values = (List<Object>) list;
|
||||||
|
assertThat(values.size(), is(2));
|
||||||
|
assertThat(values.get(0), is("string1"));
|
||||||
|
assertThat(values.get(1), is("string2"));
|
||||||
|
|
||||||
|
list = config.get("boolList");
|
||||||
|
assertThat(list, is(notNullValue()));
|
||||||
|
assertThat(list, instanceOf(List.class));
|
||||||
|
values = (List<Object>) list;
|
||||||
|
assertThat(values.size(), is(2));
|
||||||
|
assertThat(values.get(0), is(false));
|
||||||
|
assertThat(values.get(1), is(true));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTagUpdate() {
|
public void testTagUpdate() {
|
||||||
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s [foo]".getBytes()));
|
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s [foo]".getBytes()));
|
||||||
|
Loading…
Reference in New Issue
Block a user