From dfa6c09063e8e95b8ef8aacfd45eb0a9a7961ea8 Mon Sep 17 00:00:00 2001 From: Alexander Friese Date: Fri, 8 Nov 2024 17:00:13 +0100 Subject: [PATCH] code review Signed-off-by: Alexander Friese --- .../internal/MyUplinkBindingConstants.java | 2 ++ .../handler/MyUplinkAccountHandler.java | 12 ++++++++-- .../handler/MyUplinkGenericDeviceHandler.java | 1 + .../resources/OH-INF/i18n/myuplink.properties | 23 +++++++++++++++---- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/MyUplinkBindingConstants.java b/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/MyUplinkBindingConstants.java index 9324693a8247a..6f4ac2b24bcf2 100644 --- a/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/MyUplinkBindingConstants.java +++ b/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/MyUplinkBindingConstants.java @@ -159,6 +159,8 @@ public class MyUplinkBindingConstants { public static final String STATUS_NO_VALID_DATA = "@text/status.no.valid.data"; public static final String STATUS_NO_CONNECTION = "@text/status.no.connection"; public static final String STATUS_DEVICE_NOT_FOUND = "@text/status.device.not.found"; + public static final String STATUS_CONFIG_ERROR_NO_CLIENT_ID = "@text/status.config.error.no.client.id"; + public static final String STATUS_CONFIG_ERROR_NO_CLIENT_SECRET = "@text/status.config.error.no.client.secret"; // other public static final long POLLING_INITIAL_DELAY = 5; diff --git a/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/handler/MyUplinkAccountHandler.java b/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/handler/MyUplinkAccountHandler.java index a0184ac6ff13d..2b6c0192065a9 100644 --- a/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/handler/MyUplinkAccountHandler.java +++ b/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/handler/MyUplinkAccountHandler.java @@ -78,8 +78,16 @@ public void initialize() { logger.debug("myUplink Account initialized with configuration: {}", config.toString()); updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE, STATUS_WAITING_FOR_LOGIN); - webInterface.start(); - startPolling(); + + if (config.getClientId().isBlank()) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, STATUS_CONFIG_ERROR_NO_CLIENT_ID); + } else if (config.getClientSecret().isBlank()) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + STATUS_CONFIG_ERROR_NO_CLIENT_SECRET); + } else { + webInterface.start(); + startPolling(); + } } /** diff --git a/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/handler/MyUplinkGenericDeviceHandler.java b/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/handler/MyUplinkGenericDeviceHandler.java index 6078aaad96169..a30a2b7f1a28e 100644 --- a/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/handler/MyUplinkGenericDeviceHandler.java +++ b/bundles/org.openhab.binding.myuplink/src/main/java/org/openhab/binding/myuplink/internal/handler/MyUplinkGenericDeviceHandler.java @@ -271,6 +271,7 @@ public void enqueueCommand(MyUplinkCommand command) { private @Nullable MyUplinkBridgeHandler getBridgeHandler() { Bridge bridge = getBridge(); return bridge != null && bridge.getHandler() instanceof MyUplinkBridgeHandler handler ? handler : null; + } @Override public MyUplinkConfiguration getBridgeConfiguration() { diff --git a/bundles/org.openhab.binding.myuplink/src/main/resources/OH-INF/i18n/myuplink.properties b/bundles/org.openhab.binding.myuplink/src/main/resources/OH-INF/i18n/myuplink.properties index 6483b6a3799ef..e58f718f2e885 100644 --- a/bundles/org.openhab.binding.myuplink/src/main/resources/OH-INF/i18n/myuplink.properties +++ b/bundles/org.openhab.binding.myuplink/src/main/resources/OH-INF/i18n/myuplink.properties @@ -26,10 +26,6 @@ thing-type.config.myuplink.account.group.authentication.label = Authentication thing-type.config.myuplink.account.group.authentication.description = Authentication settings. thing-type.config.myuplink.account.group.connection.label = Connection thing-type.config.myuplink.account.group.connection.description = Connection settings. -thing-type.config.myuplink.account.group.customChannels.label = Custom Channels -thing-type.config.myuplink.account.group.customChannels.description = Custom Channel configuration -thing-type.config.myuplink.account.group.general.label = General -thing-type.config.myuplink.account.group.general.description = General settings. thing-type.config.myuplink.generic-device.deviceId.label = Device Id thing-type.config.myuplink.generic-device.deviceId.description = The Id to identify the device. thing-type.config.myuplink.generic-device.systemId.label = System Id @@ -63,3 +59,22 @@ channel-type.myuplink.type-percent.label = Generic Percentage channel-type.myuplink.type-pressure.label = Generic Pressure channel-type.myuplink.type-temperature.label = Generic Temperature channel-type.myuplink.type-time.label = Generic Time + +# thing types config + +thing-type.config.myuplink.account.group.customChannels.label = Custom Channels +thing-type.config.myuplink.account.group.customChannels.description = Custom Channel configuration +thing-type.config.myuplink.account.group.general.label = General +thing-type.config.myuplink.account.group.general.description = General settings. + + +# status translations + +status.token.validated = "Access token validated" +status.waiting.for.bridge = "Waiting for bridge to go online" +status.waiting.for.login = "Waiting for web api login" +status.no.valid.data = "No valid data received. This is most likely a configuration error" +status.no.connection = "No connection could be established" +status.device.not.found = "Device could not be found. Most likely a configuration error" +status.config.error.no.client.id = "No/Empty client id. Please fix the configuration." +status.config.error.no.client.secret = "No/Empty client secret. Please fix the configuration."