From 445e1fe8db5423b9bca70ea8b4256005bb946820 Mon Sep 17 00:00:00 2001 From: dw-8 Date: Sun, 25 Jul 2021 01:11:27 -0400 Subject: [PATCH] Revert "[OmniLink] Fix zone bypass/restore commands (#11005)" This reverts commit 72ca51ea60da9a9de234c29b0ca521e2c39b9213. Signed-off-by: dw-8 --- .../handler/AbstractOmnilinkHandler.java | 7 +--- .../internal/handler/AudioSourceHandler.java | 4 +- .../internal/handler/ZoneHandler.java | 42 +++++++++---------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java index 5374ad94828ba..587b253dc6b38 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java @@ -118,11 +118,6 @@ protected int getThingNumber() { * @return Configured area number for a thing. */ protected int getAreaNumber() { - String areaNumber = getThing().getProperties().get(THING_PROPERTIES_AREA); - if (areaNumber != null) { - return Integer.valueOf(areaNumber); - } else { - return -1; - } + return ((Number) getThing().getConfiguration().get(THING_PROPERTIES_AREA)).intValue(); } } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java index bec9db81d2357..b591bc685689c 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java @@ -50,7 +50,7 @@ @NonNullByDefault public class AudioSourceHandler extends AbstractOmnilinkHandler { private final Logger logger = LoggerFactory.getLogger(AudioSourceHandler.class); - private final int pollDelaySeconds = 5; + private final int POLL_DELAY_SECONDS = 5; private final int thingID = getThingNumber(); private @Nullable ScheduledFuture scheduledPolling = null; public @Nullable String number; @@ -104,7 +104,7 @@ private synchronized void cancelPolling() { private synchronized void schedulePolling() { cancelPolling(); logger.debug("Scheduling polling for Audio Source: {}", thingID); - scheduledPolling = super.scheduler.scheduleWithFixedDelay(this::pollAudioSource, 0, pollDelaySeconds, + scheduledPolling = super.scheduler.scheduleWithFixedDelay(this::pollAudioSource, 0, POLL_DELAY_SECONDS, TimeUnit.SECONDS); } diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ZoneHandler.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ZoneHandler.java index be9e6b2b3528e..8d07e9228716d 100644 --- a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ZoneHandler.java +++ b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ZoneHandler.java @@ -125,6 +125,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { default: mode = -1; } + int areaNumber = getAreaNumber(); logger.debug("mode {} on zone {} with code {}", mode, thingID, command.toFullString()); char[] code = command.toFullString().toCharArray(); if (code.length != 4) { @@ -133,30 +134,25 @@ public void handleCommand(ChannelUID channelUID, Command command) { try { final OmnilinkBridgeHandler bridge = getOmnilinkBridgeHandler(); if (bridge != null) { - int areaNumber = getAreaNumber(); - if (areaNumber == -1) { - logger.warn("Could not identify area, canceling bypass/restore command!"); + SecurityCodeValidation codeValidation = bridge.reqSecurityCodeValidation(areaNumber, + Character.getNumericValue(code[0]), Character.getNumericValue(code[1]), + Character.getNumericValue(code[2]), Character.getNumericValue(code[3])); + /* + * 0 Invalid code + * 1 Master + * 2 Manager + * 3 User + */ + logger.debug("User code number: {} level: {}", codeValidation.getCodeNumber(), + codeValidation.getAuthorityLevel()); + /* + * Valid user code number are 1-99, 251 is duress code, 0 means code does not exist + */ + if ((codeValidation.getCodeNumber() > 0 && codeValidation.getCodeNumber() <= 99) + && codeValidation.getAuthorityLevel() > 0) { + sendOmnilinkCommand(mode, codeValidation.getCodeNumber(), thingID); } else { - SecurityCodeValidation codeValidation = bridge.reqSecurityCodeValidation(getAreaNumber(), - Character.getNumericValue(code[0]), Character.getNumericValue(code[1]), - Character.getNumericValue(code[2]), Character.getNumericValue(code[3])); - /* - * 0 Invalid code - * 1 Master - * 2 Manager - * 3 User - */ - logger.debug("User code number: {} level: {}", codeValidation.getCodeNumber(), - codeValidation.getAuthorityLevel()); - /* - * Valid user code number are 1-99, 251 is duress code, 0 means code does not exist - */ - if ((codeValidation.getCodeNumber() > 0 && codeValidation.getCodeNumber() <= 99) - && codeValidation.getAuthorityLevel() > 0) { - sendOmnilinkCommand(mode, codeValidation.getCodeNumber(), thingID); - } else { - logger.warn("System reported an invalid code!"); - } + logger.warn("System reported an invalid code"); } } else { logger.debug("Received null bridge while sending zone command!");