From 351fcb18521c5523e1b68a0073f65f59aa43e7eb Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Sat, 10 Oct 2020 20:04:25 +0200 Subject: [PATCH] Include measurement system in REST root resource (#1710) Signed-off-by: Kai Kreuzer --- .../core/io/rest/internal/resources/RootResource.java | 8 ++++++-- .../core/io/rest/internal/resources/beans/RootBean.java | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/RootResource.java b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/RootResource.java index ad686d6c0..acfcfd789 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/RootResource.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/RootResource.java @@ -26,6 +26,7 @@ import javax.ws.rs.core.UriInfo; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.i18n.LocaleProvider; +import org.openhab.core.i18n.UnitProvider; import org.openhab.core.io.rest.RESTConstants; import org.openhab.core.io.rest.RESTResource; import org.openhab.core.io.rest.internal.resources.beans.RootBean; @@ -81,11 +82,14 @@ public class RootResource implements RESTResource { private final Logger logger = LoggerFactory.getLogger(RootResource.class); private final JaxrsServiceRuntime runtime; private final LocaleProvider localeProvider; + private final UnitProvider unitProvider; @Activate - public RootResource(final @Reference JaxrsServiceRuntime runtime, final @Reference LocaleProvider localeProvider) { + public RootResource(final @Reference JaxrsServiceRuntime runtime, final @Reference LocaleProvider localeProvider, + final @Reference UnitProvider unitProvider) { this.runtime = runtime; this.localeProvider = localeProvider; + this.unitProvider = unitProvider; } @GET @@ -98,7 +102,7 @@ public class RootResource implements RESTResource { final Map collectedLinks = new HashMap<>(); final RuntimeDTO runtimeDTO = runtime.getRuntimeDTO(); - final RootBean bean = new RootBean(localeProvider); + final RootBean bean = new RootBean(localeProvider, unitProvider); for (final ApplicationDTO applicationDTO : runtimeDTO.applicationDTOs) { for (final ResourceDTO resourceDTO : applicationDTO.resourceDTOs) { // We are using the JAX-RS name per convention for the link type. diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/beans/RootBean.java b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/beans/RootBean.java index 441e632a2..0540df2db 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/beans/RootBean.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/beans/RootBean.java @@ -18,6 +18,7 @@ import java.util.List; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.OpenHAB; import org.openhab.core.i18n.LocaleProvider; +import org.openhab.core.i18n.UnitProvider; import org.openhab.core.io.rest.RESTConstants; /** @@ -34,12 +35,15 @@ public class RootBean { public final String locale; + public final String measurementSystem; + public final RuntimeInfo runtimeInfo = new RuntimeInfo(); public final List links = new ArrayList<>(); - public RootBean(LocaleProvider localeProvider) { + public RootBean(LocaleProvider localeProvider, UnitProvider unitProvider) { this.locale = localeProvider.getLocale().toString(); + this.measurementSystem = unitProvider.getMeasurementSystem().getName(); } public static class RuntimeInfo {