[Netatmo] Avoid double refresh of weather channels (#15686)
* Solves issue #15684 * Removing excessive usage of inline typecast --------- Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
@@ -47,7 +47,6 @@ import org.openhab.core.types.Command;
|
|||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class Capability {
|
public class Capability {
|
||||||
|
|
||||||
protected final Thing thing;
|
protected final Thing thing;
|
||||||
protected final CommonInterface handler;
|
protected final CommonInterface handler;
|
||||||
protected final ModuleType moduleType;
|
protected final ModuleType moduleType;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||||||
import org.openhab.binding.netatmo.internal.api.NetatmoException;
|
import org.openhab.binding.netatmo.internal.api.NetatmoException;
|
||||||
import org.openhab.binding.netatmo.internal.api.WeatherApi;
|
import org.openhab.binding.netatmo.internal.api.WeatherApi;
|
||||||
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
|
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
|
||||||
|
import org.openhab.binding.netatmo.internal.api.dto.Device;
|
||||||
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
|
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
|
||||||
import org.openhab.binding.netatmo.internal.config.MeasureConfiguration;
|
import org.openhab.binding.netatmo.internal.config.MeasureConfiguration;
|
||||||
import org.openhab.binding.netatmo.internal.handler.CommonInterface;
|
import org.openhab.binding.netatmo.internal.handler.CommonInterface;
|
||||||
@@ -56,6 +57,13 @@ public class MeasureCapability extends CacheWeatherCapability {
|
|||||||
measureChannelHelper.setMeasures(measures);
|
measureChannelHelper.setMeasures(measures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateNADevice(Device newData) {
|
||||||
|
// Resolution of issue #15684 :
|
||||||
|
// Do not transfer newData to superclass - MeasureCapability pulls its own data based on measurement channels
|
||||||
|
// configuration and store them in 'measures' for the channel helper.
|
||||||
|
}
|
||||||
|
|
||||||
private void updateMeasures(WeatherApi api, String deviceId, @Nullable String moduleId) {
|
private void updateMeasures(WeatherApi api, String deviceId, @Nullable String moduleId) {
|
||||||
measures.clear();
|
measures.clear();
|
||||||
handler.getActiveChannels().filter(channel -> !channel.getConfiguration().getProperties().isEmpty())
|
handler.getActiveChannels().filter(channel -> !channel.getConfiguration().getProperties().isEmpty())
|
||||||
|
|||||||
@@ -40,14 +40,12 @@ public class HumidityChannelHelper extends ChannelHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
|
protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
|
||||||
switch (channelId) {
|
return switch (channelId) {
|
||||||
case CHANNEL_HUMIDEX:
|
case CHANNEL_HUMIDEX -> new DecimalType(humidex(dashboard.getTemperature(), dashboard.getHumidity()));
|
||||||
return new DecimalType(humidex(dashboard.getTemperature(), dashboard.getHumidity()));
|
case CHANNEL_HUMIDEX_SCALE ->
|
||||||
case CHANNEL_HUMIDEX_SCALE:
|
new DecimalType(humidexScale(humidex(dashboard.getTemperature(), dashboard.getHumidity())));
|
||||||
return new DecimalType(humidexScale(humidex(dashboard.getTemperature(), dashboard.getHumidity())));
|
case CHANNEL_VALUE -> toQuantityType(dashboard.getHumidity(), MeasureClass.HUMIDITY);
|
||||||
case CHANNEL_VALUE:
|
default -> null;
|
||||||
return toQuantityType(dashboard.getHumidity(), MeasureClass.HUMIDITY);
|
};
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.Measure;
|
|||||||
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
|
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
|
||||||
import org.openhab.core.io.net.http.HttpUtil;
|
import org.openhab.core.io.net.http.HttpUtil;
|
||||||
import org.openhab.core.library.types.DateTimeType;
|
import org.openhab.core.library.types.DateTimeType;
|
||||||
import org.openhab.core.library.types.DecimalType;
|
|
||||||
import org.openhab.core.library.types.QuantityType;
|
import org.openhab.core.library.types.QuantityType;
|
||||||
import org.openhab.core.library.types.RawType;
|
import org.openhab.core.library.types.RawType;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
@@ -75,16 +74,12 @@ public class ChannelTypeUtils {
|
|||||||
return zonedDateTime.map(zdt -> (State) new DateTimeType(zdt)).orElse(UnDefType.NULL);
|
return zonedDateTime.map(zdt -> (State) new DateTimeType(zdt)).orElse(UnDefType.NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static State toQuantityType(@Nullable Double value, @Nullable MeasureClass measureClass) {
|
public static State toQuantityType(@Nullable Double value, MeasureClass measureClass) {
|
||||||
if (value != null && !value.isNaN()) {
|
if (value != null && !value.isNaN()) {
|
||||||
if (measureClass != null) {
|
|
||||||
Measure measureDef = measureClass.measureDefinition;
|
Measure measureDef = measureClass.measureDefinition;
|
||||||
BigDecimal measure = new BigDecimal(Math.min(measureDef.maxValue, Math.max(measureDef.minValue, value)))
|
BigDecimal measure = new BigDecimal(Math.min(measureDef.maxValue, Math.max(measureDef.minValue, value)))
|
||||||
.setScale(measureDef.scale, RoundingMode.HALF_UP);
|
.setScale(measureDef.scale, RoundingMode.HALF_UP);
|
||||||
return new QuantityType<>(measure, measureDef.unit);
|
return new QuantityType<>(measure, measureDef.unit);
|
||||||
} else {
|
|
||||||
return new DecimalType(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return UnDefType.NULL;
|
return UnDefType.NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user