mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[Konnected] Adding base URL to config to allow for manually adding thing (#13251)
* 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>
This commit is contained in:
parent
bff2298b20
commit
4b5bbab009
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user