Search in sources :

Example 56 with Item

use of org.openhab.core.items.Item in project openhab1-addons by openhab.

the class MiosBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    try {
        logger.debug("internalReceiveCommand: itemName '{}', command '{}'", itemName, command);
        // Lookup the MiOS Unit name and property for this item
        String unitName = getMiosUnitName(itemName);
        MiosUnitConnector connector = getMiosConnector(unitName);
        if (connector == null) {
            logger.warn("Received command ({}) for item '{}' but no connector found for MiOS Unit '{}', ignoring", new Object[] { command.toString(), itemName, unitName });
            return;
        }
        if (!connector.isConnected()) {
            logger.warn("Received command ({}) for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", new Object[] { command.toString(), itemName, unitName });
            return;
        }
        for (BindingProvider provider : providers) {
            if (provider instanceof MiosBindingProvider) {
                MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
                MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
                if (config != null) {
                    ItemRegistry reg = miosProvider.getItemRegistry();
                    if (reg != null) {
                        Item item = reg.getItem(config.getItemName());
                        State state = item.getState();
                        connector.invokeCommand(config, command, state);
                    } else {
                        logger.warn("internalReceiveCommand: Missing ItemRegistry for item '{}' command '{}'", itemName, command);
                    }
                } else {
                    logger.trace("internalReceiveCommand: Missing BindingConfig for item '{}' command '{}'", itemName, command);
                }
            }
        }
    } catch (Exception e) {
        logger.error("Error handling command", e);
    }
}
Also used : Item(org.openhab.core.items.Item) MiosBindingConfig(org.openhab.binding.mios.internal.config.MiosBindingConfig) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) State(org.openhab.core.types.State) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) ItemRegistry(org.openhab.core.items.ItemRegistry) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 57 with Item

use of org.openhab.core.items.Item 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)

Example 58 with Item

use of org.openhab.core.items.Item in project openhab1-addons by openhab.

the class AutelisBinding method execute.

/**
     * @{inheritDoc}
     */
@Override
protected void execute() {
    logger.trace("Connecting to {}" + baseURL);
    clearState();
    String xmlDoc = fetchStateFromController();
    if (xmlDoc == null) {
        return;
    }
    for (AutelisBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {
            Item item = provider.getItem(itemName);
            String config = provider.getAutelisBindingConfigString(itemName);
            XPathFactory xpathFactory = XPathFactory.newInstance();
            XPath xpath = xpathFactory.newXPath();
            try {
                InputSource is = new InputSource(new StringReader(xmlDoc));
                String value = xpath.evaluate("response/" + config.replace('.', '/'), is);
                State state = toState(item.getClass(), value);
                State oldState = stateMap.put(itemName, state);
                if (!state.equals(oldState)) {
                    logger.debug("updating item {} with state {}", itemName, state);
                    eventPublisher.postUpdate(itemName, state);
                }
            } catch (XPathExpressionException e) {
                logger.warn("could not parse xml", e);
            }
        }
    }
}
Also used : AutelisBindingProvider(org.openhab.binding.autelis.AutelisBindingProvider) XPath(javax.xml.xpath.XPath) SwitchItem(org.openhab.core.library.items.SwitchItem) NumberItem(org.openhab.core.library.items.NumberItem) Item(org.openhab.core.items.Item) XPathFactory(javax.xml.xpath.XPathFactory) InputSource(org.xml.sax.InputSource) State(org.openhab.core.types.State) XPathExpressionException(javax.xml.xpath.XPathExpressionException) StringReader(java.io.StringReader)

Example 59 with Item

use of org.openhab.core.items.Item in project openhab1-addons by openhab.

the class EnoceanBinding method processEEPs.

private void processEEPs(EnoceanBindingProvider enoceanBindingProvider, String itemName) {
    EnoceanParameterAddress parameterAddress = enoceanBindingProvider.getParameterAddress(itemName);
    EEPId eep = enoceanBindingProvider.getEEP(itemName);
    esp3Host.addDeviceProfile(parameterAddress.getEnoceanDeviceId(), eep);
    Item item = enoceanBindingProvider.getItem(itemName);
    if (profiles.containsKey(parameterAddress.getAsString())) {
        Profile profile = profiles.get(parameterAddress.getAsString());
        profile.removeItem(item);
    }
    Class<Profile> customProfileClass = enoceanBindingProvider.getCustomProfile(itemName);
    if (customProfileClass != null) {
        Constructor<Profile> constructor;
        Profile profile;
        try {
            constructor = customProfileClass.getConstructor(Item.class, EventPublisher.class);
            profile = constructor.newInstance(item, eventPublisher);
            addProfile(item, parameterAddress, profile);
        } catch (Exception e) {
            logger.error("Could not create class for profile " + customProfileClass, e);
        }
    } else if (EEPId.EEP_F6_02_01.equals(eep) || EEPId.EEP_F6_10_00.equals(eep)) {
        if (item.getClass().equals(RollershutterItem.class)) {
            RollershutterProfile profile = new RollershutterProfile(item, eventPublisher);
            addProfile(item, parameterAddress, profile);
        }
        if (item.getClass().equals(DimmerItem.class)) {
            DimmerOnOffProfile profile = new DimmerOnOffProfile(item, eventPublisher);
            addProfile(item, parameterAddress, profile);
        }
        if (item.getClass().equals(SwitchItem.class) && parameterAddress.getParameterId() == null) {
            SwitchOnOffProfile profile = new SwitchOnOffProfile(item, eventPublisher);
            addProfile(item, parameterAddress, profile);
        }
        if (item.getClass().equals(StringItem.class) && EEPId.EEP_F6_10_00.equals(eep)) {
            WindowHandleProfile profile = new WindowHandleProfile(item, eventPublisher);
            addProfile(item, parameterAddress, profile);
        }
    }
}
Also used : EventPublisher(org.openhab.core.events.EventPublisher) EEPId(org.opencean.core.common.EEPId) RollershutterProfile(org.openhab.binding.enocean.internal.profiles.RollershutterProfile) SwitchOnOffProfile(org.openhab.binding.enocean.internal.profiles.SwitchOnOffProfile) Profile(org.openhab.binding.enocean.internal.profiles.Profile) SwitchOnOffProfile(org.openhab.binding.enocean.internal.profiles.SwitchOnOffProfile) StandardProfile(org.openhab.binding.enocean.internal.profiles.StandardProfile) DimmerOnOffProfile(org.openhab.binding.enocean.internal.profiles.DimmerOnOffProfile) WindowHandleProfile(org.openhab.binding.enocean.internal.profiles.WindowHandleProfile) RollershutterProfile(org.openhab.binding.enocean.internal.profiles.RollershutterProfile) ConfigurationException(org.osgi.service.cm.ConfigurationException) NoSuchPortException(gnu.io.NoSuchPortException) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) EnoceanParameterAddress(org.opencean.core.address.EnoceanParameterAddress) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DimmerItem(org.openhab.core.library.items.DimmerItem) DimmerOnOffProfile(org.openhab.binding.enocean.internal.profiles.DimmerOnOffProfile) WindowHandleProfile(org.openhab.binding.enocean.internal.profiles.WindowHandleProfile)

Aggregations

Item (org.openhab.core.items.Item)59 SwitchItem (org.openhab.core.library.items.SwitchItem)23 NumberItem (org.openhab.core.library.items.NumberItem)20 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)16 State (org.openhab.core.types.State)16 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 ContactItem (org.openhab.core.library.items.ContactItem)14 DimmerItem (org.openhab.core.library.items.DimmerItem)14 DecimalType (org.openhab.core.library.types.DecimalType)9 HistoricItem (org.openhab.core.persistence.HistoricItem)9 ArrayList (java.util.ArrayList)7 ColorItem (org.openhab.core.library.items.ColorItem)7 StringItem (org.openhab.core.library.items.StringItem)7 HomematicBindingConfig (org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)6 DateTimeItem (org.openhab.core.library.items.DateTimeItem)6 Test (org.junit.Test)5 GenericItem (org.openhab.core.items.GenericItem)5 GroupItem (org.openhab.core.items.GroupItem)5 ItemRegistry (org.openhab.core.items.ItemRegistry)5 Calendar (java.util.Calendar)3