public static SensorSummary sensorSummaryForCatalog(Sensor<?> sensor) { return new SensorSummary(sensor.getName(), sensor.getTypeName(), sensor.getDescription(), null); }
@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")); }
@Test public void testRebindPersistsDynamicAttribute() throws Exception { final String sensorName = "test.mydynamicsensor"; final String sensorDescription = "My description"; final AttributeSensor<String> MY_DYNAMIC_SENSOR = new BasicAttributeSensor<String>( String.class, sensorName, sensorDescription); origApp.sensors().set(MY_DYNAMIC_SENSOR, "myval"); assertEquals(origApp.getEntityType().getSensor(sensorName).getDescription(), sensorDescription); newApp = rebind(); assertEquals(newApp.getAttribute(MY_DYNAMIC_SENSOR), "myval"); assertEquals(newApp.getEntityType().getSensor(sensorName).getDescription(), sensorDescription); }
public static SensorSummary sensorSummary(Entity entity, Sensor<?> sensor, UriBuilder ub) { URI applicationUri = serviceUriBuilder(ub, ApplicationApi.class, "get").build(entity.getApplicationId()); URI entityUri = serviceUriBuilder(ub, EntityApi.class, "get").build(entity.getApplicationId(), entity.getId()); URI selfUri = serviceUriBuilder(ub, SensorApi.class, "get").build(entity.getApplicationId(), entity.getId(), sensor.getName()); MutableMap.Builder<String, URI> lb = MutableMap.<String, URI>builder() .put("self", selfUri) .put("application", applicationUri) .put("entity", entityUri) .put("action:json", selfUri); if (sensor instanceof AttributeSensor) { Iterable<RendererHints.NamedAction> hints = Iterables.filter(RendererHints.getHintsFor((AttributeSensor<?>)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()); }