From 13c2d7bf2be051fe8c72046d637770a92f517781 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sun, 6 Dec 2020 23:35:37 +0100 Subject: [PATCH] Rename classes with "SmartHome" in their name (#1896) * Rename SmartHomeUnits to Units * Rename SmartHome Servlets and HTTP Context Signed-off-by: Wouter Born --- .../core/audio/internal/AudioServlet.java | 4 +- .../DefaultScriptScopeProvider.java | 4 +- ...tpContext.java => OpenHABHttpContext.java} | 10 +- ...meServlet.java => BaseOpenHABServlet.java} | 6 +- ...Servlet.java => OpenHABBundleServlet.java} | 4 +- ...rtHomeServlet.java => OpenHABServlet.java} | 4 +- .../model/script/lib/NumberExtensions.java | 20 +-- .../ScriptImplicitlyImportedTypes.java | 4 +- .../SystemHysteresisStateProfile.java | 4 +- .../profiles/SystemOffsetProfile.java | 16 +- .../core/ui/icon/internal/IconServlet.java | 4 +- .../core/ui/internal/chart/ChartServlet.java | 4 +- .../core/internal/i18n/I18nProviderImpl.java | 14 +- .../library/unit/UnitInitializer.java | 4 +- .../core/library/types/PercentType.java | 4 +- .../core/library/types/QuantityType.java | 12 +- .../unit/{SmartHomeUnits.java => Units.java} | 144 +++++++++--------- .../openhab/core/types/util/UnitUtils.java | 7 +- .../dimension/VolumetricFlowRateTest.java | 16 +- .../core/library/types/PercentTypeTest.java | 4 +- .../core/library/types/QuantityTypeTest.java | 32 ++-- ...SmartHomeUnitsTest.java => UnitsTest.java} | 87 ++++++----- .../core/types/util/UnitUtilsTest.java | 25 ++- .../script/engine/ScriptEngineOSGiTest.java | 6 +- .../script/lib/NumberExtensionsTest.java | 6 +- 25 files changed, 222 insertions(+), 223 deletions(-) rename bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/internal/{SmartHomeHttpContext.java => OpenHABHttpContext.java} (88%) rename bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/{BaseSmartHomeServlet.java => BaseOpenHABServlet.java} (92%) rename bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/{SmartHomeBundleServlet.java => OpenHABBundleServlet.java} (88%) rename bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/{SmartHomeServlet.java => OpenHABServlet.java} (87%) rename bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/{SmartHomeUnits.java => Units.java} (74%) rename bundles/org.openhab.core/src/test/java/org/openhab/core/library/unit/{SmartHomeUnitsTest.java => UnitsTest.java} (79%) diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioServlet.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioServlet.java index 46e69b7175..bd88a9a6f9 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioServlet.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioServlet.java @@ -34,7 +34,7 @@ import org.openhab.core.audio.AudioFormat; import org.openhab.core.audio.AudioHTTPServer; import org.openhab.core.audio.AudioStream; import org.openhab.core.audio.FixedLengthAudioStream; -import org.openhab.core.io.http.servlet.SmartHomeServlet; +import org.openhab.core.io.http.servlet.OpenHABServlet; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @@ -49,7 +49,7 @@ import org.osgi.service.http.HttpService; */ @NonNullByDefault @Component -public class AudioServlet extends SmartHomeServlet implements AudioHTTPServer { +public class AudioServlet extends OpenHABServlet implements AudioHTTPServer { private static final long serialVersionUID = -3364664035854567854L; diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java index 0c465a1df0..d8cb973c78 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java @@ -50,7 +50,7 @@ import org.openhab.core.library.unit.BinaryPrefix; import org.openhab.core.library.unit.ImperialUnits; 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.openhab.core.thing.ThingRegistry; import org.openhab.core.thing.binding.ThingActions; import org.openhab.core.types.Command; @@ -150,7 +150,7 @@ public class DefaultScriptScopeProvider implements ScriptExtensionProvider { elements.put("SIUnits", SIUnits.class); elements.put("ImperialUnits", ImperialUnits.class); elements.put("MetricPrefix", MetricPrefix.class); - elements.put("SmartHomeUnits", SmartHomeUnits.class); + elements.put("Units", Units.class); elements.put("BinaryPrefix", BinaryPrefix.class); // services diff --git a/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/internal/SmartHomeHttpContext.java b/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/internal/OpenHABHttpContext.java similarity index 88% rename from bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/internal/SmartHomeHttpContext.java rename to bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/internal/OpenHABHttpContext.java index 0533219cd9..35600b062d 100644 --- a/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/internal/SmartHomeHttpContext.java +++ b/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/internal/OpenHABHttpContext.java @@ -33,17 +33,17 @@ import org.osgi.service.component.annotations.ReferencePolicy; import org.osgi.service.http.HttpContext; /** - * Default http context implementation which groups all Smart Home related http elements into one logical application. + * Default HTTP context implementation which groups all openHAB related HTTP elements into one logical application. * - * Additionally to standard http context, this one provides its own implementation of - * {@link #handleSecurity(HttpServletRequest, HttpServletResponse)} method which is based on injected list of generic - * handlers. + * Additionally to the standard HTTP context, this class provides its own implementation of the + * {@link #handleSecurity(HttpServletRequest, HttpServletResponse)} method which is based on the injected list of + * {@link Handler}s. * * @author Łukasz Dywicki - Initial contribution */ @Component(service = { HttpContext.class, WrappingHttpContext.class }, property = { "httpContext.id:String=oh-dfl-http-ctx" }) -public class SmartHomeHttpContext implements WrappingHttpContext { +public class OpenHABHttpContext implements WrappingHttpContext { /** * Sorted list of handlers, where handler with priority 0 is first. diff --git a/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/BaseSmartHomeServlet.java b/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/BaseOpenHABServlet.java similarity index 92% rename from bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/BaseSmartHomeServlet.java rename to bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/BaseOpenHABServlet.java index fd7afb8598..c106b8f870 100644 --- a/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/BaseSmartHomeServlet.java +++ b/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/BaseOpenHABServlet.java @@ -30,21 +30,21 @@ import org.slf4j.LoggerFactory; * @author Łukasz Dywicki - Initial contribution */ @NonNullByDefault -public abstract class BaseSmartHomeServlet extends HttpServlet { +public abstract class BaseOpenHABServlet extends HttpServlet { private static final long serialVersionUID = 6020752826735599455L; /** * Logger bound to child class. */ - protected final Logger logger = LoggerFactory.getLogger(BaseSmartHomeServlet.class); + protected final Logger logger = LoggerFactory.getLogger(BaseOpenHABServlet.class); /** * Http service. */ protected final HttpService httpService; - public BaseSmartHomeServlet(HttpService httpService) { + public BaseOpenHABServlet(HttpService httpService) { this.httpService = httpService; } diff --git a/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/SmartHomeBundleServlet.java b/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/OpenHABBundleServlet.java similarity index 88% rename from bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/SmartHomeBundleServlet.java rename to bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/OpenHABBundleServlet.java index d3dd8d734f..b9a5ca1c37 100644 --- a/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/SmartHomeBundleServlet.java +++ b/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/OpenHABBundleServlet.java @@ -25,11 +25,11 @@ import org.osgi.service.http.HttpService; * @author Łukasz Dywicki - Initial contribution */ @NonNullByDefault -public abstract class SmartHomeBundleServlet extends BaseSmartHomeServlet { +public abstract class OpenHABBundleServlet extends BaseOpenHABServlet { protected final HttpContextFactoryService httpContextFactoryService; - public SmartHomeBundleServlet(HttpService httpService, HttpContextFactoryService httpContextFactoryService) { + public OpenHABBundleServlet(HttpService httpService, HttpContextFactoryService httpContextFactoryService) { super(httpService); this.httpContextFactoryService = httpContextFactoryService; } diff --git a/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/SmartHomeServlet.java b/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/OpenHABServlet.java similarity index 87% rename from bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/SmartHomeServlet.java rename to bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/OpenHABServlet.java index e1abb055bc..a0317216f1 100644 --- a/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/SmartHomeServlet.java +++ b/bundles/org.openhab.core.io.http/src/main/java/org/openhab/core/io/http/servlet/OpenHABServlet.java @@ -22,7 +22,7 @@ import org.osgi.service.http.HttpService; * @author Łukasz Dywicki - Initial contribution */ @NonNullByDefault -public abstract class SmartHomeServlet extends BaseSmartHomeServlet { +public abstract class OpenHABServlet extends BaseOpenHABServlet { private static final long serialVersionUID = 6854521240046714164L; @@ -31,7 +31,7 @@ public abstract class SmartHomeServlet extends BaseSmartHomeServlet { */ protected final HttpContext httpContext; - public SmartHomeServlet(HttpService httpService, HttpContext httpContext) { + public OpenHABServlet(HttpService httpService, HttpContext httpContext) { super(httpService); this.httpContext = httpContext; } diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/lib/NumberExtensions.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/lib/NumberExtensions.java index ac64c442c6..60cd3f42e3 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/lib/NumberExtensions.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/lib/NumberExtensions.java @@ -19,7 +19,7 @@ import javax.measure.quantity.Dimensionless; import org.openhab.core.library.types.DecimalType; 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.types.Type; /** @@ -95,7 +95,7 @@ public class NumberExtensions { public static boolean operator_equals(Number left, Number right) { // in case one of the Number instances is of type QuantityType they are never equal (except for - // SmartHomeUnit.ONE). + // Units.ONE). // for both instances being QuantityTypes the specific method // operator_equals(QuantityType left, QuantityType right) is called by the script engine. if (oneIsQuantity(left, right)) { @@ -282,7 +282,7 @@ public class NumberExtensions { } public static QuantityType operator_divide(Number x, QuantityType y) { - QuantityType xQuantity = new QuantityType<>(x, SmartHomeUnits.ONE); + QuantityType xQuantity = new QuantityType<>(x, Units.ONE); return operator_divide(xQuantity, y); } @@ -294,7 +294,7 @@ public class NumberExtensions { return left.equals(right); } - // support SmartHomeUnit.ONE as Number representation + // support Units.ONE as Number representation public static boolean operator_equals(QuantityType left, Number right) { return operator_equals((Number) left, right); } @@ -303,7 +303,7 @@ public class NumberExtensions { return !operator_equals(left, right); } - // support SmartHomeUnit.ONE as Number representation + // support Units.ONE as Number representation public static boolean operator_notEquals(QuantityType left, Number right) { return operator_notEquals((Number) left, right); } @@ -317,7 +317,7 @@ public class NumberExtensions { } } - // support SmartHomeUnit.ONE as Number representation + // support Units.ONE as Number representation public static boolean operator_lessThan(QuantityType x, Number y) { return operator_lessThan((Number) x, y); } @@ -331,7 +331,7 @@ public class NumberExtensions { } } - // support SmartHomeUnit.ONE as Number representation + // support Units.ONE as Number representation public static boolean operator_lessEqualsThan(QuantityType x, Number y) { return operator_lessEqualsThan((Number) x, y); } @@ -345,7 +345,7 @@ public class NumberExtensions { } } - // support SmartHomeUnit.ONE as Number representation + // support Units.ONE as Number representation public static boolean operator_greaterThan(QuantityType x, Number y) { return operator_greaterThan((Number) x, y); } @@ -359,7 +359,7 @@ public class NumberExtensions { } } - // support SmartHomeUnit.ONE as Number representation + // support Units.ONE as Number representation public static boolean operator_greaterEqualsThan(QuantityType x, Number y) { return operator_greaterEqualsThan((Number) x, y); } @@ -393,7 +393,7 @@ public class NumberExtensions { } private static boolean isAbstractUnitOne(QuantityType left) { - return SmartHomeUnits.ONE.equals(left.getUnit()); + return Units.ONE.equals(left.getUnit()); } } diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/scoping/ScriptImplicitlyImportedTypes.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/scoping/ScriptImplicitlyImportedTypes.java index f9db5a9d2a..3874be3157 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/scoping/ScriptImplicitlyImportedTypes.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/scoping/ScriptImplicitlyImportedTypes.java @@ -24,7 +24,7 @@ import org.openhab.core.library.unit.BinaryPrefix; import org.openhab.core.library.unit.ImperialUnits; 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.openhab.core.model.script.actions.BusEvent; import org.openhab.core.model.script.actions.Exec; import org.openhab.core.model.script.actions.HTTP; @@ -96,7 +96,7 @@ public class ScriptImplicitlyImportedTypes extends ImplicitlyImportedFeatures { result.add(ImperialUnits.class); result.add(MetricPrefix.class); result.add(SIUnits.class); - result.add(SmartHomeUnits.class); + result.add(Units.class); result.add(BinaryPrefix.class); // date time static functions diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemHysteresisStateProfile.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemHysteresisStateProfile.java index ccced52431..0bd6bab48d 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemHysteresisStateProfile.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemHysteresisStateProfile.java @@ -19,7 +19,7 @@ import org.eclipse.jdt.annotation.Nullable; 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.profiles.ProfileCallback; import org.openhab.core.thing.profiles.ProfileContext; import org.openhab.core.thing.profiles.ProfileTypeUID; @@ -134,7 +134,7 @@ public class SystemHysteresisStateProfile implements StateProfile { final QuantityType qtState = (QuantityType) value; final QuantityType finalLower; final QuantityType finalUpper; - if (lower.getUnit() == SmartHomeUnits.ONE && upper.getUnit() == SmartHomeUnits.ONE) { + if (lower.getUnit() == Units.ONE && upper.getUnit() == Units.ONE) { // allow bounds without unit -> implicitly assume its the same as the one from the state, but warn // the user finalLower = new QuantityType<>(lower.toBigDecimal(), qtState.getUnit()); diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfile.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfile.java index 41ab5fa51b..1635053e21 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfile.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfile.java @@ -23,7 +23,7 @@ import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.ImperialUnits; 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.profiles.ProfileCallback; import org.openhab.core.thing.profiles.ProfileContext; import org.openhab.core.thing.profiles.ProfileTypeUID; @@ -45,9 +45,9 @@ import org.slf4j.LoggerFactory; public class SystemOffsetProfile implements StateProfile { private static final @Nullable QuantityType ZERO_CELSIUS_IN_KELVIN = new QuantityType<>(0, - SIUnits.CELSIUS).toUnit(SmartHomeUnits.KELVIN); + SIUnits.CELSIUS).toUnit(Units.KELVIN); private static final @Nullable QuantityType ZERO_FAHRENHEIT_IN_KELVIN = new QuantityType<>(0, - ImperialUnits.FAHRENHEIT).toUnit(SmartHomeUnits.KELVIN); + ImperialUnits.FAHRENHEIT).toUnit(Units.KELVIN); static final String OFFSET_PARAM = "offset"; private final Logger logger = LoggerFactory.getLogger(SystemOffsetProfile.class); @@ -115,7 +115,7 @@ public class SystemOffsetProfile implements StateProfile { if (state instanceof QuantityType) { QuantityType qtState = (QuantityType) state; try { - if (finalOffset.getUnit() == SmartHomeUnits.ONE) { + if (finalOffset.getUnit() == Units.ONE) { // allow offsets without unit -> implicitly assume its the same as the one from the state, but warn // the user finalOffset = new QuantityType<>(finalOffset.toBigDecimal(), qtState.getUnit()); @@ -124,7 +124,7 @@ public class SystemOffsetProfile implements StateProfile { state, offset); } // take care of temperatures because they start at offset -273°C = 0K - if (SmartHomeUnits.KELVIN.equals(qtState.getUnit().getSystemUnit())) { + if (Units.KELVIN.equals(qtState.getUnit().getSystemUnit())) { QuantityType tmp = handleTemperature(qtState, finalOffset); if (tmp != null) { result = tmp; @@ -135,7 +135,7 @@ public class SystemOffsetProfile implements StateProfile { } catch (UnconvertibleException e) { logger.warn("Cannot apply offset '{}' to state '{}' because types do not match.", finalOffset, qtState); } - } else if (state instanceof DecimalType && finalOffset.getUnit() == SmartHomeUnits.ONE) { + } else if (state instanceof DecimalType && finalOffset.getUnit() == Units.ONE) { DecimalType decState = (DecimalType) state; result = new DecimalType(decState.toBigDecimal().add(finalOffset.toBigDecimal())); } else { @@ -150,8 +150,8 @@ public class SystemOffsetProfile implements StateProfile { private @Nullable QuantityType handleTemperature(QuantityType qtState, QuantityType offset) { // do the math in Kelvin and afterwards convert it back to the unit of the state - final QuantityType kelvinState = qtState.toUnit(SmartHomeUnits.KELVIN); - final QuantityType kelvinOffset = offset.toUnit(SmartHomeUnits.KELVIN); + final QuantityType kelvinState = qtState.toUnit(Units.KELVIN); + final QuantityType kelvinOffset = offset.toUnit(Units.KELVIN); if (kelvinState == null || kelvinOffset == null) { return null; } diff --git a/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/IconServlet.java b/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/IconServlet.java index c9aeb29c9e..e09396b043 100644 --- a/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/IconServlet.java +++ b/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/IconServlet.java @@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.io.http.servlet.SmartHomeServlet; +import org.openhab.core.io.http.servlet.OpenHABServlet; import org.openhab.core.ui.icon.IconProvider; import org.openhab.core.ui.icon.IconSet.Format; import org.osgi.service.component.annotations.Activate; @@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory; */ @Component @NonNullByDefault -public class IconServlet extends SmartHomeServlet { +public class IconServlet extends OpenHABServlet { private static final long serialVersionUID = 2880642275858634578L; diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/ChartServlet.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/ChartServlet.java index 3b46d73b3d..84d2740b76 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/ChartServlet.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/ChartServlet.java @@ -33,7 +33,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.openhab.core.config.core.ConfigurableService; -import org.openhab.core.io.http.servlet.SmartHomeServlet; +import org.openhab.core.io.http.servlet.OpenHABServlet; import org.openhab.core.items.ItemNotFoundException; import org.openhab.core.ui.chart.ChartProvider; import org.osgi.framework.Constants; @@ -68,7 +68,7 @@ import org.osgi.service.http.HttpService; @Component(immediate = true, service = ChartServlet.class, configurationPid = "org.openhab.chart", // property = Constants.SERVICE_PID + "=org.openhab.chart") @ConfigurableService(category = "system", label = "Charts", description_uri = ChartServlet.CONFIG_URI) -public class ChartServlet extends SmartHomeServlet { +public class ChartServlet extends OpenHABServlet { private static final long serialVersionUID = 7700873790924746422L; diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java index 7ace5b4d2c..50b26f01ba 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java @@ -44,7 +44,7 @@ import org.openhab.core.library.dimension.Intensity; import org.openhab.core.library.types.PointType; import org.openhab.core.library.unit.ImperialUnits; import org.openhab.core.library.unit.SIUnits; -import org.openhab.core.library.unit.SmartHomeUnits; +import org.openhab.core.library.unit.Units; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.osgi.service.component.ComponentContext; @@ -364,18 +364,18 @@ public class I18nProviderImpl dimensionMap.put(Length.class, lengthMap); Map>> intensityMap = new HashMap<>(); - intensityMap.put(SIUnits.getInstance(), SmartHomeUnits.IRRADIANCE); - intensityMap.put(ImperialUnits.getInstance(), SmartHomeUnits.IRRADIANCE); + intensityMap.put(SIUnits.getInstance(), Units.IRRADIANCE); + intensityMap.put(ImperialUnits.getInstance(), Units.IRRADIANCE); dimensionMap.put(Intensity.class, intensityMap); Map>> percentMap = new HashMap<>(); - percentMap.put(SIUnits.getInstance(), SmartHomeUnits.ONE); - percentMap.put(ImperialUnits.getInstance(), SmartHomeUnits.ONE); + percentMap.put(SIUnits.getInstance(), Units.ONE); + percentMap.put(ImperialUnits.getInstance(), Units.ONE); dimensionMap.put(Dimensionless.class, percentMap); Map>> angleMap = new HashMap<>(); - angleMap.put(SIUnits.getInstance(), SmartHomeUnits.DEGREE_ANGLE); - angleMap.put(ImperialUnits.getInstance(), SmartHomeUnits.DEGREE_ANGLE); + angleMap.put(SIUnits.getInstance(), Units.DEGREE_ANGLE); + angleMap.put(ImperialUnits.getInstance(), Units.DEGREE_ANGLE); dimensionMap.put(Angle.class, angleMap); } } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/library/unit/UnitInitializer.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/library/unit/UnitInitializer.java index 2920533a7e..ba61a080dc 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/library/unit/UnitInitializer.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/library/unit/UnitInitializer.java @@ -14,7 +14,7 @@ package org.openhab.core.internal.library.unit; import org.openhab.core.library.unit.ImperialUnits; import org.openhab.core.library.unit.SIUnits; -import org.openhab.core.library.unit.SmartHomeUnits; +import org.openhab.core.library.unit.Units; /** * Make sure static blocks from {@link SIUnits} & {@link ImperialUnits} are executed to initialize the unit parser. @@ -24,7 +24,7 @@ import org.openhab.core.library.unit.SmartHomeUnits; public class UnitInitializer { static { - SmartHomeUnits.getInstance(); + Units.getInstance(); SIUnits.getInstance(); ImperialUnits.getInstance(); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PercentType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PercentType.java index ff6c2212f4..96f107ff0c 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PercentType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PercentType.java @@ -17,7 +17,7 @@ import java.math.RoundingMode; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.library.unit.SmartHomeUnits; +import org.openhab.core.library.unit.Units; import org.openhab.core.types.State; /** @@ -87,7 +87,7 @@ public class PercentType extends DecimalType { } else if (target == HSBType.class) { return target.cast(new HSBType(DecimalType.ZERO, PercentType.ZERO, this)); } else if (target == QuantityType.class) { - return target.cast(new QuantityType<>(toBigDecimal().doubleValue(), SmartHomeUnits.PERCENT)); + return target.cast(new QuantityType<>(toBigDecimal().doubleValue(), Units.PERCENT)); } else { return defaultConversion(target); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java index e6a732750a..052b12daee 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java @@ -33,7 +33,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.internal.library.unit.UnitInitializer; import org.openhab.core.library.unit.MetricPrefix; -import org.openhab.core.library.unit.SmartHomeUnits; +import org.openhab.core.library.unit.Units; import org.openhab.core.types.Command; import org.openhab.core.types.PrimitiveType; import org.openhab.core.types.State; @@ -238,15 +238,15 @@ public class QuantityType> extends Number final String formatPattern; if (unitPlaceholder) { - String unitSymbol = getUnit().equals(SmartHomeUnits.PERCENT) ? "%%" : getUnit().toString(); + String unitSymbol = getUnit().equals(Units.PERCENT) ? "%%" : getUnit().toString(); formatPattern = pattern.replace(UnitUtils.UNIT_PLACEHOLDER, unitSymbol); } else { formatPattern = pattern; } // The dimension could be a time value thus we want to support patterns to format datetime - if (quantity.getUnit().isCompatible(SmartHomeUnits.SECOND) && !unitPlaceholder) { - QuantityType millis = toUnit(MetricPrefix.MILLI(SmartHomeUnits.SECOND)); + if (quantity.getUnit().isCompatible(Units.SECOND) && !unitPlaceholder) { + QuantityType millis = toUnit(MetricPrefix.MILLI(Units.SECOND)); if (millis != null) { try { return String.format(formatPattern, @@ -309,7 +309,7 @@ public class QuantityType> extends Number if (target == OnOffType.class) { if (intValue() == 0) { return target.cast(OnOffType.OFF); - } else if (SmartHomeUnits.PERCENT.equals(getUnit())) { + } else if (Units.PERCENT.equals(getUnit())) { return target.cast(toBigDecimal().compareTo(BigDecimal.ZERO) > 0 ? OnOffType.ON : OnOffType.OFF); } else if (toBigDecimal().compareTo(BigDecimal.ONE) == 0) { return target.cast(OnOffType.ON); @@ -336,7 +336,7 @@ public class QuantityType> extends Number return target.cast( new HSBType(DecimalType.ZERO, PercentType.ZERO, new PercentType(toBigDecimal().multiply(HUNDRED)))); } else if (target == PercentType.class) { - if (SmartHomeUnits.PERCENT.equals(getUnit())) { + if (Units.PERCENT.equals(getUnit())) { return target.cast(new PercentType(toBigDecimal())); } return target.cast(new PercentType(toBigDecimal().multiply(HUNDRED))); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/SmartHomeUnits.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java similarity index 74% rename from bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/SmartHomeUnits.java rename to bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java index 4627f5656b..97692626f4 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/SmartHomeUnits.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/Units.java @@ -67,7 +67,6 @@ import tec.uom.se.function.RationalConverter; import tec.uom.se.unit.AlternateUnit; import tec.uom.se.unit.ProductUnit; import tec.uom.se.unit.TransformedUnit; -import tec.uom.se.unit.Units; /** * Delegate common units to {@link Units} to hide this dependency from the rest of openHAB. @@ -77,108 +76,115 @@ import tec.uom.se.unit.Units; * @author Henning Treu - Initial contribution */ @NonNullByDefault -public final class SmartHomeUnits extends CustomUnits { +public final class Units extends CustomUnits { - private static final SmartHomeUnits INSTANCE = new SmartHomeUnits(); + private static final Units INSTANCE = new Units(); // Alphabetical ordered by Unit. - public static final Unit METRE_PER_SQUARE_SECOND = addUnit(Units.METRE_PER_SQUARE_SECOND); + public static final Unit METRE_PER_SQUARE_SECOND = addUnit( + tec.uom.se.unit.Units.METRE_PER_SQUARE_SECOND); public static final Unit STANDARD_GRAVITY = addUnit(METRE_PER_SQUARE_SECOND.multiply(9.80665)); - public static final Unit MOLE = addUnit(Units.MOLE); + public static final Unit MOLE = addUnit(tec.uom.se.unit.Units.MOLE); @SuppressWarnings("unchecked") public static final Unit DEUTSCHE_HAERTE = addUnit( - new TransformedUnit<>("°dH", (Unit) MetricPrefix.MILLI(Units.MOLE).divide(Units.LITRE), - RationalConverter.of(5.6, 1))); - public static final Unit DEGREE_ANGLE = addUnit(new TransformedUnit<>(Units.RADIAN, + new TransformedUnit<>("°dH", (Unit) MetricPrefix.MILLI(tec.uom.se.unit.Units.MOLE) + .divide(tec.uom.se.unit.Units.LITRE), RationalConverter.of(5.6, 1))); + public static final Unit DEGREE_ANGLE = addUnit(new TransformedUnit<>(tec.uom.se.unit.Units.RADIAN, new PiMultiplierConverter().concatenate(new RationalConverter(BigInteger.ONE, BigInteger.valueOf(180))))); - public static final Unit RADIAN = addUnit(Units.RADIAN); - public static final Unit DOBSON_UNIT = addUnit( - new ProductUnit(MetricPrefix.MILLI(Units.MOLE).multiply(0.4462).divide(Units.SQUARE_METRE))); - public static final Unit KATAL = addUnit(Units.KATAL); + public static final Unit RADIAN = addUnit(tec.uom.se.unit.Units.RADIAN); + public static final Unit DOBSON_UNIT = addUnit(new ProductUnit(MetricPrefix + .MILLI(tec.uom.se.unit.Units.MOLE).multiply(0.4462).divide(tec.uom.se.unit.Units.SQUARE_METRE))); + public static final Unit KATAL = addUnit(tec.uom.se.unit.Units.KATAL); public static final Unit KILOGRAM_PER_CUBICMETRE = addUnit( - new ProductUnit(Units.KILOGRAM.divide(Units.CUBIC_METRE))); + new ProductUnit(tec.uom.se.unit.Units.KILOGRAM.divide(tec.uom.se.unit.Units.CUBIC_METRE))); public static final Unit MICROGRAM_PER_CUBICMETRE = addUnit(new TransformedUnit<>(KILOGRAM_PER_CUBICMETRE, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000000)))); public static final Unit ONE = addUnit(AbstractUnit.ONE); - public static final Unit PERCENT = addUnit(Units.PERCENT); + public static final Unit PERCENT = addUnit(tec.uom.se.unit.Units.PERCENT); public static final Unit PARTS_PER_BILLION = addUnit( new TransformedUnit<>(ONE, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000000)))); public static final Unit PARTS_PER_MILLION = addUnit( new TransformedUnit<>(ONE, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000)))); public static final Unit DECIBEL = addUnit(ONE.transform( new LogConverter(10).inverse().concatenate(new RationalConverter(BigInteger.ONE, BigInteger.TEN)))); - public static final Unit AMPERE = addUnit(Units.AMPERE); - public static final Unit FARAD = addUnit(Units.FARAD); - public static final Unit COULOMB = addUnit(Units.COULOMB); - public static final Unit AMPERE_HOUR = addUnit(Units.COULOMB.multiply(3600)); + public static final Unit AMPERE = addUnit(tec.uom.se.unit.Units.AMPERE); + public static final Unit FARAD = addUnit(tec.uom.se.unit.Units.FARAD); + public static final Unit COULOMB = addUnit(tec.uom.se.unit.Units.COULOMB); + public static final Unit AMPERE_HOUR = addUnit(tec.uom.se.unit.Units.COULOMB.multiply(3600)); public static final Unit MILLIAMPERE_HOUR = addUnit(MetricPrefix.MILLI(AMPERE_HOUR)); - public static final Unit SIEMENS = addUnit(Units.SIEMENS); + public static final Unit SIEMENS = addUnit(tec.uom.se.unit.Units.SIEMENS); public static final Unit SIEMENS_PER_METRE = addUnit( - new ProductUnit(Units.SIEMENS.divide(Units.METRE))); - public static final Unit HENRY = addUnit(Units.HENRY); - public static final Unit VOLT = addUnit(Units.VOLT); - public static final Unit OHM = addUnit(Units.OHM); - public static final Unit JOULE = addUnit(Units.JOULE); - public static final Unit WATT_SECOND = addUnit(new ProductUnit<>(Units.WATT.multiply(Units.SECOND))); - public static final Unit WATT_HOUR = addUnit(new ProductUnit<>(Units.WATT.multiply(Units.HOUR))); + new ProductUnit(tec.uom.se.unit.Units.SIEMENS.divide(tec.uom.se.unit.Units.METRE))); + public static final Unit HENRY = addUnit(tec.uom.se.unit.Units.HENRY); + public static final Unit VOLT = addUnit(tec.uom.se.unit.Units.VOLT); + public static final Unit OHM = addUnit(tec.uom.se.unit.Units.OHM); + public static final Unit JOULE = addUnit(tec.uom.se.unit.Units.JOULE); + public static final Unit WATT_SECOND = addUnit( + new ProductUnit<>(tec.uom.se.unit.Units.WATT.multiply(tec.uom.se.unit.Units.SECOND))); + public static final Unit WATT_HOUR = addUnit( + new ProductUnit<>(tec.uom.se.unit.Units.WATT.multiply(tec.uom.se.unit.Units.HOUR))); public static final Unit KILOWATT_HOUR = addUnit(MetricPrefix.KILO(WATT_HOUR)); public static final Unit MEGAWATT_HOUR = addUnit(MetricPrefix.MEGA(WATT_HOUR)); - public static final Unit VAR = addUnit(new AlternateUnit<>(Units.WATT, "var")); + public static final Unit VAR = addUnit(new AlternateUnit<>(tec.uom.se.unit.Units.WATT, "var")); public static final Unit KILOVAR = addUnit(MetricPrefix.KILO(VAR)); - public static final Unit VAR_HOUR = addUnit(new ProductUnit<>(VAR.multiply(Units.HOUR)), Energy.class); - public static final Unit KILOVAR_HOUR = addUnit(MetricPrefix.KILO(VAR_HOUR)); - public static final Unit VOLT_AMPERE = addUnit(new AlternateUnit<>(Units.WATT, "VA")); - public static final Unit VOLT_AMPERE_HOUR = addUnit(new ProductUnit<>(VOLT_AMPERE.multiply(Units.HOUR)), + public static final Unit VAR_HOUR = addUnit(new ProductUnit<>(VAR.multiply(tec.uom.se.unit.Units.HOUR)), Energy.class); - public static final Unit NEWTON = addUnit(Units.NEWTON); - public static final Unit HERTZ = addUnit(Units.HERTZ); - public static final Unit IRRADIANCE = addUnit(new ProductUnit<>(Units.WATT.divide(Units.SQUARE_METRE))); + public static final Unit KILOVAR_HOUR = addUnit(MetricPrefix.KILO(VAR_HOUR)); + public static final Unit VOLT_AMPERE = addUnit(new AlternateUnit<>(tec.uom.se.unit.Units.WATT, "VA")); + public static final Unit VOLT_AMPERE_HOUR = addUnit( + new ProductUnit<>(VOLT_AMPERE.multiply(tec.uom.se.unit.Units.HOUR)), Energy.class); + public static final Unit NEWTON = addUnit(tec.uom.se.unit.Units.NEWTON); + public static final Unit HERTZ = addUnit(tec.uom.se.unit.Units.HERTZ); + public static final Unit IRRADIANCE = addUnit( + new ProductUnit<>(tec.uom.se.unit.Units.WATT.divide(tec.uom.se.unit.Units.SQUARE_METRE))); public static final Unit MICROWATT_PER_SQUARE_CENTIMETRE = addUnit( new TransformedUnit<>(IRRADIANCE, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(100)))); - public static final Unit LUX = addUnit(Units.LUX); - public static final Unit LUMEN = addUnit(Units.LUMEN); - public static final Unit CANDELA = addUnit(Units.CANDELA); - public static final Unit WEBER = addUnit(Units.WEBER); - public static final Unit TESLA = addUnit(Units.TESLA); - public static final Unit WATT = addUnit(Units.WATT); + public static final Unit LUX = addUnit(tec.uom.se.unit.Units.LUX); + public static final Unit LUMEN = addUnit(tec.uom.se.unit.Units.LUMEN); + public static final Unit CANDELA = addUnit(tec.uom.se.unit.Units.CANDELA); + public static final Unit WEBER = addUnit(tec.uom.se.unit.Units.WEBER); + public static final Unit TESLA = addUnit(tec.uom.se.unit.Units.TESLA); + public static final Unit WATT = addUnit(tec.uom.se.unit.Units.WATT); public static final Unit DECIBEL_MILLIWATTS = new TransformedUnit<>("dBm", MetricPrefix.MILLI(WATT), new ExpConverter(10.0).concatenate(new MultiplyConverter(0.1))); - public static final Unit MILLIMETRE_OF_MERCURY = addUnit(new TransformedUnit<>("mmHg", Units.PASCAL, - new RationalConverter(BigInteger.valueOf(133322368), BigInteger.valueOf(1000000)))); - public static final Unit BAR = addUnit(new TransformedUnit<>("bar", Units.PASCAL, + public static final Unit MILLIMETRE_OF_MERCURY = addUnit( + new TransformedUnit<>("mmHg", tec.uom.se.unit.Units.PASCAL, + new RationalConverter(BigInteger.valueOf(133322368), BigInteger.valueOf(1000000)))); + public static final Unit BAR = addUnit(new TransformedUnit<>("bar", tec.uom.se.unit.Units.PASCAL, new RationalConverter(BigInteger.valueOf(100000), BigInteger.ONE))); public static final Unit MILLIBAR = addUnit(MetricPrefix.MILLI(BAR)); - public static final Unit BECQUEREL = addUnit(Units.BECQUEREL); + public static final Unit BECQUEREL = addUnit(tec.uom.se.unit.Units.BECQUEREL); public static final Unit BECQUEREL_PER_CUBIC_METRE = addUnit( - new ProductUnit<>(Units.BECQUEREL.divide(Units.CUBIC_METRE))); - public static final Unit GRAY = addUnit(Units.GRAY); - public static final Unit SIEVERT = addUnit(Units.SIEVERT); - public static final Unit MILLIMETRE_PER_HOUR = addUnit(new TransformedUnit<>("mm/h", - Units.KILOMETRE_PER_HOUR, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000)))); + new ProductUnit<>(tec.uom.se.unit.Units.BECQUEREL.divide(tec.uom.se.unit.Units.CUBIC_METRE))); + public static final Unit GRAY = addUnit(tec.uom.se.unit.Units.GRAY); + public static final Unit SIEVERT = addUnit(tec.uom.se.unit.Units.SIEVERT); + public static final Unit MILLIMETRE_PER_HOUR = addUnit( + new TransformedUnit<>("mm/h", tec.uom.se.unit.Units.KILOMETRE_PER_HOUR, + new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000)))); public static final Unit INCHES_PER_HOUR = addUnit(new TransformedUnit<>("in/h", ImperialUnits.MILES_PER_HOUR, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(63360)))); - public static final Unit METRE_PER_SECOND = addUnit(Units.METRE_PER_SECOND); - public static final Unit KNOT = addUnit(new TransformedUnit<>("kn", Units.KILOMETRE_PER_HOUR, + public static final Unit METRE_PER_SECOND = addUnit(tec.uom.se.unit.Units.METRE_PER_SECOND); + public static final Unit KNOT = addUnit(new TransformedUnit<>("kn", tec.uom.se.unit.Units.KILOMETRE_PER_HOUR, new RationalConverter(BigInteger.valueOf(1852), BigInteger.valueOf(1000)))); - public static final Unit STERADIAN = addUnit(Units.STERADIAN); - public static final Unit KELVIN = addUnit(Units.KELVIN); - public static final Unit