use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.
the class MetadataConsoleCommandExtension method removeMetadata.
private void removeMetadata(Console console, String itemName, @Nullable String namespace) {
if (itemRegistry.get(itemName) == null) {
console.println("Warning: Item " + itemName + " does not exist, removing metadata anyway.");
}
if (namespace == null) {
metadataRegistry.stream().filter(MetadataPredicates.ofItem(itemName)).map(Metadata::getUID).forEach(key -> removeMetadata(console, key));
} else {
MetadataKey key = new MetadataKey(namespace, itemName);
removeMetadata(console, key);
}
}
use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.
the class GenericItemProvider2Test method testMetadataUpdate.
@Test
public void testMetadataUpdate() {
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s { meta=\"foo\" }".getBytes()));
Metadata metadata1 = metadataRegistry.get(new MetadataKey("meta", "s"));
assertNotNull(metadata1);
assertEquals("foo", metadata1.getValue());
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s { meta=\"bar\" }".getBytes()));
Metadata metadata2 = metadataRegistry.get(new MetadataKey("meta", "s"));
assertNotNull(metadata2);
assertEquals("bar", metadata2.getValue());
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream("Switch s".getBytes()));
Metadata metadata3 = metadataRegistry.get(new MetadataKey("meta", "s"));
assertNull(metadata3);
}
use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.
the class GenericItemProvider2Test method testMetadata_simple.
@Test
public void testMetadata_simple() {
String model = "Switch simple { namespace=\"value\" } ";
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
Item item = itemRegistry.get("simple");
assertNotNull(item);
Metadata res = metadataRegistry.get(new MetadataKey("namespace", "simple"));
assertNotNull(res);
assertEquals("value", res.getValue());
assertNotNull(res.getConfiguration());
}
use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.
the class GenericItemProvider2Test method testMetadata_configured.
@Test
public void testMetadata_configured() {
String model = //
"Switch simple { namespace=\"value\" } " + "Switch configured { foo=\"bar\" [ answer=42 ] } ";
modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
Item item = itemRegistry.get("configured");
assertNotNull(item);
Metadata res = metadataRegistry.get(new MetadataKey("foo", "configured"));
assertNotNull(res);
assertEquals("bar", res.getValue());
assertEquals(new BigDecimal(42), res.getConfiguration().get("answer"));
modelRepository.removeModel(TESTMODEL_NAME);
res = metadataRegistry.get(new MetadataKey("foo", "configured"));
assertNull(res);
}
use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.
the class ItemResource method addMetadata.
private void addMetadata(EnrichedItemDTO dto, Set<String> namespaces, @Nullable Predicate<Metadata> filter) {
Map<String, Object> metadata = new HashMap<>();
for (String namespace : namespaces) {
MetadataKey key = new MetadataKey(namespace, dto.name);
Metadata md = metadataRegistry.get(key);
if (md != null && (filter == null || filter.test(md))) {
MetadataDTO mdDto = new MetadataDTO();
mdDto.value = md.getValue();
mdDto.config = md.getConfiguration().isEmpty() ? null : md.getConfiguration();
metadata.put(namespace, mdDto);
}
}
if (dto instanceof EnrichedGroupItemDTO) {
for (EnrichedItemDTO member : ((EnrichedGroupItemDTO) dto).members) {
addMetadata(member, namespaces, filter);
}
}
if (!metadata.isEmpty()) {
// we only set it in the dto if there is really data available
dto.metadata = metadata;
}
}
Aggregations