Search in sources :

Example 1 with DSCAlarmBindingConfig

use of org.openhab.binding.dscalarm.DSCAlarmBindingConfig in project openhab1-addons by openhab.

the class DSCAlarmActiveBinding method getItemName.

/**
     * Searches for an items name and returns it
     *
     * @param dscAlarmItemType
     * @param partitionId
     * @param zoneId
     * @return itemName
     */
private String getItemName(DSCAlarmItemType dscAlarmItemType, int partitionId, int zoneId) {
    String itemName = "";
    DSCAlarmBindingConfig config = null;
    for (DSCAlarmBindingProvider prov : providers) {
        for (String iName : prov.getItemNames()) {
            config = prov.getDSCAlarmBindingConfig(iName);
            if (config.getDSCAlarmItemType() == dscAlarmItemType) {
                if (partitionId == -1) {
                    if (config.getZoneId() == zoneId) {
                        itemName = iName;
                        break;
                    }
                } else if (zoneId == -1) {
                    if (config.getPartitionId() == partitionId) {
                        itemName = iName;
                        break;
                    }
                } else if ((config.getPartitionId() == partitionId) && (config.getZoneId() == zoneId)) {
                    itemName = iName;
                    break;
                }
            }
        }
    }
    return itemName;
}
Also used : DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig)

Example 2 with DSCAlarmBindingConfig

use of org.openhab.binding.dscalarm.DSCAlarmBindingConfig in project openhab1-addons by openhab.

the class DSCAlarmActiveBinding method buildUpdateMap.

/**
     * Build the Update Items Map
     */
private void buildUpdateMap() {
    DSCAlarmBindingConfig config;
    for (DSCAlarmBindingProvider prov : providers) {
        if (!prov.getItemNames().isEmpty()) {
            itemCount = prov.getItemNames().size();
            dscAlarmUpdateMap.clear();
            for (String iName : prov.getItemNames()) {
                config = prov.getDSCAlarmBindingConfig(iName);
                if (config != null) {
                    dscAlarmUpdateMap.put(iName, config);
                }
            }
        }
    }
}
Also used : DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig)

Example 3 with DSCAlarmBindingConfig

use of org.openhab.binding.dscalarm.DSCAlarmBindingConfig in project openhab1-addons by openhab.

the class DSCAlarmActiveBinding method handleDSCAlarmEvent.

/**
     * Handle incoming DSC Alarm events
     *
     * @param dscAlarmItemType
     * @param dscAlarmEvent
     * @param apiMessage
     */
private void handleDSCAlarmEvent(DSCAlarmItemType dscAlarmItemType, DSCAlarmEvent dscAlarmEvent, APIMessage apiMessage) {
    logger.debug("handleDSCAlarmEvent(): Event received! Looking for item: {}", dscAlarmItemType);
    DSCAlarmBindingConfig config = null;
    APIMessage.APIMessageType apiMessageType = apiMessage.getAPIMessageType();
    Item item = null;
    String itemName = "";
    int partitionId = apiMessage.getPartition();
    int zoneId = apiMessage.getZone();
    if (dscAlarmItemType != null) {
        for (DSCAlarmBindingProvider prov : providers) {
            for (String iName : prov.getItemNames()) {
                config = prov.getDSCAlarmBindingConfig(iName);
                if (config != null) {
                    switch(apiMessageType) {
                        case PANEL_EVENT:
                            if (dscAlarmItemType == config.getDSCAlarmItemType()) {
                                itemName = iName;
                            }
                            break;
                        case PARTITION_EVENT:
                            if (partitionId == config.getPartitionId() && dscAlarmItemType == config.getDSCAlarmItemType()) {
                                itemName = iName;
                            }
                            break;
                        case ZONE_EVENT:
                            if (zoneId == config.getZoneId() && dscAlarmItemType == config.getDSCAlarmItemType()) {
                                itemName = iName;
                            }
                            break;
                        case KEYPAD_EVENT:
                            if (dscAlarmItemType == config.getDSCAlarmItemType()) {
                                itemName = iName;
                            }
                            break;
                        default:
                            break;
                    }
                }
                if (StringUtils.isNotEmpty(itemName)) {
                    item = prov.getItem(itemName);
                    dscAlarmItemUpdate.updateDeviceItem(item, config, eventPublisher, dscAlarmEvent, 0, "");
                    pollTimeStart = 0;
                    return;
                }
            }
        }
    }
}
Also used : Item(org.openhab.core.items.Item) DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig) APIMessage(org.openhab.binding.dscalarm.internal.protocol.APIMessage)

Example 4 with DSCAlarmBindingConfig

use of org.openhab.binding.dscalarm.DSCAlarmBindingConfig in project openhab1-addons by openhab.

the class DSCAlarmActiveBinding method updateItem.

/**
     * Update an item by item name
     *
     * @param itemName
     */
private void updateItem(String itemName, int state, String description) {
    DSCAlarmBindingConfig config = null;
    Item item = null;
    for (DSCAlarmBindingProvider prov : providers) {
        for (String iName : prov.getItemNames()) {
            if (itemName == iName) {
                config = prov.getDSCAlarmBindingConfig(iName);
                if (config != null) {
                    item = prov.getItem(itemName);
                    dscAlarmItemUpdate.updateDeviceItem(item, config, eventPublisher, null, state, description);
                    break;
                }
            }
        }
    }
}
Also used : Item(org.openhab.core.items.Item) DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig)

Example 5 with DSCAlarmBindingConfig

use of org.openhab.binding.dscalarm.DSCAlarmBindingConfig in project openhab1-addons by openhab.

the class DSCAlarmActiveBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    DSCAlarmBindingConfig dscAlarmBindingConfig = null;
    for (DSCAlarmBindingProvider prov : providers) {
        dscAlarmBindingConfig = prov.getDSCAlarmBindingConfig(itemName);
        if (dscAlarmBindingConfig != null) {
            DSCAlarmDeviceType dscAlarmDeviceType = dscAlarmBindingConfig.getDeviceType();
            int partitionId;
            int zoneId;
            int cmd;
            logger.debug("internalReceiveCommand():  Item Name: {} Command: {} Item Device Type: {}", itemName, command, dscAlarmDeviceType);
            if (connected) {
                switch(dscAlarmDeviceType) {
                    case PANEL:
                        switch(dscAlarmBindingConfig.getDSCAlarmItemType()) {
                            case PANEL_CONNECTION:
                                if (command.toString().equals("0")) {
                                    closeConnection();
                                    if (!connected) {
                                        dscAlarmItemUpdate.setConnected(false);
                                    }
                                }
                                break;
                            case PANEL_COMMAND:
                                cmd = Integer.parseInt(command.toString());
                                switch(cmd) {
                                    case 0:
                                        api.sendCommand(APICode.Poll);
                                        break;
                                    case 1:
                                        api.sendCommand(APICode.StatusReport);
                                        break;
                                    case 2:
                                        api.sendCommand(APICode.LabelsRequest);
                                        break;
                                    case 8:
                                        api.sendCommand(APICode.DumpZoneTimers);
                                        break;
                                    case 10:
                                        api.sendCommand(APICode.SetTimeDate);
                                        break;
                                    case 200:
                                        api.sendCommand(APICode.CodeSend);
                                        break;
                                    default:
                                        break;
                                }
                                itemName = getItemName(DSCAlarmItemType.PANEL_COMMAND, 0, 0);
                                if (StringUtils.isNotEmpty(itemName)) {
                                    updateItem(itemName, -1, "");
                                }
                                break;
                            case PANEL_TIME_STAMP:
                                if (command instanceof OnOffType) {
                                    cmd = command == OnOffType.ON ? 1 : 0;
                                    api.sendCommand(APICode.TimeStampControl, String.valueOf(cmd));
                                    updateItem(itemName, cmd, "");
                                }
                                break;
                            case PANEL_TIME_BROADCAST:
                                if (command instanceof OnOffType) {
                                    cmd = command == OnOffType.ON ? 1 : 0;
                                    api.sendCommand(APICode.TimeDateBroadcastControl, String.valueOf(cmd));
                                    updateItem(itemName, cmd, "");
                                }
                                break;
                            default:
                                break;
                        }
                        break;
                    case PARTITION:
                        partitionId = dscAlarmBindingConfig.getPartitionId();
                        switch(dscAlarmBindingConfig.getDSCAlarmItemType()) {
                            case PARTITION_ARM_MODE:
                                if (command.toString().equals("0")) {
                                    api.sendCommand(APICode.PartitionDisarmControl, String.valueOf(partitionId));
                                } else if (command.toString().equals("1")) {
                                    api.sendCommand(APICode.PartitionArmControlAway, String.valueOf(partitionId));
                                } else if (command.toString().equals("2")) {
                                    api.sendCommand(APICode.PartitionArmControlStay, String.valueOf(partitionId));
                                } else if (command.toString().equals("3")) {
                                    api.sendCommand(APICode.PartitionArmControlZeroEntryDelay, String.valueOf(partitionId));
                                } else if (command.toString().equals("4")) {
                                    api.sendCommand(APICode.PartitionArmControlWithUserCode, String.valueOf(partitionId));
                                }
                                break;
                            default:
                                break;
                        }
                        break;
                    case ZONE:
                        partitionId = dscAlarmBindingConfig.getPartitionId();
                        zoneId = dscAlarmBindingConfig.getZoneId();
                        switch(dscAlarmBindingConfig.getDSCAlarmItemType()) {
                            case ZONE_BYPASS_MODE:
                                if (command.toString().equals("0")) {
                                    String data = String.valueOf(partitionId) + "*1" + String.format("%02d", zoneId) + "#";
                                    api.sendCommand(APICode.KeySequence, data);
                                } else if (command.toString().equals("1")) {
                                    String data = String.valueOf(partitionId) + "*1" + String.format("%02d", zoneId) + "#";
                                    api.sendCommand(APICode.KeySequence, data);
                                }
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        logger.debug("internalReceiveCommand(): No Command Sent.");
                        break;
                }
            } else {
                if (dscAlarmDeviceType == DSCAlarmDeviceType.PANEL) {
                    if (dscAlarmBindingConfig.getDSCAlarmItemType() == DSCAlarmItemType.PANEL_CONNECTION) {
                        if (command.toString().equals("1")) {
                            if (api != null) {
                                openConnection();
                                if (connected) {
                                    dscAlarmItemUpdate.setConnected(true);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : DSCAlarmBindingProvider(org.openhab.binding.dscalarm.DSCAlarmBindingProvider) OnOffType(org.openhab.core.library.types.OnOffType) DSCAlarmDeviceType(org.openhab.binding.dscalarm.internal.model.DSCAlarmDeviceType) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig)

Aggregations

DSCAlarmBindingConfig (org.openhab.binding.dscalarm.DSCAlarmBindingConfig)9 DSCAlarmBindingProvider (org.openhab.binding.dscalarm.DSCAlarmBindingProvider)7 Item (org.openhab.core.items.Item)4 DSCAlarmDeviceType (org.openhab.binding.dscalarm.internal.model.DSCAlarmDeviceType)2 OnOffType (org.openhab.core.library.types.OnOffType)2 HashMap (java.util.HashMap)1 APIMessage (org.openhab.binding.dscalarm.internal.protocol.APIMessage)1 State (org.openhab.core.types.State)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1