diff --git a/bundles/org.openhab.binding.telegram/README.md b/bundles/org.openhab.binding.telegram/README.md index 298e9540c18ee..fe9ef0807155b 100644 --- a/bundles/org.openhab.binding.telegram/README.md +++ b/bundles/org.openhab.binding.telegram/README.md @@ -67,7 +67,7 @@ In order to send a message, an action must be used instead. | `proxyHost` | None | No | Proxy host for telegram binding. | | `proxyPort` | None | No | Proxy port for telegram binding. | | `proxyType` | SOCKS5 | No | Type of proxy server for telegram binding (SOCKS5 or HTTP). | -| `longPollingTime` | 25 | No | Timespan in seconds for long polling the telegram API. | +| `longPollingTime` | 25 | No | Timespan in seconds for long polling the telegram API. (0 to disable) | By default chat ids are bi-directionally, i.e. they can send and receive messages. They can be prefixed with an access modifier: diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java index 5b7cc20319108..55d6ecfd1adc2 100644 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java +++ b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java @@ -186,8 +186,11 @@ public void initialize() { updateStatus(ThingStatus.UNKNOWN); delayThingOnlineStatus(); TelegramBot localBot = bot = new TelegramBot.Builder(botToken).okHttpClient(botLibClient).build(); - localBot.setUpdatesListener(this::handleUpdates, this::handleExceptions, - getGetUpdatesRequest(config.getLongPollingTime())); + int longPollingTime = config.getLongPollingTime(); + if (longPollingTime > 0) { + localBot.setUpdatesListener(this::handleUpdates, this::handleExceptions, + getGetUpdatesRequest(longPollingTime)); + } } private void createReceiverChatIdsAndAuthorizedSenderChatIds(List chatIds) { @@ -470,7 +473,10 @@ public void dispose() { OkHttpClient localClient = botLibClient; TelegramBot localBot = bot; if (localClient != null && localBot != null) { - localBot.removeGetUpdatesListener(); + TelegramConfiguration config = this.getConfig().as(TelegramConfiguration.class); + if (config.getLongPollingTime() > 0) { + localBot.removeGetUpdatesListener(); + } localClient.dispatcher().executorService().shutdown(); localClient.connectionPool().evictAll(); logger.debug("Telegram client closed"); diff --git a/bundles/org.openhab.binding.telegram/src/main/resources/OH-INF/i18n/telegram.properties b/bundles/org.openhab.binding.telegram/src/main/resources/OH-INF/i18n/telegram.properties index 3c8c3689baaf3..b9c3260a7ea16 100644 --- a/bundles/org.openhab.binding.telegram/src/main/resources/OH-INF/i18n/telegram.properties +++ b/bundles/org.openhab.binding.telegram/src/main/resources/OH-INF/i18n/telegram.properties @@ -15,7 +15,7 @@ thing-type.config.telegram.telegramBot.botToken.description = Enter the bot toke thing-type.config.telegram.telegramBot.chatIds.label = Chat Id(s) thing-type.config.telegram.telegramBot.chatIds.description = One or more chat id(s). Access modifiers ("<" for inbound only, ">" for outbound only) can be used as prefix (optional). thing-type.config.telegram.telegramBot.longPollingTime.label = Long Polling Time -thing-type.config.telegram.telegramBot.longPollingTime.description = Enter the long polling time in seconds. +thing-type.config.telegram.telegramBot.longPollingTime.description = Enter the long polling time in seconds. Set 0 to disable. thing-type.config.telegram.telegramBot.parseMode.label = Parse Mode thing-type.config.telegram.telegramBot.parseMode.description = Support for formatted messages, values: Markdown or HTML. Default: no formatting is used. thing-type.config.telegram.telegramBot.parseMode.option. = No Formatting diff --git a/bundles/org.openhab.binding.telegram/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.telegram/src/main/resources/OH-INF/thing/thing-types.xml index 55cbeb00ead07..b0570eaa1432e 100644 --- a/bundles/org.openhab.binding.telegram/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.telegram/src/main/resources/OH-INF/thing/thing-types.xml @@ -62,7 +62,7 @@ - Enter the long polling time in seconds. + Enter the long polling time in seconds. Set 0 to disable. 25