@Test public void testGetSensor() throws Exception { Sensor<?> sensor = entity.getEntityType().getSensor("entity.sensor.added"); assertEquals(sensor.getDescription(), "Sensor dynamically added to entity"); assertEquals(sensor.getName(), "entity.sensor.added"); assertNull(entity.getEntityType().getSensor("does.not.exist")); }
@SuppressWarnings("rawtypes") public static SensorSummary sensorSummary(Entity entity, Sensor<?> sensor) { String applicationUri = "/v1/applications/" + entity.getApplicationId(); String entityUri = applicationUri + "/entities/" + entity.getId(); String selfUri = entityUri + "/sensors/" + URLParamEncoder.encode(sensor.getName()); MutableMap.Builder<String, URI> lb = MutableMap.<String, URI>builder() .put("self", URI.create(selfUri)) .put("application", URI.create(applicationUri)) .put("entity", URI.create(entityUri)) .put("action:json", URI.create(selfUri)); Iterable<RendererHints.NamedAction> hints = Iterables.filter(RendererHints.getHintsFor(sensor), RendererHints.NamedAction.class); for (RendererHints.NamedAction na : hints) addNamedAction(lb, na, entity, sensor); return new SensorSummary( sensor.getName(), sensor.getTypeName(), sensor.getDescription(), lb.build()); }
public static SensorSummary sensorSummaryForCatalog(Sensor<?> sensor) { return new SensorSummary(sensor.getName(), sensor.getTypeName(), sensor.getDescription(), null); }