diff --git a/pom.xml b/pom.xml index ad5aae9..03b433a 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,11 @@ io.quarkus quarkus-arc + + org.apache.commons + commons-lang3 + 3.12.0 + org.jscience jscience diff --git a/src/main/java/com/c4181/camel/CamelConfiguration.java b/src/main/java/com/c4181/camel/CamelConfiguration.java index f43ef8b..3915a00 100644 --- a/src/main/java/com/c4181/camel/CamelConfiguration.java +++ b/src/main/java/com/c4181/camel/CamelConfiguration.java @@ -2,6 +2,7 @@ package com.c4181.camel; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.lang3.StringUtils; import javax.measure.Measure; import javax.measure.quantity.Pressure; @@ -12,24 +13,39 @@ public class CamelConfiguration extends RouteBuilder { @Override public void configure() { - from("paho-mqtt5:teslamate/cars/1/update_version?brokerUrl={{sys:BROKER_URL}}").process((exchange -> { - String updateVersion = exchange.getIn().getBody(String.class); - exchange.getIn().setBody("New Update available. Version: " + updateVersion); + from("paho-mqtt5:teslamate/cars/1/update_version?brokerUrl={{sys:BROKER_URL}}") + .filter(exchange -> StringUtils.isNotBlank(exchange.getIn().getBody(String.class))) + .process((exchange -> { + String updateVersion = exchange.getIn().getBody(String.class); - log.info("New Version {} found. Sending to telegram", updateVersion); - })) + if (StringUtils.isNotBlank(updateVersion)) { + exchange.getIn().setBody("New Update available. Version: " + updateVersion); + } else { + exchange.setRouteStop(true); + } + + log.info("New Version {} found. Sending to telegram", updateVersion); + })) .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); from("paho-mqtt5:teslamate/cars/1/tpms_pressure_fl?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Front left"))) + .throttle(1).rejectExecution(true) + .timePeriodMillis(900000) // 15 minutes .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); from("paho-mqtt5:teslamate/cars/1/tpms_pressure_fr?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Front right"))) + .throttle(1).rejectExecution(true) + .timePeriodMillis(900000) // 15 minutes .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); from("paho-mqtt5:teslamate/cars/1/tpms_pressure_rl?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Back left"))) + .throttle(1).rejectExecution(true) + .timePeriodMillis(900000) // 15 minutes .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); from("paho-mqtt5:teslamate/cars/1/tpms_pressure_rr?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Back right"))) + .throttle(1).rejectExecution(true) + .timePeriodMillis(900000) // 15 minutes .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); }