Skip to content

Instantly share code, notes, and snippets.

@jezinka

jezinka/Sensor.java Secret

Last active Aug 9, 2018
Embed
What would you like to do?
public class Sensor {
private long id;
private String label;
private double temperature;
private long timestamp;
private int humidity;
private double lux;
private Double barPressure;
private double vbat, vreg;
Sensor(Map.Entry<String, JsonElement> entry, String label) {
this.id = Long.valueOf(entry.getKey());
this.label = label;
JsonObject measurement = entry.getValue().getAsJsonObject();
this.temperature = measurement.get("hum_temp").getAsDouble();
this.timestamp = measurement.get("stamp").getAsLong();
this.humidity = measurement.get("hum_hum").getAsInt();
this.lux = measurement.get("lux").getAsDouble();
this.barPressure = measurement.get("bar_pres_rel").isJsonNull() ? null : measurement.get("bar_pres_rel").getAsDouble();
this.vbat = measurement.get("vbat").getAsDouble();
this.vreg = measurement.get("vreg").getAsDouble();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment