Search in sources :

Example 1 with HomematicClientException

use of org.openhab.binding.homematic.internal.communicator.client.HomematicClientException in project openhab1-addons by openhab.

the class HomematicPublisher method execute.

/**
     * Sends or delays a event to a Homematic server.
     */
public void execute(final Event event) throws HomematicClientException {
    double delay = event.getDelay();
    if (delay > 0.0) {
        synchronized (this) {
            logger.debug("Delaying event for {} seconds: {}", delay, event.getHmValueItem());
            Timer timer = delayedEvents.get(event.getBindingConfig());
            if (timer != null) {
                timer.cancel();
            }
            timer = new Timer();
            delayedEvents.put(event.getBindingConfig(), timer);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    try {
                        delayedEvents.remove(event.getBindingConfig());
                        sendToClient(event);
                    } catch (Exception ex) {
                        logger.error(ex.getMessage(), ex);
                    }
                }
            }, (long) (delay * 1000));
        }
    } else {
        sendToClient(event);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) HomematicClientException(org.openhab.binding.homematic.internal.communicator.client.HomematicClientException)

Example 2 with HomematicClientException

use of org.openhab.binding.homematic.internal.communicator.client.HomematicClientException in project openhab1-addons by openhab.

the class RemoteControlOptionParser method getSymbols.

/**
     * Returns all possible symbols from the remote control.
     */
private String[] getSymbols() throws HomematicClientException {
    DatapointConfig dpConfig = new DatapointConfig(remoteControlAddress, "18", "SUBMIT");
    HmDatapoint rcDatapoint = (HmDatapoint) context.getStateHolder().getState(dpConfig);
    if (rcDatapoint == null) {
        throw new HomematicClientException("Address " + remoteControlAddress + " is not a Homematic remote control with a display");
    }
    List<String> symbols = new ArrayList<String>();
    for (HmDatapoint datapoint : rcDatapoint.getChannel().getDatapoints()) {
        if (datapoint.isWriteable() && datapoint.getValueType() == 2 && !"SUBMIT".equals(datapoint.getName())) {
            symbols.add(datapoint.getName());
        }
    }
    return symbols.toArray(new String[0]);
}
Also used : DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) HomematicClientException(org.openhab.binding.homematic.internal.communicator.client.HomematicClientException) ArrayList(java.util.ArrayList) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Aggregations

HomematicClientException (org.openhab.binding.homematic.internal.communicator.client.HomematicClientException)2 ArrayList (java.util.ArrayList)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 DatapointConfig (org.openhab.binding.homematic.internal.config.binding.DatapointConfig)1 HmDatapoint (org.openhab.binding.homematic.internal.model.HmDatapoint)1