protected void activate(ComponentContext componentContext) {
super.activate(componentContext);
Dictionary<String, Object> properties = componentContext.getProperties();
- callbackUrl = (String) properties.get("callbackUrl");
+ callbackUrl = (String) properties.get(CALLBACK_URL);
+ logger.debug("Callback URL from OSGI service: {}", callbackUrl);
try {
this.servlet = registerWebHookServlet();
} catch (KonnectedWebHookFail e) {
@Override
protected @Nullable ThingHandler createHandler(Thing thing) {
- KonnectedHandler thingHandler = new KonnectedHandler(thing, '/' + BINDING_ID, createCallbackUrl(),
- createCallbackPort());
+
+ KonnectedHandler thingHandler = new KonnectedHandler(thing, getCallbackUrl());
if (servlet != null) {
logger.debug("Adding thinghandler for thing {} to webhook.", thing.getUID().getId());
servlet.add(thingHandler);
this.httpService = null;
}
- private String createCallbackUrl() {
- if (callbackUrl != null) {
- logger.debug("The callback ip address from the OSGI is:{}", callbackUrl);
- return callbackUrl;
- } else {
- final String ipAddress = networkAddressService.getPrimaryIpv4HostAddress();
- if (ipAddress == null) {
- logger.warn("No network interface could be found.");
- return null;
+ private String getCallbackUrl() {
+ if (callbackUrl == null) {
+ String callbackIP = discoverCallbackIP();
+ String callbackPort = discoverCallbackPort();
+ if (callbackPort != null && callbackIP != null) {
+ callbackUrl = "http://" + discoverCallbackIP() + ":" + discoverCallbackPort() + '/' + BINDING_ID;
}
- logger.debug("The callback ip address obtained from the Network Address Service was:{}", ipAddress);
- return ipAddress;
}
+ return callbackUrl;
+ }
+
+ private String discoverCallbackIP() {
+ final String ipAddress = networkAddressService.getPrimaryIpv4HostAddress();
+ if (ipAddress == null) {
+ logger.warn("No network interface could be found.");
+ return null;
+ }
+ logger.debug("The callback ip address obtained from the Network Address Service was:{}", ipAddress);
+ return ipAddress;
}
- private String createCallbackPort() {
+ private String discoverCallbackPort() {
// we do not use SSL as it can cause certificate validation issues.
final int port = HttpServiceUtil.getHttpServicePort(bundleContext);
if (port == -1) {
public class KonnectedHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(KonnectedHandler.class);
private KonnectedConfiguration config;
- private final String konnectedServletPath;
private final KonnectedHTTPUtils http = new KonnectedHTTPUtils(30);
- private String callbackIpAddress = null;
+ private String callbackUrl;
private String baseUrl;
private final Gson gson = new GsonBuilder().create();
private int retryCount;
* @param hostAddress the webaddress of the openHAB server instance obtained by the runtime
* @param port the port on which the openHAB instance is running that was obtained by the runtime.
*/
- public KonnectedHandler(Thing thing, String path, String hostAddress, String port) {
+ public KonnectedHandler(Thing thing, String callbackUrl) {
super(thing);
- this.konnectedServletPath = path;
- callbackIpAddress = hostAddress + ":" + port;
- logger.debug("The callback ip address is: {}", callbackIpAddress);
+ this.callbackUrl = callbackUrl;
+ logger.debug("The auto discovered callback URL is: {}", this.callbackUrl);
retryCount = 2;
thingID = getThing().getThingTypeUID().getId();
authToken = getThing().getUID().getAsString();
String testRetryCount = testConfig.get(RETRY_COUNT).toString();
String testRequestTimeout = testConfig.get(REQUEST_TIMEOUT).toString();
baseUrl = testConfig.get(BASE_URL).toString();
+ String configuredCallbackUrl = (String) getThing().getConfiguration().get(CALLBACK_URL);
+ if (configuredCallbackUrl != null) {
+ callbackUrl = configuredCallbackUrl;
+ } else {
+ getThing().getConfiguration().put(CALLBACK_URL, callbackUrl);
+ }
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);
+ logger.debug("The callback URL is: {}", callbackUrl);
try {
this.retryCount = Integer.parseInt(testRetryCount);
} catch (NumberFormatException e) {
testRequestTimeout);
}
- if ((callbackIpAddress == null)) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
- "Unable to obtain hostaddress from OSGI service, please configure hostaddress");
+ if ((callbackUrl == null)) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Unable to obtain callback URL");
}
else {
* @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_URL);
- if (apiUrl == null) {
- apiUrl = "http://" + callbackIpAddress + this.konnectedServletPath;
- }
-
logger.debug("The Auth_Token is: {}", authToken);
- KonnectedModulePayload payload = new KonnectedModulePayload(authToken, apiUrl);
+ KonnectedModulePayload payload = new KonnectedModulePayload(authToken, callbackUrl);
payload.setBlink(config.blink);
payload.setDiscovery(config.discovery);
this.getThing().getChannels().forEach(channel -> {
</parameter>
<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
+ <label>Callback URL</label>
+ <description>The URL 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
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.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.callbackUrl.label = Callback URL
+thing-type.config.konnected.module.callbackUrl.description = The URL 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