]> git.basschouten.com Git - openhab-addons.git/commitdiff
[Konnected] Adding base URL to config to allow for manually adding thing (#13251)
authorHaavar Valeur <github.com@haavar.com>
Sat, 13 Aug 2022 08:34:39 +0000 (01:34 -0700)
committerGitHub <noreply@github.com>
Sat, 13 Aug 2022 08:34:39 +0000 (10:34 +0200)
* Adding base URL to config to allow for manually adding thing
* Simplified reading of the base URL configuration. Renamed field to baseUrl to be consistent.
* Changed config parameters to camel case

Signed-off-by: Haavar Valeur <haavar@haavar.com>
bundles/org.openhab.binding.konnected/src/main/java/org/openhab/binding/konnected/internal/KonnectedBindingConstants.java
bundles/org.openhab.binding.konnected/src/main/java/org/openhab/binding/konnected/internal/discovery/KonnectedUPnPServer.java
bundles/org.openhab.binding.konnected/src/main/java/org/openhab/binding/konnected/internal/handler/KonnectedHandler.java
bundles/org.openhab.binding.konnected/src/main/resources/OH-INF/config/config.xml
bundles/org.openhab.binding.konnected/src/main/resources/OH-INF/i18n/konnected.properties

index a328ae54eca1722101d15fc836e2f9dcc9f67601..cfc0ad9ea42f0750e075b529abcf856e7bf5e4b6 100644 (file)
@@ -36,11 +36,11 @@ public class KonnectedBindingConstants {
     public static final ThingTypeUID THING_TYPE_PROMODULE = new ThingTypeUID(BINDING_ID, PRO_MODULE);
 
     // Thing config properties
-    public static final String HOST = "ipAddress";
+    public static final String BASE_URL = "baseUrl";
     public static final String MAC_ADDR = "macAddress";
-    public static final String REQUEST_TIMEOUT = "request_timeout";
-    public static final String RETRY_COUNT = "retry_count";
-    public static final String CALLBACK_URI = "callback_uri";
+    public static final String REQUEST_TIMEOUT = "requestTimeout";
+    public static final String RETRY_COUNT = "retryCount";
+    public static final String CALLBACK_URL = "callbackUrl";
 
     // ESP8266_ZONE_TO_PIN map, this maps a zone to a pin for ESP8266 based devices
     // Source: https://help.konnected.io/support/solutions/articles/32000026808-zone-to-gpio-pin-mapping
index 360954aacdc61351dcb82977b54832b4bb4c1c72..29a512ec6f234695d23d15fc442da94873a247d1 100644 (file)
@@ -60,7 +60,7 @@ public class KonnectedUPnPServer implements UpnpDiscoveryParticipant {
         ThingUID uid = getThingUID(device);
         if (uid != null) {
             Map<String, Object> properties = new HashMap<>();
-            properties.put(HOST, device.getDetails().getBaseURL());
+            properties.put(BASE_URL, device.getDetails().getBaseURL());
             properties.put(MAC_ADDR, device.getDetails().getSerialNumber());
             DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
                     .withLabel(device.getDetails().getFriendlyName()).withRepresentationProperty(MAC_ADDR).build();
index 1e604f5c0b00ed19277a93552ecccb1e3d418dd0..befa1e6118c1585300f0fcebbff3d47862b3a54a 100644 (file)
@@ -56,7 +56,7 @@ public class KonnectedHandler extends BaseThingHandler {
     private final String konnectedServletPath;
     private final KonnectedHTTPUtils http = new KonnectedHTTPUtils(30);
     private String callbackIpAddress = null;
-    private String moduleIpAddress;
+    private String baseUrl;
     private final Gson gson = new GsonBuilder().create();
     private int retryCount;
     private final String thingID;
@@ -177,8 +177,10 @@ public class KonnectedHandler extends BaseThingHandler {
         Configuration testConfig = this.getConfig();
         String testRetryCount = testConfig.get(RETRY_COUNT).toString();
         String testRequestTimeout = testConfig.get(REQUEST_TIMEOUT).toString();
+        baseUrl = testConfig.get(BASE_URL).toString();
         logger.debug("The RequestTimeout Parameter is Configured as: {}", testRequestTimeout);
         logger.debug("The Retry Count Parameter is Configured as: {}", testRetryCount);
+        logger.debug("Base URL is Configured as: {}", baseUrl);
         try {
             this.retryCount = Integer.parseInt(testRetryCount);
         } catch (NumberFormatException e) {
@@ -224,7 +226,7 @@ public class KonnectedHandler extends BaseThingHandler {
                 if (cfg[1].equals("softreset") && value instanceof Boolean && (Boolean) value) {
                     scheduler.execute(() -> {
                         try {
-                            http.doGet(moduleIpAddress + "/settings?restart=true", null, retryCount);
+                            http.doGet(baseUrl + "/settings?restart=true", null, retryCount);
                         } catch (KonnectedHttpRetryExceeded e) {
                             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
                         }
@@ -233,7 +235,7 @@ public class KonnectedHandler extends BaseThingHandler {
                 } else if (cfg[1].equals("removewifi") && value instanceof Boolean && (Boolean) value) {
                     scheduler.execute(() -> {
                         try {
-                            http.doGet(moduleIpAddress + "/settings?restore=true", null, retryCount);
+                            http.doGet(baseUrl + "/settings?restore=true", null, retryCount);
                         } catch (KonnectedHttpRetryExceeded e) {
                             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
                         }
@@ -288,7 +290,6 @@ public class KonnectedHandler extends BaseThingHandler {
         } catch (ConfigValidationException e) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
         }
-        this.moduleIpAddress = this.getThing().getProperties().get(HOST).toString();
         scheduler.execute(() -> {
             try {
                 String response = updateKonnectedModule();
@@ -320,7 +321,7 @@ public class KonnectedHandler extends BaseThingHandler {
      * @return a json settings payload which can be sent to the Konnected Module based on the Thing
      */
     private String constructSettingsPayload() {
-        String apiUrl = (String) getThing().getConfiguration().get(CALLBACK_URI);
+        String apiUrl = (String) getThing().getConfiguration().get(CALLBACK_URL);
         if (apiUrl == null) {
             apiUrl = "http://" + callbackIpAddress + this.konnectedServletPath;
         }
@@ -404,7 +405,7 @@ public class KonnectedHandler extends BaseThingHandler {
      */
     private String updateKonnectedModule() throws KonnectedHttpRetryExceeded {
         String payload = constructSettingsPayload();
-        String response = http.doPut(moduleIpAddress + "/settings", payload, retryCount);
+        String response = http.doPut(baseUrl + "/settings", payload, retryCount);
         logger.debug("The response of the put request was: {}", response);
         return response;
     }
@@ -469,7 +470,7 @@ public class KonnectedHandler extends BaseThingHandler {
                         path = "/device";
                         break;
                 }
-                http.doPut(moduleIpAddress + path, payloadString, retryCount);
+                http.doPut(baseUrl + path, payloadString, retryCount);
             } else {
                 logger.debug("The channel {} returned null for channelId.getID(): {}", channelId.toString(),
                         channelId.getId());
@@ -515,7 +516,7 @@ public class KonnectedHandler extends BaseThingHandler {
 
     private void sendSetSwitchState(String thingId, String payloadString) throws KonnectedHttpRetryExceeded {
         String path = thingId.equals(WIFI_MODULE) ? "/device" : "/zone";
-        String response = http.doGet(moduleIpAddress + path, payloadString, retryCount);
+        String response = http.doGet(baseUrl + path, payloadString, retryCount);
         KonnectedModuleGson[] events = gson.fromJson(response, KonnectedModuleGson[].class);
         for (KonnectedModuleGson event : events) {
             this.handleWebHookEvent(event);
index c807b8798282acfba01d4a92a2f7e6e8ed7f6be7..ed3bacd31a35340ef12e8288369d5a805ae4c91e 100644 (file)
@@ -9,6 +9,10 @@
                        <label>Actions</label>
                        <description/>
                </parameter-group>
+               <parameter name="baseUrl" type="text" required="true">
+                       <label>Base URL</label>
+                       <description>The base URL of the Konnected Alarm Panel.</description>
+               </parameter>
                <parameter name="blink" type="boolean">
                        <label>Blink</label>
                        <description> When set to false the Led on the device won't blink during transmission.</description>
@@ -23,7 +27,7 @@
                        <default>true</default>
                        <advanced>true</advanced>
                </parameter>
-               <parameter name="retry_count" type="integer">
+               <parameter name="retryCount" type="integer">
                        <label>Retry Count</label>
                        <description>The number of times the binding attempts to send http requests to the Konnected Alarm Panel. Increase
                                this setting if you are experiencing situations where the module is reporting as offline but you can access the
@@ -32,7 +36,7 @@
                        <default>2</default>
                        <advanced>true</advanced>
                </parameter>
-               <parameter name="request_timeout" type="integer">
+               <parameter name="requestTimeout" type="integer">
                        <label>Request Timeout</label>
                        <description>The timeout period in seconds for HTTP requests to the Konnected Alarm Panel. The default is 30.
                                Adjusting this setting can help in networks situations with high latency where the binding is erroneously reporting
@@ -41,7 +45,7 @@
                        <advanced>true</advanced>
                </parameter>
 
-               <parameter name="callback_uri" type="text">
+               <parameter name="callbackUrl" type="text">
                        <label>Callback URI</label>
                        <description>The URI where the Konnected panel will make callbacks. The default is to auto detect the port and IP
                                address of openHAB. This may not work in case you use a reverse proxy or openHAB
index d6b00bb3d5f8a981261c2540ffe4300db0d9419d..ed42b785532bbf42a8087f45d7e4c90e8f5ab41d 100644 (file)
@@ -12,10 +12,12 @@ thing-type.konnected.wifi-module.description = The Konnected Wi-Fi Alarm Panel
 
 # thing types config
 
+thing-type.config.konnected.module.baseUrl.label = Base URL
+thing-type.config.konnected.module.baseUrl.description = The base URL of the Konnected Alarm Panel.
 thing-type.config.konnected.module.blink.label = Blink
 thing-type.config.konnected.module.blink.description = When set to false the Led on the device won't blink during transmission.
-thing-type.config.konnected.module.callback_uri.label = Callback URI
-thing-type.config.konnected.module.callback_uri.description = The URI where the Konnected panel will make callbacks. The default is to auto detect the port and IP address of openHAB. This may not work in case you use a reverse proxy or openHAB is running in Docker. Then the plugin is bound to the /konnected http context.
+thing-type.config.konnected.module.callbackUrl.label = Callback URI
+thing-type.config.konnected.module.callbackUrl.description = The URI where the Konnected panel will make callbacks. The default is to auto detect the port and IP address of openHAB. This may not work in case you use a reverse proxy or openHAB is running in Docker. Then the plugin is bound to the /konnected http context.
 thing-type.config.konnected.module.controller_removewifi.label = Factory Reset
 thing-type.config.konnected.module.controller_removewifi.description = Resets the module to Factory Conditions.
 thing-type.config.konnected.module.controller_sendConfig.label = Update Settings
@@ -25,10 +27,10 @@ thing-type.config.konnected.module.controller_softreset.description = Send A Res
 thing-type.config.konnected.module.discovery.label = Discovery
 thing-type.config.konnected.module.discovery.description = If set to false the device will not respond to discovery requests via UPnP. Make sure you have statically assigned an IP address to the module before turning this setting off. See https://help.konnected.io/support/solutions/articles/32000023968-disabling-device-discovery
 thing-type.config.konnected.module.group.actions.label = Actions
-thing-type.config.konnected.module.request_timeout.label = Request Timeout
-thing-type.config.konnected.module.request_timeout.description = The timeout period in seconds for HTTP requests to the Konnected Alarm Panel. The default is 30. Adjusting this setting can help in networks situations with high latency where the binding is erroneously reporting the thing as offline.
-thing-type.config.konnected.module.retry_count.label = Retry Count
-thing-type.config.konnected.module.retry_count.description = The number of times the binding attempts to send http requests to the Konnected Alarm Panel. Increase this setting if you are experiencing situations where the module is reporting as offline but you can access the website of the Alarm Panel to confirm that the Alarm Panel is Konnected to the Network. This will allow the binding to attempt more retries before it considers the connection a failure and marks the thing as offline.
+thing-type.config.konnected.module.requestTimeout.label = Request Timeout
+thing-type.config.konnected.module.requestTimeout.description = The timeout period in seconds for HTTP requests to the Konnected Alarm Panel. The default is 30. Adjusting this setting can help in networks situations with high latency where the binding is erroneously reporting the thing as offline.
+thing-type.config.konnected.module.retryCount.label = Retry Count
+thing-type.config.konnected.module.retryCount.description = The number of times the binding attempts to send http requests to the Konnected Alarm Panel. Increase this setting if you are experiencing situations where the module is reporting as offline but you can access the website of the Alarm Panel to confirm that the Alarm Panel is Konnected to the Network. This will allow the binding to attempt more retries before it considers the connection a failure and marks the thing as offline.
 
 # channel types