JsonObjectBuilder contextUpdateBuilder = Json.createObjectBuilder();
if (rooms != null) {
for (Room room : rooms) {
String name = room.getName();
if (name.equalsIgnoreCase(roomId)) {
SimulationContext context = room.getLocalContext();
int[] lightColor = context.getLightColor();
contextUpdateBuilder
.add(SimulationContext.BRIGHTNESS,
context.getBrightness())
.add(SimulationContext.TEMPERATURE,
context.getTemperature())
.add(SimulationContext.LIGHTCOLOR,
String.format("%d %d %d", lightColor[0],
lightColor[1], lightColor[2]))
.add(SimulationContext.ENERGY_CONSUMPTION,
context.getEnergyConsumption())
.add(SimulationContext.MUSIC_GENRE,
context.getMusicGenre())
.add(SimulationContext.MUSIC_VOLUME,
context.getMusicVolume());
}
}
}
JsonObject contextUpdate = contextUpdateBuilder.build();
return contextUpdate;