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

[powermax] Introduce some new channels for better status reporting #10624

Merged
merged 4 commits into from
Sep 8, 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 @@ -47,8 +47,11 @@ public class PowermaxBindingConstants {

// List of all Channel ids
public static final String MODE = "mode";
public static final String LAST_MESSAGE_TIME = "last_message_time";
public static final String ACTIVE_ALERTS = "active_alerts";
public static final String TROUBLE = "trouble";
public static final String ALERT_IN_MEMORY = "alert_in_memory";
public static final String RINGING = "ringing";
public static final String SYSTEM_STATUS = "system_status";
public static final String READY = "ready";
public static final String WITH_ZONES_BYPASSED = "with_zones_bypassed";
Expand All @@ -58,8 +61,14 @@ public class PowermaxBindingConstants {
public static final String TRIPPED = "tripped";
public static final String LAST_TRIP = "last_trip";
public static final String BYPASSED = "bypassed";
public static final String ALARMED = "alarmed";
public static final String TAMPER_ALARM = "tamper_alarm";
public static final String INACTIVE = "inactive";
public static final String TAMPERED = "tampered";
public static final String ARMED = "armed";
public static final String LOCKED = "locked";
public static final String ZONE_LAST_MESSAGE = "last_message";
public static final String ZONE_LAST_MESSAGE_TIME = "last_message_time";
public static final String LOW_BATTERY = "low_battery";
public static final String PGM_STATUS = "pgm_status";
public static final String X10_STATUS = "x10_status";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void initialize() {
try {
logger.trace("Powermax job...");
updateMotionSensorState();
updateRingingState();
if (isConnected()) {
checkKeepAlive();
commManager.retryDownloadSetup(remainingDownloadAttempts);
Expand Down Expand Up @@ -254,6 +255,23 @@ private void updateMotionSensorState() {
}
}

/**
* Turn off the Ringing flag when the bell time expires
*/
private void updateRingingState() {
if (currentState != null && Boolean.TRUE.equals(currentState.ringing.getValue())) {
long now = System.currentTimeMillis();
long bellTime = getPanelSettings().getBellTime() * ONE_MINUTE;

if ((currentState.ringingSince.getValue() + bellTime) < now) {
PowermaxState updateState = commManager.createNewState();
updateState.ringing.setValue(false);
updateChannelsFromAlarmState(RINGING, updateState);
currentState.merge(updateState);
}
}
}

/*
* Check that we're actively communicating with the panel
*/
Expand All @@ -266,8 +284,8 @@ private void checkKeepAlive() {
commManager.sendRestoreMessage();
currentState.lastKeepAlive.setValue(now);
} else if (!Boolean.TRUE.equals(currentState.downloadMode.getValue())
&& (currentState.lastMessageReceived.getValue() != null)
&& ((now - currentState.lastMessageReceived.getValue()) > FIVE_MINUTES)) {
&& (currentState.lastMessageTime.getValue() != null)
&& ((now - currentState.lastMessageTime.getValue()) > FIVE_MINUTES)) {
// In Standard mode: ping the panel every so often to detect disconnects
commManager.sendMessage(PowermaxSendType.STATUS);
}
Expand All @@ -281,6 +299,7 @@ private void tryReconnect() {
openConnection();
logger.debug("openConnection(): connected");
updateStatus(ThingStatus.ONLINE);
updateChannelsFromAlarmState(currentState);
ronisaacson marked this conversation as resolved.
Show resolved Hide resolved
if (forceStandardMode) {
currentState.powerlinkMode.setValue(false);
updateChannelsFromAlarmState(MODE, currentState);
Expand Down Expand Up @@ -455,12 +474,12 @@ public void onNewStateEvent(EventObject event) {

boolean doProcessSettings = (updateState.powerlinkMode.getValue() != null);

for (int i = 1; i <= getPanelSettings().getNbZones(); i++) {
getPanelSettings().getZoneRange().forEach(i -> {
if (Boolean.TRUE.equals(updateState.getZone(i).armed.getValue())
&& Boolean.TRUE.equals(currentState.getZone(i).bypassed.getValue())) {
updateState.getZone(i).armed.setValue(false);
}
}
});

updateState.keepOnlyDifferencesWith(currentState);
updateChannelsFromAlarmState(updateState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ public void updateChannelFromAlarmState(String channel, PowermaxState state) {
int num = getConfigAs(PowermaxZoneConfiguration.class).zoneNumber.intValue();

for (Value<?> value : state.getZone(num).getValues()) {
String v_channel = value.getChannel();
String vChannel = value.getChannel();

if (channel.equals(v_channel) && (value.getValue() != null)) {
updateState(v_channel, value.getState());
if (channel.equals(vChannel) && (value.getValue() != null)) {
updateState(vChannel, value.getState());
}
}
} else if (getThing().getThingTypeUID().equals(THING_TYPE_X10)) {
Expand Down Expand Up @@ -256,6 +256,9 @@ public void onZoneSettingsUpdated(int zoneNumber, @Nullable PowermaxPanelSetting
updateStatus(ThingStatus.ONLINE);
logger.debug("Set handler status to ONLINE for thing {} (zone number {} paired)",
getThing().getUID(), config.zoneNumber);

logger.debug("Using name '{}' for {}", getThing().getLabel(), getThing().getUID());
zoneSettings.setName(getThing().getLabel());
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void onNewMessageEvent(EventObject event) {
updateState = createNewState();
}

updateState.lastMessageReceived.setValue(System.currentTimeMillis());
updateState.lastMessageTime.setValue(System.currentTimeMillis());

if (updateState.getUpdateSettings() != null) {
panelSettings.updateRawSettings(updateState.getUpdateSettings());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected PowermaxState handleMessageInternal(PowermaxCommManager commManager) {
String timestamp = String.format("%02d/%02d/%04d %02d:%02d:%02d", day, month, year, hour, minute, second);
byte eventZone = message[10];
byte logEvent = message[11];
String logEventStr = PowermaxMessageConstants.getSystemEventString(logEvent & 0x000000FF);
String logUserStr = PowermaxMessageConstants.getZoneOrUserString(eventZone & 0x000000FF);
String logEventStr = PowermaxMessageConstants.getSystemEvent(logEvent & 0x000000FF).toString();
String logUserStr = panelSettings.getZoneOrUserName(eventZone & 0x000000FF);

String eventStr;
if (panelSettings.getPanelType().getPartitions() > 1) {
Expand Down
Loading