[rest] Add timezone information to root resource (#4826)

Signed-off-by: Florian Hotze <dev@florianhotze.com>
pull/4835/head
Florian Hotze 2025-05-30 03:12:10 +02:00 committed by GitHub
parent 07ad5b52b2
commit 5126166611
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -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.TimeZoneProvider;
import org.openhab.core.i18n.UnitProvider;
import org.openhab.core.io.rest.RESTConstants;
import org.openhab.core.io.rest.RESTResource;
@ -83,13 +84,15 @@ public class RootResource implements RESTResource {
private final JaxrsServiceRuntime runtime;
private final LocaleProvider localeProvider;
private final UnitProvider unitProvider;
private final TimeZoneProvider timeZoneProvider;
@Activate
public RootResource(final @Reference JaxrsServiceRuntime runtime, final @Reference LocaleProvider localeProvider,
final @Reference UnitProvider unitProvider) {
final @Reference UnitProvider unitProvider, final @Reference TimeZoneProvider timeZoneProvider) {
this.runtime = runtime;
this.localeProvider = localeProvider;
this.unitProvider = unitProvider;
this.timeZoneProvider = timeZoneProvider;
}
@GET
@ -102,7 +105,7 @@ public class RootResource implements RESTResource {
final Map<String, String> collectedLinks = new HashMap<>();
final RuntimeDTO runtimeDTO = runtime.getRuntimeDTO();
final RootBean bean = new RootBean(localeProvider, unitProvider);
final RootBean bean = new RootBean(localeProvider, unitProvider, timeZoneProvider);
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.

View File

@ -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.TimeZoneProvider;
import org.openhab.core.i18n.UnitProvider;
import org.openhab.core.io.rest.RESTConstants;
@ -37,13 +38,16 @@ public class RootBean {
public final String measurementSystem;
public final String timezone;
public final RuntimeInfo runtimeInfo = new RuntimeInfo();
public final List<Links> links = new ArrayList<>();
public RootBean(LocaleProvider localeProvider, UnitProvider unitProvider) {
public RootBean(LocaleProvider localeProvider, UnitProvider unitProvider, TimeZoneProvider timeZoneProvider) {
this.locale = localeProvider.getLocale().toString();
this.measurementSystem = unitProvider.getMeasurementSystem().getName();
this.timezone = timeZoneProvider.getTimeZone().toString();
}
public static class RuntimeInfo {