Search in sources :

Example 1 with IllegalClassException

use of org.apache.commons.lang.IllegalClassException in project openhab1-addons by openhab.

the class KNXBinding method sendTypeToItemButNotToKnx.

private void sendTypeToItemButNotToKnx(GroupAddress destination, String itemName, Type type) {
    // we need to make sure that we won't send out this event to
    // the knx bus again, when receiving it on the openHAB bus
    ignoreEventList.add(itemName + type.toString());
    logger.trace("Added event (item='{}', type='{}') to the ignore event list", itemName, type.toString());
    if (type instanceof Command && isCommandGA(destination)) {
        eventPublisher.postCommand(itemName, (Command) type);
    } else if (type instanceof State) {
        eventPublisher.postUpdate(itemName, (State) type);
    } else {
        throw new IllegalClassException("Cannot process datapoint of type " + type.toString());
    }
    logger.trace("Processed event (item='{}', type='{}', destination='{}')", itemName, type.toString(), destination.toString());
}
Also used : Command(org.openhab.core.types.Command) State(org.openhab.core.types.State) IllegalClassException(org.apache.commons.lang.IllegalClassException)

Example 2 with IllegalClassException

use of org.apache.commons.lang.IllegalClassException in project openhab1-addons by openhab.

the class SonosBinding method processVariableMap.

@SuppressWarnings("rawtypes")
public void processVariableMap(RemoteDevice device, Map<String, StateVariableValue> values) {
    if (device != null && values != null) {
        SonosZonePlayer associatedPlayer = sonosZonePlayerCache.getByDevice(device);
        if (associatedPlayer == null) {
            logger.debug("There is no Sonos Player defined matching the device {}", device);
            return;
        }
        for (String stateVariable : values.keySet()) {
            // find all the CommandTypes that are defined for each
            // StateVariable
            List<SonosCommandType> supportedCommands = SonosCommandType.getCommandByVariable(stateVariable);
            StateVariableValue status = values.get(stateVariable);
            for (SonosCommandType sonosCommandType : supportedCommands) {
                // create a new State based on the type of Sonos Command and
                // the status value in the map
                Type newState = null;
                try {
                    newState = createStateForType((Class<? extends State>) sonosCommandType.getTypeClass(), status.getValue().toString());
                } catch (BindingConfigParseException e) {
                    logger.error("Error parsing a value {} to a state variable of type {}", status.toString(), sonosCommandType.getTypeClass().toString());
                }
                for (SonosBindingProvider provider : providers) {
                    List<String> qualifiedItems = provider.getItemNames(sonosZonePlayerCache.getByDevice(device).getId(), sonosCommandType.getSonosCommand());
                    List<String> qualifiedItemsByUDN = provider.getItemNames(sonosZonePlayerCache.getByDevice(device).getUdn().getIdentifierString(), sonosCommandType.getSonosCommand());
                    for (String item : qualifiedItemsByUDN) {
                        if (!qualifiedItems.contains(item)) {
                            qualifiedItems.add(item);
                        }
                    }
                    for (String anItem : qualifiedItems) {
                        // get the openHAB commands attached to each Item at
                        // this given Provider
                        List<Command> commands = provider.getCommands(anItem, sonosCommandType.getSonosCommand());
                        if (provider.getAcceptedDataTypes(anItem).contains(sonosCommandType.getTypeClass())) {
                            if (newState != null) {
                                eventPublisher.postUpdate(anItem, (State) newState);
                            } else {
                                throw new IllegalClassException("Cannot process update for the command of type " + sonosCommandType.toString());
                            }
                        } else {
                            logger.warn("Cannot cast {} to an accepted state type for item {}", sonosCommandType.getTypeClass().toString(), anItem);
                        }
                    }
                }
            }
        }
    }
}
Also used : StateVariableValue(org.teleal.cling.model.state.StateVariableValue) SonosCommandType(org.openhab.binding.sonos.SonosCommandType) IllegalClassException(org.apache.commons.lang.IllegalClassException) StringType(org.openhab.core.library.types.StringType) SonosCommandType(org.openhab.binding.sonos.SonosCommandType) OnOffType(org.openhab.core.library.types.OnOffType) UDAServiceType(org.teleal.cling.model.types.UDAServiceType) Type(org.openhab.core.types.Type) DecimalType(org.openhab.core.library.types.DecimalType) SonosBindingProvider(org.openhab.binding.sonos.SonosBindingProvider) Command(org.openhab.core.types.Command) State(org.openhab.core.types.State) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 3 with IllegalClassException

use of org.apache.commons.lang.IllegalClassException in project jstorm by alibaba.

the class WindowsStateUpdater method updateState.

@Override
public void updateState(WindowsState state, List<TridentTuple> tuples, TridentCollector collector) {
    Long currentTxId = state.getCurrentTxId();
    LOG.debug("Removing triggers using WindowStateUpdater, txnId: [{}] ", currentTxId);
    for (TridentTuple tuple : tuples) {
        try {
            Object fieldValue = tuple.getValueByField(WindowTridentProcessor.TRIGGER_FIELD_NAME);
            if (!(fieldValue instanceof WindowTridentProcessor.TriggerInfo)) {
                throw new IllegalClassException(WindowTridentProcessor.TriggerInfo.class, fieldValue.getClass());
            }
            WindowTridentProcessor.TriggerInfo triggerInfo = (WindowTridentProcessor.TriggerInfo) fieldValue;
            String triggerCompletedKey = WindowTridentProcessor.getWindowTriggerInprocessIdPrefix(triggerInfo.windowTaskId) + currentTxId;
            LOG.debug("Removing trigger key [{}] and trigger completed key [{}] from store: [{}]", triggerInfo, triggerCompletedKey, windowsStore);
            windowsStore.removeAll(Lists.newArrayList(triggerInfo.generateTriggerKey(), triggerCompletedKey));
        } catch (Exception ex) {
            LOG.warn(ex.getMessage());
            collector.reportError(ex);
            throw new FailedException(ex);
        }
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) IllegalClassException(org.apache.commons.lang.IllegalClassException) FailedException(backtype.storm.topology.FailedException) IllegalClassException(org.apache.commons.lang.IllegalClassException) TridentTuple(storm.trident.tuple.TridentTuple)

Example 4 with IllegalClassException

use of org.apache.commons.lang.IllegalClassException in project openhab1-addons by openhab.

the class PlugwiseBinding method postUpdate.

/**
     * Method to post updates to the OH runtime.
     *
     *
     * @param MAC of the Plugwise device concerned
     * @param ctype is the Plugwise Command type
     * @param value is the value (to be converted) to post
     */
public void postUpdate(String MAC, PlugwiseCommandType ctype, Object value) {
    if (MAC != null && ctype != null && value != null) {
        for (PlugwiseBindingProvider provider : providers) {
            Set<String> qualifiedItems = provider.getItemNames(MAC, ctype);
            // Make sure we also capture those devices that were pre-defined with a friendly name in a .cfg or alike
            Set<String> qualifiedItemsFriendly = provider.getItemNames(stick.getDevice(MAC).getName(), ctype);
            qualifiedItems.addAll(qualifiedItemsFriendly);
            State type = null;
            try {
                type = createStateForType(ctype, value);
            } catch (BindingConfigParseException e) {
                logger.error("Error parsing a value {} to a state variable of type {}", value.toString(), ctype.getTypeClass().toString());
            }
            for (String item : qualifiedItems) {
                if (type instanceof State) {
                    eventPublisher.postUpdate(item, type);
                } else {
                    throw new IllegalClassException("Cannot process update of type " + (type == null ? "null" : type.toString()));
                }
            }
        }
    }
}
Also used : PlugwiseBindingProvider(org.openhab.binding.plugwise.PlugwiseBindingProvider) State(org.openhab.core.types.State) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) IllegalClassException(org.apache.commons.lang.IllegalClassException)

Aggregations

IllegalClassException (org.apache.commons.lang.IllegalClassException)4 State (org.openhab.core.types.State)3 Command (org.openhab.core.types.Command)2 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)2 FailedException (backtype.storm.topology.FailedException)1 PlugwiseBindingProvider (org.openhab.binding.plugwise.PlugwiseBindingProvider)1 SonosBindingProvider (org.openhab.binding.sonos.SonosBindingProvider)1 SonosCommandType (org.openhab.binding.sonos.SonosCommandType)1 DecimalType (org.openhab.core.library.types.DecimalType)1 OnOffType (org.openhab.core.library.types.OnOffType)1 StringType (org.openhab.core.library.types.StringType)1 Type (org.openhab.core.types.Type)1 StateVariableValue (org.teleal.cling.model.state.StateVariableValue)1 UDAServiceType (org.teleal.cling.model.types.UDAServiceType)1 TridentTuple (storm.trident.tuple.TridentTuple)1