Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OmniLink] Fix zone bypass/restore commands #11005

Merged
merged 2 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ protected int getThingNumber() {
* @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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
@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;
Expand Down Expand Up @@ -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, POLL_DELAY_SECONDS,
scheduledPolling = super.scheduler.scheduleWithFixedDelay(this::pollAudioSource, 0, pollDelaySeconds,
TimeUnit.SECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ 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) {
Expand All @@ -134,25 +133,30 @@ public void handleCommand(ChannelUID channelUID, Command command) {
try {
final OmnilinkBridgeHandler bridge = getOmnilinkBridgeHandler();
if (bridge != null) {
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);
int areaNumber = getAreaNumber();
if (areaNumber == -1) {
logger.warn("Could not identify area, canceling bypass/restore command!");
} 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 {
logger.debug("Received null bridge while sending zone command!");
Expand Down