Skip to content

Commit

Permalink
[powermax] Introduce some new channels for better status reporting (#…
Browse files Browse the repository at this point in the history
…10624)

* [powermax] Introduce some new channels for better status reporting

* New panel channels:
    - Ringing indicator (the siren is currently sounding)
    - Date/time the last message was received from the panel
    - List of all active alarms and alerts (similar to panel's
      Memory list, but items get removed from the list as conditions
      resolve)
* New zone channels:
    - Alarmed indicator (zone is in alarm, or has an alarm in memory)
    - Tamper alarm indicator (same but for a tamper condition)
    - Inactive indicator
    - Tamper indicator (zone is actively tampered right now)
    - Last status message received for this zone, and when
* Use descriptive names for zones in log messages. If you create a
  Thing for a zone, it will use that Thing's label in all reporting
  for that zone. If there's no Thing then it will attempt to use the
  zone label from the panel (e.g. "Basement").
* Clear all channels during startup to keep from displaying stale
  values loaded from persistence
* Also includes some minor SAT fixes (checkstyle, spotbugs)

Signed-off-by: Ron Isaacson <isaacson.ron@gmail.com>

* Incorporate review feedback from lolodomo

Signed-off-by: Ron Isaacson <isaacson.ron@gmail.com>
  • Loading branch information
ronisaacson committed Sep 8, 2021
1 parent 0a1f23f commit d4983c4
Show file tree
Hide file tree
Showing 19 changed files with 794 additions and 277 deletions.
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);
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

0 comments on commit d4983c4

Please sign in to comment.