EspHome
This commit is contained in:
parent
4feb38c14c
commit
98c08201f3
@ -1,5 +1,6 @@
|
|||||||
package de.ph87.data.topic;
|
package de.ph87.data.topic;
|
||||||
|
|
||||||
|
import de.ph87.data.topic.parser.EspHome;
|
||||||
import de.ph87.data.topic.parser.PatrixOpenDtu;
|
import de.ph87.data.topic.parser.PatrixOpenDtu;
|
||||||
import de.ph87.data.topic.parser.PatrixSmartMeter;
|
import de.ph87.data.topic.parser.PatrixSmartMeter;
|
||||||
import de.ph87.data.topic.parser.ShellyPlus1PM;
|
import de.ph87.data.topic.parser.ShellyPlus1PM;
|
||||||
@ -12,6 +13,7 @@ public enum TopicType {
|
|||||||
PatrixSmartMeter(PatrixSmartMeter.class),
|
PatrixSmartMeter(PatrixSmartMeter.class),
|
||||||
TasmotaSmartMeter(TasmotaSmartMeter.class),
|
TasmotaSmartMeter(TasmotaSmartMeter.class),
|
||||||
ShellyPlus1PM(ShellyPlus1PM.class),
|
ShellyPlus1PM(ShellyPlus1PM.class),
|
||||||
|
EspHome(EspHome.class),
|
||||||
;
|
;
|
||||||
|
|
||||||
public final Class<? extends ITopicParser> clazz;
|
public final Class<? extends ITopicParser> clazz;
|
||||||
|
|||||||
58
src/main/java/de/ph87/data/topic/parser/EspHome.java
Normal file
58
src/main/java/de/ph87/data/topic/parser/EspHome.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package de.ph87.data.topic.parser;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import de.ph87.data.series.data.delta.DeltaService;
|
||||||
|
import de.ph87.data.series.data.varying.VaryingService;
|
||||||
|
import de.ph87.data.topic.TopicDto;
|
||||||
|
import de.ph87.data.topic.TopicParserAbstract;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class EspHome extends TopicParserAbstract<EspHome.Dto> {
|
||||||
|
|
||||||
|
public EspHome(@NonNull final ObjectMapper mapper, @NonNull final DeltaService deltaService, @NonNull final VaryingService varyingService) {
|
||||||
|
super(Dto.class, mapper, deltaService, varyingService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handle2(@NonNull final TopicDto topic, @NonNull final Dto dto) {
|
||||||
|
if (topic.series0 != null) {
|
||||||
|
if (topic.series0.unit.equals(dto.unit)) {
|
||||||
|
varying(topic.series0, dto.date, dto.value);
|
||||||
|
} else {
|
||||||
|
log.warn("Unit mismatch: dto={}, series={}", dto, topic.series0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Dto {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public final ZonedDateTime date;
|
||||||
|
|
||||||
|
public final double value;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public final String unit;
|
||||||
|
|
||||||
|
public Dto(
|
||||||
|
@JsonProperty(value = "timestamp", required = true) @NonNull final long epochSeconds,
|
||||||
|
@JsonProperty(value = "value", required = true) final double value,
|
||||||
|
@JsonProperty(value = "unit", required = true) final String unit
|
||||||
|
) {
|
||||||
|
this.date = ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSeconds), ZoneId.systemDefault());
|
||||||
|
this.value = value;
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user