Search in sources :

Example 1 with PowerMaxBindingConfig

use of org.openhab.binding.powermax.PowerMaxBindingConfig in project openhab1-addons by openhab.

the class PowerMaxBinding method updateItemsFromPanelSettings.

/**
     * Post item updates on the bus to match the alarm panel settings
     *
     * @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
     */
private synchronized void updateItemsFromPanelSettings(PowerMaxBindingProvider provider, String name, PowerMaxSelectorType selector) {
    if (itemUpdateDisabled) {
        logger.debug("updateItemsFromPanelSettings(): items update disabled");
        return;
    }
    if (provider == null) {
        for (PowerMaxBindingProvider prov : providers) {
            if (prov != null) {
                updateItemsFromPanelSettings(prov, name, selector);
            }
        }
    } else {
        PowerMaxPanelSettings settings = PowerMaxPanelSettings.getThePanelSettings();
        for (String itemName : provider.getItemNames()) {
            if ((name == null) || itemName.equals(name)) {
                String value = null;
                PowerMaxBindingConfig config = provider.getConfig(itemName);
                if ((selector == null) || (selector == config.getSelectorType())) {
                    switch(config.getSelectorType()) {
                        case PANEL_TYPE:
                            value = (settings.getPanelType() != null) ? settings.getPanelType().getLabel() : null;
                            break;
                        case PANEL_SERIAL:
                            value = settings.getPanelSerial();
                            break;
                        case PANEL_EPROM:
                            value = settings.getPanelEprom();
                            break;
                        case PANEL_SOFTWARE:
                            value = settings.getPanelSoftware();
                            break;
                        default:
                            break;
                    }
                }
                if (value != null) {
                    State itemState = TypeParser.parseState(config.getAcceptedDataTypes(), value);
                    if (itemState != null) {
                        eventPublisher.postUpdate(itemName, itemState);
                    }
                }
            }
        }
    }
}
Also used : PowerMaxBindingConfig(org.openhab.binding.powermax.PowerMaxBindingConfig) PowerMaxState(org.openhab.binding.powermax.internal.state.PowerMaxState) State(org.openhab.core.types.State) PowerMaxPanelSettings(org.openhab.binding.powermax.internal.state.PowerMaxPanelSettings) PowerMaxBindingProvider(org.openhab.binding.powermax.PowerMaxBindingProvider)

Example 2 with PowerMaxBindingConfig

use of org.openhab.binding.powermax.PowerMaxBindingConfig in project openhab1-addons by openhab.

the class PowerMaxGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    String[] selector = StringUtils.split(StringUtils.trim(bindingConfig), ':');
    try {
        PowerMaxSelectorType selectorType = PowerMaxSelectorType.fromString(selector[0]);
        String selectorParam = null;
        if (selector.length == 2) {
            selectorParam = selector[1];
        }
        PowerMaxBindingConfig config = new PowerMaxBindingConfig(selectorType, selectorParam, item);
        addBindingConfig(item, config);
    } catch (IllegalArgumentException e) {
        throw new BindingConfigParseException("item '" + item.getName() + "': parse error of string " + bindingConfig);
    }
}
Also used : PowerMaxBindingConfig(org.openhab.binding.powermax.PowerMaxBindingConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 3 with PowerMaxBindingConfig

use of org.openhab.binding.powermax.PowerMaxBindingConfig in project openhab1-addons by openhab.

the class PowerMaxBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    // the code being executed when a command was sent on the openHAB
    // event bus goes here. This method is only called if one of the
    // BindingProviders provide a binding for the given 'itemName'.
    logger.debug("internalReceiveCommand({},{}) is called", itemName, command);
    if (!isProperlyConfigured() || !connected) {
        logger.warn("PowerMax alarm binding is not properly configured. Command is ignored.");
        return;
    }
    String armMode = null;
    String actionPGMX10 = null;
    Byte devicePGMX10 = null;
    Boolean bypass = null;
    byte zoneNr = 0;
    String commandStr = null;
    PowerMaxPanelSettings settings = PowerMaxPanelSettings.getThePanelSettings();
    PowerMaxCommDriver comm = PowerMaxCommDriver.getTheCommDriver();
    for (PowerMaxBindingProvider provider : providers) {
        PowerMaxBindingConfig config = provider.getConfig(itemName);
        if (config == null) {
            continue;
        }
        switch(config.getSelectorType()) {
            case PARTITION_ARM_MODE:
                if (command instanceof StringType) {
                    armMode = command.toString();
                }
                break;
            case PARTITION_ARMED:
                if (command instanceof OnOffType) {
                    armMode = command.equals(OnOffType.ON) ? "Armed" : "Disarmed";
                }
                break;
            case PGM_STATUS:
                if (command instanceof OnOffType) {
                    actionPGMX10 = command.toString();
                }
                break;
            case X10_STATUS:
                if (command instanceof OnOffType || command instanceof StringType) {
                    actionPGMX10 = command.toString();
                }
                try {
                    devicePGMX10 = Byte.parseByte(config.getSelectorParam());
                } catch (NumberFormatException e) {
                    logger.warn("PowerMax alarm binding: invalid X10 device id: {}", config.getSelectorParam());
                    actionPGMX10 = null;
                }
                break;
            case ZONE_BYPASSED:
                if (command instanceof OnOffType) {
                    bypass = command.equals(OnOffType.ON) ? Boolean.TRUE : Boolean.FALSE;
                }
                try {
                    zoneNr = Byte.parseByte(config.getSelectorParam());
                } catch (NumberFormatException e) {
                    logger.warn("PowerMax alarm binding: invalid zone number: {}", config.getSelectorParam());
                    bypass = null;
                }
                break;
            case COMMAND:
                if (command instanceof StringType) {
                    commandStr = command.toString();
                    eventPublisher.postUpdate(itemName, new StringType(commandStr));
                }
                break;
            default:
                break;
        }
        if (armMode != null) {
            HashMap<String, Boolean> allowedModes = new HashMap<String, Boolean>();
            allowedModes.put("Disarmed", allowDisarming);
            allowedModes.put("Stay", allowArming);
            allowedModes.put("Armed", allowArming);
            allowedModes.put("StayInstant", allowArming);
            allowedModes.put("ArmedInstant", allowArming);
            allowedModes.put("Night", allowArming);
            allowedModes.put("NightInstant", allowArming);
            Boolean allowed = allowedModes.get(armMode);
            if ((allowed == null) || !allowed) {
                logger.warn("PowerMax alarm binding: rejected command {}", armMode);
            } else {
                comm.requestArmMode(armMode, currentState.isPowerlinkMode() ? PowerMaxPanelSettings.getThePanelSettings().getFirstPinCode() : pinCode);
            }
            break;
        } else if (actionPGMX10 != null) {
            comm.sendPGMX10(actionPGMX10, devicePGMX10);
            break;
        } else if (bypass != null) {
            if ((currentState.isPowerlinkMode() == null) || currentState.isPowerlinkMode().equals(Boolean.FALSE)) {
                logger.warn("PowerMax alarm binding: Bypass option only supported in Powerlink mode");
            } else if (!PowerMaxPanelSettings.getThePanelSettings().isBypassEnabled()) {
                logger.warn("PowerMax alarm binding: Bypass option not enabled in panel settings");
            } else {
                comm.sendZoneBypass(bypass.booleanValue(), zoneNr, PowerMaxPanelSettings.getThePanelSettings().getFirstPinCode());
            }
            break;
        } else if (commandStr != null) {
            if (commandStr.equalsIgnoreCase("get_event_log")) {
                comm.requestEventLog(currentState.isPowerlinkMode() ? PowerMaxPanelSettings.getThePanelSettings().getFirstPinCode() : pinCode);
            } else if (commandStr.equalsIgnoreCase("download_setup")) {
                if ((currentState.isPowerlinkMode() == null) || currentState.isPowerlinkMode().equals(Boolean.FALSE)) {
                    logger.warn("PowerMax alarm binding: download setup only supported in Powerlink mode");
                } else {
                    comm.startDownload();
                    if (currentState.getLastKeepAlive() != null) {
                        currentState.setLastKeepAlive(System.currentTimeMillis());
                    }
                }
            } else if (commandStr.equalsIgnoreCase("log_setup")) {
                settings.log();
            } else if (commandStr.equalsIgnoreCase("help_items")) {
                settings.helpItems();
            } else {
                logger.warn("PowerMax alarm binding: rejected command {}", commandStr);
            }
            break;
        }
    }
}
Also used : PowerMaxBindingConfig(org.openhab.binding.powermax.PowerMaxBindingConfig) StringType(org.openhab.core.library.types.StringType) HashMap(java.util.HashMap) PowerMaxCommDriver(org.openhab.binding.powermax.internal.message.PowerMaxCommDriver) OnOffType(org.openhab.core.library.types.OnOffType) PowerMaxPanelSettings(org.openhab.binding.powermax.internal.state.PowerMaxPanelSettings) PowerMaxBindingProvider(org.openhab.binding.powermax.PowerMaxBindingProvider)

Example 4 with PowerMaxBindingConfig

use of org.openhab.binding.powermax.PowerMaxBindingConfig 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)

Aggregations

PowerMaxBindingConfig (org.openhab.binding.powermax.PowerMaxBindingConfig)4 PowerMaxBindingProvider (org.openhab.binding.powermax.PowerMaxBindingProvider)3 PowerMaxPanelSettings (org.openhab.binding.powermax.internal.state.PowerMaxPanelSettings)2 PowerMaxState (org.openhab.binding.powermax.internal.state.PowerMaxState)2 State (org.openhab.core.types.State)2 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 PowerMaxCommDriver (org.openhab.binding.powermax.internal.message.PowerMaxCommDriver)1 DateTimeType (org.openhab.core.library.types.DateTimeType)1 OnOffType (org.openhab.core.library.types.OnOffType)1 StringType (org.openhab.core.library.types.StringType)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1