From 3bd53b764a6db0f003be3fb79f5d097b0a0864b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Mon, 18 Nov 2024 13:39:12 +0100 Subject: [PATCH] Added binding to pom.xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaƫl L'hopital --- .../handler/AirParifBridgeHandler.java | 21 +++++++++++-------- .../internal/handler/LocationHandler.java | 9 ++++---- bundles/pom.xml | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/handler/AirParifBridgeHandler.java b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/handler/AirParifBridgeHandler.java index 353c22dfcde..b22c3a6d459 100755 --- a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/handler/AirParifBridgeHandler.java +++ b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/handler/AirParifBridgeHandler.java @@ -90,12 +90,15 @@ import org.slf4j.LoggerFactory; public class AirParifBridgeHandler extends BaseBridgeHandler implements HandlerUtils { private static final int REQUEST_TIMEOUT_MS = (int) TimeUnit.SECONDS.toMillis(30); private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; + private static final String AQ_JOB = "Air Quality Bulletin"; + private static final String POLLENS_JOB = "Pollens Update"; + private static final String EPISODE_JOB = "Episode"; private final Logger logger = LoggerFactory.getLogger(AirParifBridgeHandler.class); + private final Map> jobs = new HashMap<>(); private final AirParifDeserializer deserializer; private final AirParifIconProvider iconProvider; private final HttpClient httpClient; - private final Map> jobs = new HashMap<>(); private BridgeConfiguration config = new BridgeConfiguration(); private @Nullable PollensResponse pollens; @@ -173,7 +176,7 @@ public class AirParifBridgeHandler extends BaseBridgeHandler implements HandlerU @Override public void handleCommand(ChannelUID channelUID, Command command) { - logger.debug("The AirParif bridge does not handles commands"); + logger.debug("The AirParif bridge does not handle commands"); } private void initiateConnexion() { @@ -209,11 +212,10 @@ public class AirParifBridgeHandler extends BaseBridgeHandler implements HandlerU ThingUID thingUID = thing.getUID(); - schedule("Pollens Update", () -> updatePollens(new ChannelGroupUID(thingUID, GROUP_POLLENS)), - Duration.ofSeconds(1)); - schedule("Air Quality Bulletin", () -> updateDailyAQBulletin(new ChannelGroupUID(thingUID, GROUP_AQ_BULLETIN), + schedule(POLLENS_JOB, () -> updatePollens(new ChannelGroupUID(thingUID, GROUP_POLLENS)), Duration.ofSeconds(1)); + schedule(AQ_JOB, () -> updateDailyAQBulletin(new ChannelGroupUID(thingUID, GROUP_AQ_BULLETIN), new ChannelGroupUID(thingUID, GROUP_AQ_BULLETIN_TOMORROW)), Duration.ofSeconds(2)); - schedule("Episode", () -> updateEpisode(new ChannelGroupUID(thingUID, GROUP_DAILY)), Duration.ofSeconds(3)); + schedule(EPISODE_JOB, () -> updateEpisode(new ChannelGroupUID(thingUID, GROUP_DAILY)), Duration.ofSeconds(3)); } private void updatePollens(ChannelGroupUID pollensGroupUID) { @@ -235,7 +237,7 @@ public class AirParifBridgeHandler extends BaseBridgeHandler implements HandlerU long delay = localPollens.getValidityDuration().getSeconds(); // if delay is null, update in 3600 seconds delay += delay == 0 ? 3600 : 60; - schedule("Pollens Update", () -> updatePollens(pollensGroupUID), Duration.ofSeconds(delay)); + schedule(POLLENS_JOB, () -> updatePollens(pollensGroupUID), Duration.ofSeconds(delay)); // Send pollens information to childs getThing().getThings().stream().map(Thing::getHandler).filter(LocationHandler.class::isInstance) @@ -269,7 +271,7 @@ public class AirParifBridgeHandler extends BaseBridgeHandler implements HandlerU ZonedDateTime tomorrowMorning = ZonedDateTime.now().plusDays(1).truncatedTo(ChronoUnit.DAYS).plusMinutes(1); logger.debug("Rescheduling daily air quality bulletin job tomorrow morning"); - schedule("Air Quality Bulletin", () -> updateDailyAQBulletin(todayGroupUID, tomorrowGroupUID), + schedule(AQ_JOB, () -> updateDailyAQBulletin(todayGroupUID, tomorrowGroupUID), Duration.between(ZonedDateTime.now(), tomorrowMorning)); } @@ -292,7 +294,8 @@ public class AirParifBridgeHandler extends BaseBridgeHandler implements HandlerU // }); ZonedDateTime tomorrowMorning = ZonedDateTime.now().plusDays(1).truncatedTo(ChronoUnit.DAYS).plusMinutes(1); - schedule("Episode", () -> updateEpisode(dailyGroupUID), Duration.between(ZonedDateTime.now(), tomorrowMorning)); + schedule(EPISODE_JOB, () -> updateEpisode(dailyGroupUID), + Duration.between(ZonedDateTime.now(), tomorrowMorning)); } public @Nullable Route getConcentrations(String location) { diff --git a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/handler/LocationHandler.java b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/handler/LocationHandler.java index 3407afe2a09..f84175eff5b 100755 --- a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/handler/LocationHandler.java +++ b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/handler/LocationHandler.java @@ -49,12 +49,13 @@ import org.slf4j.LoggerFactory; */ @NonNullByDefault public class LocationHandler extends BaseThingHandler implements HandlerUtils { + private static final String AQ_JOB = "Local Air Quality"; private final Logger logger = LoggerFactory.getLogger(LocationHandler.class); private final Map> jobs = new HashMap<>(); - private @Nullable LocationConfiguration config; private Map myPollens = Map.of(); + private @Nullable LocationConfiguration config; public LocationHandler(Thing thing) { super(thing); @@ -64,7 +65,7 @@ public class LocationHandler extends BaseThingHandler implements HandlerUtils { public void initialize() { config = getConfigAs(LocationConfiguration.class); updateStatus(ThingStatus.UNKNOWN); - schedule("Local Air Quality", this::getConcentrations, Duration.ofSeconds(2)); + schedule(AQ_JOB, this::getConcentrations, Duration.ofSeconds(2)); } @Override @@ -113,12 +114,12 @@ public class LocationHandler extends BaseThingHandler implements HandlerUtils { } else { delay = 10; } - schedule("Local Air Quality", this::getConcentrations, Duration.ofSeconds(delay)); + schedule(AQ_JOB, this::getConcentrations, Duration.ofSeconds(delay)); } @Override public void handleCommand(ChannelUID channelUID, Command command) { - // TODO Auto-generated method stub + logger.debug("This thing does not handle commands"); } @Override diff --git a/bundles/pom.xml b/bundles/pom.xml index 68102f6c939..8f1a5024627 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -48,6 +48,7 @@ org.openhab.binding.adorne org.openhab.binding.ahawastecollection org.openhab.binding.airgradient + org.openhab.binding.airparif org.openhab.binding.airq org.openhab.binding.airquality org.openhab.binding.airvisualnode