Search in sources :

Example 6 with PowerMaxState

use of org.openhab.binding.powermax.internal.state.PowerMaxState in project openhab1-addons by openhab.

the class PowerMaxBinding method updateItemsFromAlarmState.

/**
     * Post item updates on the bus to match a new alarm system state
     *
     * @param provider
     *            filter on provider; if null, no filter on provider
     * @param name
     *            filter on item name; if null, no filter on item name
     * @param selector
     *            filter on selector type; if null, no filter on selector type
     * @param state
     *            the alarm system state
     */
private synchronized void updateItemsFromAlarmState(PowerMaxBindingProvider provider, String name, PowerMaxSelectorType selector, PowerMaxState state) {
    if (state == null) {
        return;
    }
    if (itemUpdateDisabled) {
        logger.debug("updateItemsFromAlarmState(): items update disabled");
        return;
    }
    if (provider == null) {
        for (PowerMaxBindingProvider prov : providers) {
            if (prov != null) {
                updateItemsFromAlarmState(prov, name, selector, state);
            }
        }
    } else {
        for (String itemName : provider.getItemNames()) {
            if ((name == null) || itemName.equals(name)) {
                String value = null;
                String value2 = null;
                PowerMaxBindingConfig config = provider.getConfig(itemName);
                Integer num = config.getSelectorIntParam();
                if ((selector == null) || (selector == config.getSelectorType())) {
                    switch(config.getSelectorType()) {
                        case PANEL_MODE:
                            value = state.getPanelMode();
                            break;
                        case PARTITION_STATUS:
                            value = state.getStatusStr();
                            break;
                        case PARTITION_READY:
                            if (state.isReady() != null) {
                                value = state.isReady() ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case PARTITION_BYPASS:
                            if (state.isBypass() != null) {
                                value = state.isBypass() ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case PARTITION_ALARM:
                            if (state.isAlarmActive() != null) {
                                value = state.isAlarmActive() ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case PANEL_TROUBLE:
                            if (state.isTrouble() != null) {
                                value = state.isTrouble() ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case PANEL_ALERT_IN_MEMORY:
                            if (state.isAlertInMemory() != null) {
                                value = state.isAlertInMemory() ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case EVENT_LOG:
                            if ((num != null) && (state.getEventLog(num) != null)) {
                                value = state.getEventLog(num);
                            }
                            break;
                        case PARTITION_ARMED:
                            if (state.isArmed() != null) {
                                value = state.isArmed() ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case PARTITION_ARM_MODE:
                            value = state.getShortArmMode();
                            break;
                        case ZONE_STATUS:
                            if ((num != null) && (state.isSensorTripped(num) != null)) {
                                value = state.isSensorTripped(num) ? OpenClosedType.OPEN.toString() : OpenClosedType.CLOSED.toString();
                                value2 = state.isSensorTripped(num) ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case ZONE_LAST_TRIP:
                            if ((num != null) && (state.getSensorLastTripped(num) != null)) {
                                Calendar cal = Calendar.getInstance();
                                cal.setTimeInMillis(state.getSensorLastTripped(num));
                                value = new DateTimeType(cal).toString();
                            }
                            break;
                        case ZONE_BYPASSED:
                            if ((num != null) && (state.isSensorBypassed(num) != null)) {
                                value = state.isSensorBypassed(num) ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case ZONE_ARMED:
                            if ((num != null) && (state.isSensorArmed(num) != null)) {
                                value = state.isSensorArmed(num) ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case ZONE_LOW_BATTERY:
                            if ((num != null) && (state.isSensorLowBattery(num) != null)) {
                                value = state.isSensorLowBattery(num) ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case PGM_STATUS:
                            if (state.getPGMX10DeviceStatus(0) != null) {
                                value = state.getPGMX10DeviceStatus(0) ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        case X10_STATUS:
                            if ((num != null) && (state.getPGMX10DeviceStatus(num) != null)) {
                                value = state.getPGMX10DeviceStatus(num) ? OnOffType.ON.toString() : OnOffType.OFF.toString();
                            }
                            break;
                        default:
                            break;
                    }
                }
                State itemState = null;
                if (value != null) {
                    itemState = TypeParser.parseState(config.getAcceptedDataTypes(), value);
                }
                if ((itemState == null) && (value2 != null)) {
                    itemState = TypeParser.parseState(config.getAcceptedDataTypes(), value2);
                }
                if (itemState != null) {
                    eventPublisher.postUpdate(itemName, itemState);
                }
            }
        }
    }
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) PowerMaxBindingConfig(org.openhab.binding.powermax.PowerMaxBindingConfig) PowerMaxState(org.openhab.binding.powermax.internal.state.PowerMaxState) State(org.openhab.core.types.State) Calendar(java.util.Calendar) PowerMaxBindingProvider(org.openhab.binding.powermax.PowerMaxBindingProvider)

Example 7 with PowerMaxState

use of org.openhab.binding.powermax.internal.state.PowerMaxState in project openhab1-addons by openhab.

the class PowerMaxAckMessage method handleMessage.

/**
     * {@inheritDoc}
     */
@Override
public PowerMaxState handleMessage() {
    super.handleMessage();
    PowerMaxState updatedState = null;
    if (PowerMaxCommDriver.getTheCommDriver().getLastSendMsg().getSendType() == PowerMaxSendType.EXIT) {
        updatedState = new PowerMaxState();
        updatedState.setPowerlinkMode(true);
        updatedState.setDownloadMode(false);
    }
    return updatedState;
}
Also used : PowerMaxState(org.openhab.binding.powermax.internal.state.PowerMaxState)

Example 8 with PowerMaxState

use of org.openhab.binding.powermax.internal.state.PowerMaxState in project openhab1-addons by openhab.

the class PowerMaxDeniedMessage method handleMessage.

/**
     * {@inheritDoc}
     */
@Override
public PowerMaxState handleMessage() {
    super.handleMessage();
    PowerMaxState updatedState = null;
    PowerMaxSendType lastSendType = PowerMaxCommDriver.getTheCommDriver().getLastSendMsg().getSendType();
    if (lastSendType == PowerMaxSendType.EVENTLOG || lastSendType == PowerMaxSendType.ARM || lastSendType == PowerMaxSendType.BYPASS) {
        logger.warn("PowerMax alarm binding: invalid PIN code");
    } else if (lastSendType == PowerMaxSendType.DOWNLOAD) {
        logger.warn("PowerMax alarm binding: openHAB Powerlink not enrolled");
        updatedState = new PowerMaxState();
        updatedState.setPowerlinkMode(false);
    }
    return updatedState;
}
Also used : PowerMaxState(org.openhab.binding.powermax.internal.state.PowerMaxState)

Example 9 with PowerMaxState

use of org.openhab.binding.powermax.internal.state.PowerMaxState in project openhab1-addons by openhab.

the class PowerMaxInfoMessage method handleMessage.

/**
     * {@inheritDoc}
     */
@Override
public PowerMaxState handleMessage() {
    super.handleMessage();
    PowerMaxState updatedState = new PowerMaxState();
    byte[] message = getRawData();
    PowerMaxPanelType panelType = null;
    try {
        panelType = PowerMaxPanelType.fromCode(message[7]);
    } catch (IllegalArgumentException e) {
        logger.warn("PowerMax alarm binding: unknwon panel type for code {}", message[7] & 0x000000FF);
        panelType = null;
    }
    logger.debug("Reading panel settings");
    updatedState.setDownloadMode(true);
    PowerMaxCommDriver comm = PowerMaxCommDriver.getTheCommDriver();
    comm.sendMessage(PowerMaxSendType.DL_PANELFW);
    comm.sendMessage(PowerMaxSendType.DL_SERIAL);
    comm.sendMessage(PowerMaxSendType.DL_ZONESTR);
    if (isAutoSyncTime()) {
        comm.sendSetTime();
    }
    if ((panelType != null) && panelType.isPowerMaster()) {
        comm.sendMessage(PowerMaxSendType.DL_MR_SIRKEYZON);
    }
    comm.sendMessage(PowerMaxSendType.START);
    comm.sendMessage(PowerMaxSendType.EXIT);
    return updatedState;
}
Also used : PowerMaxPanelType(org.openhab.binding.powermax.internal.state.PowerMaxPanelType) PowerMaxState(org.openhab.binding.powermax.internal.state.PowerMaxState)

Example 10 with PowerMaxState

use of org.openhab.binding.powermax.internal.state.PowerMaxState in project openhab1-addons by openhab.

the class PowerMaxPowerlinkMessage method handleMessage.

/**
     * {@inheritDoc}
     */
@Override
public PowerMaxState handleMessage() {
    super.handleMessage();
    PowerMaxState updatedState = null;
    byte[] message = getRawData();
    byte subType = message[2];
    PowerMaxCommDriver comm = PowerMaxCommDriver.getTheCommDriver();
    if (subType == 0x03) {
        // keep alive message
        comm.sendAck(this, (byte) 0x02);
        updatedState = new PowerMaxState();
        updatedState.setLastKeepAlive(System.currentTimeMillis());
    } else if (subType == 0x0A && message[4] == 0x01) {
        logger.info("PowerMax alarm binding: Enrolling Powerlink");
        comm.enrollPowerlink();
        updatedState = new PowerMaxState();
        updatedState.setDownloadSetupRequired(true);
    } else {
        comm.sendAck(this, (byte) 0x02);
    }
    return updatedState;
}
Also used : PowerMaxState(org.openhab.binding.powermax.internal.state.PowerMaxState)

Aggregations

PowerMaxState (org.openhab.binding.powermax.internal.state.PowerMaxState)11 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 PowerMaxBindingConfig (org.openhab.binding.powermax.PowerMaxBindingConfig)1 PowerMaxBindingProvider (org.openhab.binding.powermax.PowerMaxBindingProvider)1 PowerMaxEvent (org.openhab.binding.powermax.internal.connector.PowerMaxEvent)1 PowerMaxBaseMessage (org.openhab.binding.powermax.internal.message.PowerMaxBaseMessage)1 PowerMaxInfoMessage (org.openhab.binding.powermax.internal.message.PowerMaxInfoMessage)1 PowerMaxPanelSettings (org.openhab.binding.powermax.internal.state.PowerMaxPanelSettings)1 PowerMaxPanelType (org.openhab.binding.powermax.internal.state.PowerMaxPanelType)1 PowerMaxZoneSettings (org.openhab.binding.powermax.internal.state.PowerMaxZoneSettings)1 DateTimeType (org.openhab.core.library.types.DateTimeType)1 State (org.openhab.core.types.State)1