Search in sources :

Example 1 with DSCAlarmDeviceType

use of org.openhab.binding.dscalarm.internal.model.DSCAlarmDeviceType 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)

Example 2 with DSCAlarmDeviceType

use of org.openhab.binding.dscalarm.internal.model.DSCAlarmDeviceType in project openhab1-addons by openhab.

the class DSCAlarmItemUpdate method updateDeviceItem.

/**
     * Update a DSC Alarm Device Item
     *
     * @param item
     * @param config
     * @param eventPublisher
     * @param event
     */
public synchronized void updateDeviceItem(Item item, DSCAlarmBindingConfig config, EventPublisher eventPublisher, DSCAlarmEvent event, int state, String description) {
    logger.debug("updateDeviceItem(): Item Name: {}", item.getName());
    if (config != null) {
        DSCAlarmDeviceType dscAlarmDeviceType = config.getDeviceType();
        int panelId = 1;
        int partitionId;
        int zoneId;
        int keypadId = 1;
        switch(dscAlarmDeviceType) {
            case PANEL:
                Panel panel = null;
                // Right now we can only connect to one Panel so we only create a single Panel object;
                if (panelMap.isEmpty()) {
                    panel = new Panel(panelId);
                    panelMap.put(panelId, panel);
                } else {
                    panel = panelMap.get(1);
                }
                if (config.getDSCAlarmItemType() == DSCAlarmItemType.PANEL_CONNECTION) {
                    panel.refreshItem(item, config, eventPublisher, connected ? 1 : 0, "Panel Connected");
                    break;
                }
                if (event != null) {
                    panel.handleEvent(item, config, eventPublisher, event);
                } else {
                    panel.refreshItem(item, config, eventPublisher, state, description);
                }
                break;
            case PARTITION:
                partitionId = config.getPartitionId();
                Partition partition = partitionMap.get(partitionId);
                if (partition == null) {
                    partition = new Partition(partitionId);
                    partitionMap.put(partitionId, partition);
                }
                if (event != null) {
                    partition.handleEvent(item, config, eventPublisher, event);
                } else {
                    partition.refreshItem(item, config, eventPublisher, state, description);
                }
                break;
            case ZONE:
                partitionId = config.getPartitionId();
                zoneId = config.getZoneId();
                Zone zone = zoneMap.get(zoneId);
                if (zone == null) {
                    zone = new Zone(partitionId, zoneId);
                    zoneMap.put(zoneId, zone);
                }
                if (event != null) {
                    zone.handleEvent(item, config, eventPublisher, event);
                } else {
                    zone.refreshItem(item, config, eventPublisher, state, description);
                }
                break;
            case KEYPAD:
                Keypad keypad = null;
                // There is only one Keypad object per panel;
                if (keypadMap.isEmpty()) {
                    keypad = new Keypad(keypadId);
                    keypadMap.put(keypadId, keypad);
                } else {
                    keypad = keypadMap.get(1);
                }
                if (event != null) {
                    keypad.handleEvent(item, config, eventPublisher, event);
                } else {
                    keypad.refreshItem(item, config, eventPublisher, state, description);
                }
                break;
            default:
                logger.debug("updateDeviceItem(): Item not updated.");
                break;
        }
    }
}
Also used : Panel(org.openhab.binding.dscalarm.internal.model.Panel) Partition(org.openhab.binding.dscalarm.internal.model.Partition) Zone(org.openhab.binding.dscalarm.internal.model.Zone) DSCAlarmDeviceType(org.openhab.binding.dscalarm.internal.model.DSCAlarmDeviceType) Keypad(org.openhab.binding.dscalarm.internal.model.Keypad)

Example 3 with DSCAlarmDeviceType

use of org.openhab.binding.dscalarm.internal.model.DSCAlarmDeviceType in project openhab1-addons by openhab.

the class DSCAlarmGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    String[] sections = bindingConfig.split(":");
    if (sections.length < 2 || sections.length > 4) {
        throw new BindingConfigParseException("Invalid number of sections in the binding: " + bindingConfig);
    }
    DSCAlarmDeviceType dscAlarmDeviceType = null;
    int partitionId = 0;
    int zoneId = 0;
    DSCAlarmItemType dscAlarmItemType = null;
    try {
        dscAlarmDeviceType = DSCAlarmDeviceType.getDSCAlarmDeviceType(sections[0]);
        switch(dscAlarmDeviceType) {
            case PANEL:
                dscAlarmItemType = DSCAlarmItemType.getDSCAlarmItemType(sections[1]);
                break;
            case PARTITION:
                partitionId = Integer.parseInt(sections[1]);
                dscAlarmItemType = DSCAlarmItemType.getDSCAlarmItemType(sections[2]);
                break;
            case ZONE:
                partitionId = Integer.parseInt(sections[1]);
                zoneId = Integer.parseInt(sections[2]);
                dscAlarmItemType = DSCAlarmItemType.getDSCAlarmItemType(sections[3]);
                break;
            case KEYPAD:
                dscAlarmItemType = DSCAlarmItemType.getDSCAlarmItemType(sections[1]);
                break;
            default:
                logger.debug("Invalid Device Type in binding configuration: {}", dscAlarmDeviceType);
                break;
        }
    } catch (Exception e) {
        throw new BindingConfigParseException("Binding Configuration Error: deviceType: " + dscAlarmDeviceType);
    }
    if (dscAlarmItemType == null) {
        logger.error("processBindingConfiguration(): {}: DSC Alarm Item Type is NULL! Item Not Added!", item.getName());
        return;
    }
    DSCAlarmBindingConfig config = new DSCAlarmBindingConfig(dscAlarmDeviceType, partitionId, zoneId, dscAlarmItemType);
    addBindingConfig(item, config);
    super.processBindingConfiguration(context, item, bindingConfig);
    logger.debug("processBindingConfiguration(): Item added: {} - {}", item.getName(), bindingConfig);
}
Also used : DSCAlarmDeviceType(org.openhab.binding.dscalarm.internal.model.DSCAlarmDeviceType) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) DSCAlarmBindingConfig(org.openhab.binding.dscalarm.DSCAlarmBindingConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Aggregations

DSCAlarmDeviceType (org.openhab.binding.dscalarm.internal.model.DSCAlarmDeviceType)3 DSCAlarmBindingConfig (org.openhab.binding.dscalarm.DSCAlarmBindingConfig)2 DSCAlarmBindingProvider (org.openhab.binding.dscalarm.DSCAlarmBindingProvider)1 Keypad (org.openhab.binding.dscalarm.internal.model.Keypad)1 Panel (org.openhab.binding.dscalarm.internal.model.Panel)1 Partition (org.openhab.binding.dscalarm.internal.model.Partition)1 Zone (org.openhab.binding.dscalarm.internal.model.Zone)1 OnOffType (org.openhab.core.library.types.OnOffType)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1