@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"));
  }
Beispiel #2
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 public void onEvent(SensorEvent event) {
   Number value = recompute();
   Number typedValue = cast(value, (Class<? extends Number>) target.getType());
   if (target instanceof AttributeSensor) {
     entity.setAttribute((AttributeSensor) target, typedValue);
   } else if (typedValue != null) entity.emit((Sensor) target, typedValue);
 }
  @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());
  }
 @Override
 public String toString() {
   return (e != null ? e.getId() : "*") + ":" + (s != null ? s.getName() : "*");
 }
 public static SensorSummary sensorSummaryForCatalog(Sensor<?> sensor) {
   return new SensorSummary(sensor.getName(), sensor.getTypeName(), sensor.getDescription(), null);
 }