Bringing a solution to issue #14256. (#14265)

This solution is not the best but takes in account observations made in issue #13015.

Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2023-01-27 08:49:47 +01:00 committed by GitHub
parent 9ddcbb55ad
commit 26d608c8da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 19 deletions

View File

@ -69,26 +69,24 @@ public class MeasureCapability extends RestCapability<WeatherApi> {
handler.getActiveChannels().filter(channel -> !channel.getConfiguration().getProperties().isEmpty()) handler.getActiveChannels().filter(channel -> !channel.getConfiguration().getProperties().isEmpty())
.forEach(channel -> { .forEach(channel -> {
ChannelTypeUID channelTypeUID = channel.getChannelTypeUID(); ChannelTypeUID channelTypeUID = channel.getChannelTypeUID();
if (channelTypeUID != null) { if (channelTypeUID == null) {
MeasureConfiguration measureDef = channel.getConfiguration().as(MeasureConfiguration.class); return;
String descriptor = channelTypeUID.getId().split("-")[0]; }
try {
Object result = measureDef.limit.isBlank() MeasureConfiguration measureDef = channel.getConfiguration().as(MeasureConfiguration.class);
? api.getMeasures(deviceId, moduleId, measureDef.period, descriptor) String descriptor = channelTypeUID.getId().split("-")[0];
: api.getMeasures(deviceId, moduleId, measureDef.period, descriptor, try {
measureDef.limit); Object result = measureDef.limit.isBlank()
MeasureClass.AS_SET.stream().filter(mc -> mc.apiDescriptor.equals(descriptor)).findFirst() ? api.getMeasures(deviceId, moduleId, measureDef.period, descriptor)
.ifPresent(mc -> { : api.getMeasures(deviceId, moduleId, measureDef.period, descriptor, measureDef.limit);
State state = result instanceof ZonedDateTime MeasureClass.AS_SET.stream().filter(mc -> mc.apiDescriptor.equals(descriptor))
? toDateTimeType((ZonedDateTime) result) .reduce((first, second) -> second)
.ifPresent(mc -> measures.put(channel.getUID().getIdWithoutGroup(),
result instanceof ZonedDateTime ? toDateTimeType((ZonedDateTime) result)
: result instanceof Double ? toQuantityType((Double) result, mc) : result instanceof Double ? toQuantityType((Double) result, mc)
: UnDefType.UNDEF; : UnDefType.UNDEF));
measures.put(channel.getUID().getIdWithoutGroup(), state); } catch (NetatmoException e) {
}); logger.warn("Error getting measures for channel {}, check configuration", channel.getLabel());
} catch (NetatmoException e) {
logger.warn("Error getting measures for channel {}, check configuration",
channel.getLabel());
}
} }
}); });
} }