Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
@@ -29,6 +29,7 @@ public class ApiHandlerConfiguration {
|
||||
public String clientSecret = "";
|
||||
public String refreshToken = "";
|
||||
public String webHookUrl = "";
|
||||
public String webHookPostfix = "";
|
||||
public int reconnectInterval = 300;
|
||||
|
||||
public ConfigurationLevel check() {
|
||||
|
||||
@@ -160,7 +160,7 @@ public class ApiBridgeHandler extends BaseBridgeHandler {
|
||||
SecurityApi securityApi = getRestManager(SecurityApi.class);
|
||||
if (securityApi != null) {
|
||||
WebhookServlet servlet = new WebhookServlet(this, httpService, deserializer, securityApi,
|
||||
configuration.webHookUrl);
|
||||
configuration.webHookUrl, configuration.webHookPostfix);
|
||||
servlet.startListening();
|
||||
this.webHookServlet = servlet;
|
||||
}
|
||||
|
||||
@@ -50,21 +50,23 @@ public class WebhookServlet extends NetatmoServlet {
|
||||
private final SecurityApi securityApi;
|
||||
private final NADeserializer deserializer;
|
||||
private final String webHookUrl;
|
||||
private final String webHookPostfix;
|
||||
|
||||
private boolean hookSet = false;
|
||||
|
||||
public WebhookServlet(ApiBridgeHandler handler, HttpService httpService, NADeserializer deserializer,
|
||||
SecurityApi securityApi, String webHookUrl) {
|
||||
SecurityApi securityApi, String webHookUrl, String webHookPostfix) {
|
||||
super(handler, httpService, "webhook");
|
||||
this.deserializer = deserializer;
|
||||
this.securityApi = securityApi;
|
||||
this.webHookUrl = webHookUrl;
|
||||
this.webHookPostfix = webHookPostfix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListening() {
|
||||
super.startListening();
|
||||
URI uri = UriBuilder.fromUri(webHookUrl).path(path).build();
|
||||
URI uri = UriBuilder.fromUri(webHookUrl).path(path + webHookPostfix).build();
|
||||
try {
|
||||
logger.info("Setting up WebHook at Netatmo to {}", uri.toString());
|
||||
hookSet = securityApi.addwebhook(uri);
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
<description>@text/config.webHookUrl.description</description>
|
||||
</parameter>
|
||||
|
||||
<parameter name="webHookPostfix" type="text" required="false">
|
||||
<label>@text/config.webHookPostfix.label</label>
|
||||
<description>@text/config.webHookPostfix.description</description>
|
||||
</parameter>
|
||||
|
||||
<parameter name="reconnectInterval" type="integer" unit="s">
|
||||
<label>@text/config.reconnectInterval.label</label>
|
||||
<description>@text/config.reconnectInterval.description</description>
|
||||
|
||||
@@ -423,6 +423,8 @@ config.clientSecret.label = Client Secret
|
||||
config.clientSecret.description = Client Secret provided for the application you created.
|
||||
config.refreshToken.label = Refresh Token
|
||||
config.refreshToken.description = Refresh token provided by the oAuth2 authentication process.
|
||||
config.webHookPostfix.label = Webhook Postfix
|
||||
config.webHookPostfix.description = String appended to the generated webhook address (should start with `/`).
|
||||
config.webHookUrl.label = Webhook Address
|
||||
config.webHookUrl.description = Protocol, public IP or hostname and port to access openHAB server from Internet.
|
||||
config.reconnectInterval.label = Reconnect Interval
|
||||
|
||||
Reference in New Issue
Block a user