[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>
pull/11009/head
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.
*/
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
public class AudioSourceHandler extends AbstractOmnilinkHandler {
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 @Nullable ScheduledFuture<?> scheduledPolling = null;
public @Nullable String number;
@ -104,7 +104,7 @@ public class AudioSourceHandler extends AbstractOmnilinkHandler {
private synchronized void schedulePolling() {
cancelPolling();
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);
}

View File

@ -125,7 +125,6 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedZoneStatu
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) {
@ -134,7 +133,11 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedZoneStatu
try {
final OmnilinkBridgeHandler bridge = getOmnilinkBridgeHandler();
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[2]), Character.getNumericValue(code[3]));
/*
@ -152,7 +155,8 @@ public class ZoneHandler extends AbstractOmnilinkStatusHandler<ExtendedZoneStatu
&& 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!");