Use renamed Units class (#9267)

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2020-12-07 10:34:02 +01:00
committed by GitHub
parent d0480d0f2e
commit ac6f08908f
208 changed files with 1087 additions and 1169 deletions

View File

@@ -25,7 +25,7 @@ import javax.measure.quantity.Temperature;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.types.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,7 +57,7 @@ public class Util {
Double saturationVaporPressure = 611.2 * Math.exp(17.62 * theta / (243.12 + theta));
// absolute humidity in kg/m^3
Double aH = relativeHumidity.doubleValue() / 100 * saturationVaporPressure / (461.52 * (273.15 + theta));
State absoluteHumidity = new QuantityType<>(aH, SmartHomeUnits.KILOGRAM_PER_CUBICMETRE).toUnit("g/m³");
State absoluteHumidity = new QuantityType<>(aH, Units.KILOGRAM_PER_CUBICMETRE).toUnit("g/m³");
if (absoluteHumidity != null) {
return absoluteHumidity;
} else {

View File

@@ -31,7 +31,7 @@ import org.openhab.binding.onewire.internal.owserver.OwserverDeviceParameter;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command;
@@ -241,8 +241,7 @@ public class BAE0910 extends AbstractOwDevice {
// Analog
if (enabledChannels.contains(CHANNEL_VOLTAGE)) {
State analogValue = bridgeHandler.readDecimalType(sensorId, pin7AnalogParameter);
callback.postUpdate(CHANNEL_VOLTAGE,
new QuantityType<>((DecimalType) analogValue, SmartHomeUnits.VOLT));
callback.postUpdate(CHANNEL_VOLTAGE, new QuantityType<>((DecimalType) analogValue, Units.VOLT));
}
// PWM
@@ -251,32 +250,32 @@ public class BAE0910 extends AbstractOwDevice {
if (enabledChannels.contains(CHANNEL_PWM_FREQ1)) {
period1 = ((DecimalType) bridgeHandler.readDecimalType(sensorId, period1Parameter)).intValue();
double frequency = (period1 > 0) ? 1 / (period1 * resolution1 * 1e-6) : 0;
callback.postUpdate(CHANNEL_PWM_FREQ1, new QuantityType<>(frequency, SmartHomeUnits.HERTZ));
callback.postUpdate(CHANNEL_PWM_FREQ1, new QuantityType<>(frequency, Units.HERTZ));
}
if (enabledChannels.contains(CHANNEL_PWM_FREQ2)) {
period2 = ((DecimalType) bridgeHandler.readDecimalType(sensorId, period2Parameter)).intValue();
double frequency = (period2 > 0) ? 1 / (period2 * resolution2 * 1e-6) : 0;
callback.postUpdate(CHANNEL_PWM_FREQ2, new QuantityType<>(frequency, SmartHomeUnits.HERTZ));
callback.postUpdate(CHANNEL_PWM_FREQ2, new QuantityType<>(frequency, Units.HERTZ));
}
if (enabledChannels.contains(CHANNEL_PWM_DUTY1)) {
int dutyValue = ((DecimalType) bridgeHandler.readDecimalType(sensorId, duty1Parameter)).intValue();
double duty = (period1 > 0 && dutyValue <= period1) ? 100 * dutyValue / period1 : 100;
callback.postUpdate(CHANNEL_PWM_DUTY1, new QuantityType<>(duty, SmartHomeUnits.PERCENT));
callback.postUpdate(CHANNEL_PWM_DUTY1, new QuantityType<>(duty, Units.PERCENT));
}
if (enabledChannels.contains(CHANNEL_PWM_DUTY2)) {
int dutyValue = ((DecimalType) bridgeHandler.readDecimalType(sensorId, duty2Parameter)).intValue();
double duty = (period2 > 0 && dutyValue <= period2) ? 100 * dutyValue / period2 : 100;
callback.postUpdate(CHANNEL_PWM_DUTY2, new QuantityType<>(duty, SmartHomeUnits.PERCENT));
callback.postUpdate(CHANNEL_PWM_DUTY2, new QuantityType<>(duty, Units.PERCENT));
}
if (enabledChannels.contains(CHANNEL_PWM_DUTY3)) {
int dutyValue = ((DecimalType) bridgeHandler.readDecimalType(sensorId, duty3Parameter)).intValue();
double duty = (period1 > 0 && dutyValue <= period1) ? 100 * dutyValue / period1 : 100;
callback.postUpdate(CHANNEL_PWM_DUTY3, new QuantityType<>(duty, SmartHomeUnits.PERCENT));
callback.postUpdate(CHANNEL_PWM_DUTY3, new QuantityType<>(duty, Units.PERCENT));
}
if (enabledChannels.contains(CHANNEL_PWM_DUTY4)) {
int dutyValue = ((DecimalType) bridgeHandler.readDecimalType(sensorId, duty4Parameter)).intValue();
double duty = (period2 > 0 && dutyValue <= period2) ? 100 * dutyValue / period2 : 100;
callback.postUpdate(CHANNEL_PWM_DUTY4, new QuantityType<>(duty, SmartHomeUnits.PERCENT));
callback.postUpdate(CHANNEL_PWM_DUTY4, new QuantityType<>(duty, Units.PERCENT));
}
}
}
@@ -382,7 +381,7 @@ public class BAE0910 extends AbstractOwDevice {
private DecimalType convertFrequencyToPeriod(Command command, double resolution) throws OwException {
@SuppressWarnings("unchecked")
QuantityType<Frequency> fHz = ((QuantityType<Frequency>) command).toUnit(SmartHomeUnits.HERTZ);
QuantityType<Frequency> fHz = ((QuantityType<Frequency>) command).toUnit(Units.HERTZ);
if (fHz == null) {
throw new OwException("could not convert command to frequency");
}

View File

@@ -27,7 +27,7 @@ import org.openhab.binding.onewire.internal.owserver.OwserverDeviceParameter;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,8 +66,7 @@ public class DS1923 extends AbstractOwDevice {
if (enabledChannels.contains(CHANNEL_HUMIDITY) || enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)
|| enabledChannels.contains(CHANNEL_DEWPOINT)) {
QuantityType<Dimensionless> humidity = new QuantityType<>(
(DecimalType) bridgeHandler.readDecimalType(sensorId, humidityParameter),
SmartHomeUnits.PERCENT);
(DecimalType) bridgeHandler.readDecimalType(sensorId, humidityParameter), Units.PERCENT);
if (enabledChannels.contains(CHANNEL_HUMIDITY)) {
callback.postUpdate(CHANNEL_HUMIDITY, humidity);

View File

@@ -29,7 +29,7 @@ import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.State;
@@ -107,8 +107,7 @@ public class DS2438 extends AbstractOwDevice {
if (enabledChannels.contains(CHANNEL_HUMIDITY) || enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)
|| enabledChannels.contains(CHANNEL_DEWPOINT)) {
QuantityType<Dimensionless> humidity = new QuantityType<>(
(DecimalType) bridgeHandler.readDecimalType(sensorId, humidityParameter),
SmartHomeUnits.PERCENT);
(DecimalType) bridgeHandler.readDecimalType(sensorId, humidityParameter), Units.PERCENT);
logger.trace("read humidity {} from {}", humidity, sensorId);
if (enabledChannels.contains(CHANNEL_HUMIDITY)) {
@@ -133,7 +132,7 @@ public class DS2438 extends AbstractOwDevice {
// workaround bug in DS2438
measured = 0.0;
}
State voltage = new QuantityType<>(measured, SmartHomeUnits.VOLT);
State voltage = new QuantityType<>(measured, Units.VOLT);
logger.trace("read voltage {} from {}", voltage, sensorId);
callback.postUpdate(CHANNEL_VOLTAGE, voltage);
@@ -145,7 +144,7 @@ public class DS2438 extends AbstractOwDevice {
if (current instanceof DecimalType) {
double currentDouble = ((DecimalType) current).doubleValue();
if (currentDouble >= 0.1 || currentDouble <= 3.78) {
current = new QuantityType<>(currentDouble * 5.163 + 0.483, SmartHomeUnits.AMPERE);
current = new QuantityType<>(currentDouble * 5.163 + 0.483, Units.AMPERE);
}
callback.postUpdate(CHANNEL_CURRENT, current);
} else {
@@ -154,14 +153,14 @@ public class DS2438 extends AbstractOwDevice {
} else {
State current = new QuantityType<>(
(DecimalType) bridgeHandler.readDecimalType(sensorId, currentParamater),
MILLI(SmartHomeUnits.AMPERE));
MILLI(Units.AMPERE));
callback.postUpdate(CHANNEL_CURRENT, current);
}
}
if (enabledChannels.contains(CHANNEL_SUPPLYVOLTAGE)) {
Vcc = ((DecimalType) bridgeHandler.readDecimalType(sensorId, supplyVoltageParameter)).doubleValue();
State supplyVoltage = new QuantityType<>(Vcc, SmartHomeUnits.VOLT);
State supplyVoltage = new QuantityType<>(Vcc, Units.VOLT);
callback.postUpdate(CHANNEL_SUPPLYVOLTAGE, supplyVoltage);
}
@@ -172,7 +171,7 @@ public class DS2438 extends AbstractOwDevice {
if (light instanceof DecimalType) {
light = new QuantityType<>(
Math.round(Math.pow(10, ((DecimalType) light).doubleValue() / 47 * 1000)),
SmartHomeUnits.LUX);
Units.LUX);
callback.postUpdate(CHANNEL_LIGHT, light);
}
break;
@@ -182,7 +181,7 @@ public class DS2438 extends AbstractOwDevice {
light = new QuantityType<>(Math.round(Math
.exp(1.059 * Math.log(1000000 * ((DecimalType) light).doubleValue() / (4096 * 390))
+ 4.518)
* 20000), SmartHomeUnits.LUX);
* 20000), Units.LUX);
callback.postUpdate(CHANNEL_LIGHT, light);
}
break;
@@ -191,10 +190,10 @@ public class DS2438 extends AbstractOwDevice {
.doubleValue();
if (measured <= 0 || measured > 10.0) {
// workaround bug in DS2438
light = new QuantityType<>(0, SmartHomeUnits.LUX);
light = new QuantityType<>(0, Units.LUX);
} else {
light = new QuantityType<>(Math.pow(10, (65 / 7.5) - (47 / 7.5) * (Vcc / measured)),
SmartHomeUnits.LUX);
Units.LUX);
}
callback.postUpdate(CHANNEL_LIGHT, light);
}

View File

@@ -30,7 +30,7 @@ import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,8 +79,7 @@ public class EDS006x extends AbstractOwDevice {
if (enabledChannels.contains(CHANNEL_HUMIDITY) || enabledChannels.contains(CHANNEL_ABSOLUTE_HUMIDITY)
|| enabledChannels.contains(CHANNEL_DEWPOINT)) {
QuantityType<Dimensionless> humidity = new QuantityType<>(
(DecimalType) bridgeHandler.readDecimalType(sensorId, humidityParameter),
SmartHomeUnits.PERCENT);
(DecimalType) bridgeHandler.readDecimalType(sensorId, humidityParameter), Units.PERCENT);
if (enabledChannels.contains(CHANNEL_HUMIDITY)) {
callback.postUpdate(CHANNEL_HUMIDITY, humidity);
@@ -99,7 +98,7 @@ public class EDS006x extends AbstractOwDevice {
if (enabledChannels.contains(CHANNEL_LIGHT)) {
QuantityType<Illuminance> light = new QuantityType<>(
(DecimalType) bridgeHandler.readDecimalType(sensorId, lightParameter), SmartHomeUnits.LUX);
(DecimalType) bridgeHandler.readDecimalType(sensorId, lightParameter), Units.LUX);
callback.postUpdate(CHANNEL_LIGHT, light);
}