PatrixJsonHandler + Unit.VOLUME_L + Unit.LENGTH_CM
This commit is contained in:
parent
5358f1b9f6
commit
d7ee5062e4
@ -5,7 +5,7 @@ spring.datasource.driverClassName=org.h2.Driver
|
|||||||
spring.datasource.username=sa
|
spring.datasource.username=sa
|
||||||
spring.datasource.password=password
|
spring.datasource.password=password
|
||||||
#-
|
#-
|
||||||
#spring.jpa.hibernate.ddl-auto=create
|
spring.jpa.hibernate.ddl-auto=create
|
||||||
#-
|
#-
|
||||||
de.ph87.data.message.receive.mqtt.host=10.0.0.50
|
de.ph87.data.message.receive.mqtt.host=10.0.0.50
|
||||||
de.ph87.data.message.receive.mqtt.topic=#
|
de.ph87.data.message.receive.mqtt.topic=#
|
||||||
|
|||||||
@ -0,0 +1,73 @@
|
|||||||
|
package de.ph87.data.message.handler;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import de.ph87.data.message.IMessageHandler;
|
||||||
|
import de.ph87.data.message.Message;
|
||||||
|
import de.ph87.data.series.meter.MeterInbound;
|
||||||
|
import de.ph87.data.series.varying.VaryingInbound;
|
||||||
|
import de.ph87.data.value.Unit;
|
||||||
|
import de.ph87.data.value.Value;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PatrixJsonHandler implements IMessageHandler {
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
private final ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(@NonNull final Message message) throws Exception {
|
||||||
|
if (!message.topic.endsWith("/PatrixJson")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Inbound inbound = objectMapper.readValue(message.payload, Inbound.class);
|
||||||
|
applicationEventPublisher.publishEvent(inbound);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||||
|
@JsonSubTypes({
|
||||||
|
@JsonSubTypes.Type(name = "VARYING", value = Varying.class),
|
||||||
|
@JsonSubTypes.Type(name = "METER", value = Meter.class),
|
||||||
|
})
|
||||||
|
private interface Inbound {
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
VARYING,
|
||||||
|
METER,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public static class Varying extends VaryingInbound implements Inbound {
|
||||||
|
|
||||||
|
protected Varying(@NonNull final String name, final long date, final double value, @NonNull final Unit unit) {
|
||||||
|
super(name, ZonedDateTime.ofInstant(Instant.ofEpochSecond(date), ZoneId.systemDefault()), new Value(value, unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public static class Meter extends MeterInbound implements Inbound {
|
||||||
|
|
||||||
|
protected Meter(@NonNull final String name, @NonNull final String number, final long date, final double value, @NonNull final Unit unit) {
|
||||||
|
super(name, number, ZonedDateTime.ofInstant(Instant.ofEpochSecond(date), ZoneId.systemDefault()), new Value(value, unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,11 +1,13 @@
|
|||||||
package de.ph87.data.value;
|
package de.ph87.data.value;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.*;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.databind.*;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import lombok.*;
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public enum Unit {
|
public enum Unit {
|
||||||
TEMPERATURE_C("°C"),
|
TEMPERATURE_C("°C"),
|
||||||
@ -50,7 +52,9 @@ public enum Unit {
|
|||||||
DOOR_BOOLEAN("", 1, BOOLEAN),
|
DOOR_BOOLEAN("", 1, BOOLEAN),
|
||||||
WINDOW_BOOLEAN("", 1, BOOLEAN),
|
WINDOW_BOOLEAN("", 1, BOOLEAN),
|
||||||
LIGHT_BOOLEAN("", 1, BOOLEAN),
|
LIGHT_BOOLEAN("", 1, BOOLEAN),
|
||||||
;
|
|
||||||
|
VOLUME_L("l"),
|
||||||
|
LENGTH_CM("cm");
|
||||||
|
|
||||||
public final String unit;
|
public final String unit;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user