[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
parent
ff617aceae
commit
b4a7c433f2
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,25 +133,30 @@ 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();
|
||||||
Character.getNumericValue(code[0]), Character.getNumericValue(code[1]),
|
if (areaNumber == -1) {
|
||||||
Character.getNumericValue(code[2]), Character.getNumericValue(code[3]));
|
logger.warn("Could not identify area, canceling bypass/restore command!");
|
||||||
/*
|
|
||||||
* 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 {
|
} else {
|
||||||
logger.warn("System reported an invalid code");
|
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!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Received null bridge while sending zone command!");
|
logger.debug("Received null bridge while sending zone command!");
|
||||||
|
|
Loading…
Reference in New Issue