[OmniLink] Fix zone bypass/restore commands (#11005)

* Fix zone bypass/restore commands
* Name variables using openHAB guidelines

Signed-off-by: Ethan Dye <mrtops03@gmail.com>
This commit is contained in:
Ethan Dye 2021-07-17 00:54:34 -06:00 committed by GitHub
parent ff617aceae
commit b4a7c433f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 22 deletions

View File

@ -118,6 +118,11 @@ public abstract class AbstractOmnilinkHandler extends BaseThingHandler {
* @return Configured area number for a thing. * @return Configured area number for a thing.
*/ */
protected int getAreaNumber() { protected int getAreaNumber() {
return ((Number) getThing().getConfiguration().get(THING_PROPERTIES_AREA)).intValue(); String areaNumber = getThing().getProperties().get(THING_PROPERTIES_AREA);
if (areaNumber != null) {
return Integer.valueOf(areaNumber);
} else {
return -1;
}
} }
} }

View File

@ -50,7 +50,7 @@ import com.digitaldan.jomnilinkII.OmniUnknownMessageTypeException;
@NonNullByDefault @NonNullByDefault
public class AudioSourceHandler extends AbstractOmnilinkHandler { public class AudioSourceHandler extends AbstractOmnilinkHandler {
private final Logger logger = LoggerFactory.getLogger(AudioSourceHandler.class); private final Logger logger = LoggerFactory.getLogger(AudioSourceHandler.class);
private final int POLL_DELAY_SECONDS = 5; private final int pollDelaySeconds = 5;
private final int thingID = getThingNumber(); private final int thingID = getThingNumber();
private @Nullable ScheduledFuture<?> scheduledPolling = null; private @Nullable ScheduledFuture<?> scheduledPolling = null;
public @Nullable String number; public @Nullable String number;
@ -104,7 +104,7 @@ public class AudioSourceHandler extends AbstractOmnilinkHandler {
private synchronized void schedulePolling() { private synchronized void schedulePolling() {
cancelPolling(); cancelPolling();
logger.debug("Scheduling polling for Audio Source: {}", thingID); logger.debug("Scheduling polling for Audio Source: {}", thingID);
scheduledPolling = super.scheduler.scheduleWithFixedDelay(this::pollAudioSource, 0, POLL_DELAY_SECONDS, scheduledPolling = super.scheduler.scheduleWithFixedDelay(this::pollAudioSource, 0, pollDelaySeconds,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }

View File

@ -125,7 +125,6 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedZoneStatu
default: default:
mode = -1; mode = -1;
} }
int areaNumber = getAreaNumber();
logger.debug("mode {} on zone {} with code {}", mode, thingID, command.toFullString()); logger.debug("mode {} on zone {} with code {}", mode, thingID, command.toFullString());
char[] code = command.toFullString().toCharArray(); char[] code = command.toFullString().toCharArray();
if (code.length != 4) { if (code.length != 4) {
@ -134,7 +133,11 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedZoneStatu
try { try {
final OmnilinkBridgeHandler bridge = getOmnilinkBridgeHandler(); final OmnilinkBridgeHandler bridge = getOmnilinkBridgeHandler();
if (bridge != null) { if (bridge != null) {
SecurityCodeValidation codeValidation = bridge.reqSecurityCodeValidation(areaNumber, int areaNumber = getAreaNumber();
if (areaNumber == -1) {
logger.warn("Could not identify area, canceling bypass/restore command!");
} else {
SecurityCodeValidation codeValidation = bridge.reqSecurityCodeValidation(getAreaNumber(),
Character.getNumericValue(code[0]), Character.getNumericValue(code[1]), Character.getNumericValue(code[0]), Character.getNumericValue(code[1]),
Character.getNumericValue(code[2]), Character.getNumericValue(code[3])); Character.getNumericValue(code[2]), Character.getNumericValue(code[3]));
/* /*
@ -152,7 +155,8 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedZoneStatu
&& codeValidation.getAuthorityLevel() > 0) { && codeValidation.getAuthorityLevel() > 0) {
sendOmnilinkCommand(mode, codeValidation.getCodeNumber(), thingID); sendOmnilinkCommand(mode, codeValidation.getCodeNumber(), thingID);
} else { } else {
logger.warn("System reported an invalid code"); logger.warn("System reported an invalid code!");
}
} }
} else { } else {
logger.debug("Received null bridge while sending zone command!"); logger.debug("Received null bridge while sending zone command!");