Search in sources :

Example 1 with BticinoBindingConfig

use of org.openhab.binding.bticino.internal.BticinoGenericBindingProvider.BticinoBindingConfig in project openhab1-addons by openhab.

the class BticinoBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     */
@Override
public void internalReceiveCommand(String itemName, Command command) {
    super.internalReceiveCommand(itemName, command);
    // Get the bticino interface id from the itemconfig
    BticinoBindingConfig l_item_binding = getBticinoBindingConfigForItem(itemName);
    // Get the interface from the item config
    String l_interface_id = l_item_binding.gatewayID;
    // Get the bticino device from the map (if it exists)
    if (m_bticino_devices.containsKey(l_interface_id)) {
        BticinoDevice l_bticino_device = m_bticino_devices.get(l_interface_id);
        l_bticino_device.receiveCommand(itemName, command, l_item_binding);
    } else {
        // just to know that something is wrong
        logger.error("Item [" + itemName + "] uses Bticino interface with ID [" + l_interface_id + "] but this gateway doesn't exist : check items.cfg and openhab.cfg!");
    }
}
Also used : BticinoBindingConfig(org.openhab.binding.bticino.internal.BticinoGenericBindingProvider.BticinoBindingConfig)

Example 2 with BticinoBindingConfig

use of org.openhab.binding.bticino.internal.BticinoGenericBindingProvider.BticinoBindingConfig in project openhab1-addons by openhab.

the class BticinoDevice method handleEvent.

public void handleEvent(ProtocolRead p_protocol_read) throws Exception {
    // the events on the bus are now received
    // map them to events on the openhab bus
    logger.debug("Gateway [" + m_gateway_id + "], Bticino WHO [" + p_protocol_read.getProperty("who") + "], WHAT [" + p_protocol_read.getProperty("what") + "], WHERE [" + p_protocol_read.getProperty("where") + "]");
    // Get all the configs that are connected to this (who,where), multiple
    // possible
    List<BticinoBindingConfig> l_binding_configs = m_bticino_binding.getItemForBticinoBindingConfig(p_protocol_read.getProperty("who"), p_protocol_read.getProperty("where"));
    // log it when an event has occured that no item is bound to
    if (l_binding_configs.isEmpty()) {
        logger.debug("Gateway [" + m_gateway_id + "], No Item found for bticino event, WHO [" + p_protocol_read.getProperty("who") + "], WHAT [" + p_protocol_read.getProperty("what") + "], WHERE [" + p_protocol_read.getProperty("where") + "]");
    }
    // every item associated with this who/where update the status
    for (BticinoBindingConfig l_binding_config : l_binding_configs) {
        // Get the Item out of the config
        Item l_item = l_binding_config.getItem();
        if (l_item instanceof SwitchItem) {
            // Lights
            if (p_protocol_read.getProperty("messageType").equalsIgnoreCase("lighting")) {
                logger.debug("Gateway [" + m_gateway_id + "], RECEIVED EVENT FOR SwitchItem [" + l_item.getName() + "], TRANSLATE TO OPENHAB BUS EVENT");
                if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Light ON")) {
                    eventPublisher.postUpdate(l_item.getName(), OnOffType.ON);
                } else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Light OFF")) {
                    eventPublisher.postUpdate(l_item.getName(), OnOffType.OFF);
                }
            } else // CENs
            if (p_protocol_read.getProperty("messageType").equalsIgnoreCase("CEN Basic and Evolved")) {
                // Pushbutton virtual address must match
                if (l_binding_config.what.equalsIgnoreCase(p_protocol_read.getProperty("what"))) {
                    logger.debug("Gateway [" + m_gateway_id + "], RECEIVED EVENT FOR SwitchItem [" + l_item.getName() + "], TRANSLATE TO OPENHAB BUS EVENT");
                    if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Virtual pressure")) {
                        // only returns when finished
                        eventPublisher.sendCommand(l_item.getName(), OnOffType.ON);
                    } else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Virtual release after short pressure")) {
                        // only returns when finished
                        eventPublisher.sendCommand(l_item.getName(), OnOffType.ON);
                    } else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Virtual release after an extended pressure")) {
                        // only returns when finished
                        eventPublisher.sendCommand(l_item.getName(), OnOffType.ON);
                    } else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Virtual extended pressure")) {
                        // only returns when finished
                        eventPublisher.sendCommand(l_item.getName(), OnOffType.ON);
                    }
                }
            }
        } else if (l_item instanceof RollershutterItem) {
            logger.debug("Gateway [" + m_gateway_id + "], RECEIVED EVENT FOR RollershutterItem [" + l_item.getName() + "], TRANSLATE TO OPENHAB BUS EVENT");
            if (p_protocol_read.getProperty("messageType").equalsIgnoreCase("automation")) {
                if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Automation UP")) {
                    eventPublisher.postUpdate(l_item.getName(), UpDownType.UP);
                } else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Automation DOWN")) {
                    eventPublisher.postUpdate(l_item.getName(), UpDownType.DOWN);
                }
            }
        } else if (l_item instanceof NumberItem) {
            logger.debug("Gateway [" + m_gateway_id + "], RECEIVED EVENT FOR NumberItem [" + l_item.getName() + "], TRANSLATE TO OPENHAB BUS EVENT");
            // THERMOREGULATION
            if (p_protocol_read.getProperty("messageType").equalsIgnoreCase("thermoregulation")) {
                if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Temperature value")) {
                    eventPublisher.postUpdate(l_item.getName(), DecimalType.valueOf(p_protocol_read.getProperty("temperature")));
                }
            }
        }
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) SwitchItem(org.openhab.core.library.items.SwitchItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) Item(org.openhab.core.items.Item) NumberItem(org.openhab.core.library.items.NumberItem) BticinoBindingConfig(org.openhab.binding.bticino.internal.BticinoGenericBindingProvider.BticinoBindingConfig) RollershutterItem(org.openhab.core.library.items.RollershutterItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

BticinoBindingConfig (org.openhab.binding.bticino.internal.BticinoGenericBindingProvider.BticinoBindingConfig)2 Item (org.openhab.core.items.Item)1 NumberItem (org.openhab.core.library.items.NumberItem)1 RollershutterItem (org.openhab.core.library.items.RollershutterItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1