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