Search in sources :

Example 1 with TellstickDevice

use of org.openhab.binding.tellstick.internal.device.TellstickDevice in project openhab1-addons by openhab.

the class TellstickGenericBindingProvider method getDevice.

@Override
public TellstickDevice getDevice(String itemName) {
    TellstickDevice res = null;
    TellstickBindingConfig conf = getTellstickBindingConfig(itemName);
    if (conf != null) {
        for (TellstickDevice device : getAllDevices()) {
            if (device.getId() == conf.getId()) {
                res = device;
                break;
            }
        }
    } else {
        logger.warn("Could not find conf for " + itemName);
    }
    return res;
}
Also used : TellstickDevice(org.openhab.binding.tellstick.internal.device.TellstickDevice) TellstickBindingConfig(org.openhab.binding.tellstick.TellstickBindingConfig)

Example 2 with TellstickDevice

use of org.openhab.binding.tellstick.internal.device.TellstickDevice in project openhab1-addons by openhab.

the class TellstickBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    // the code being executed when a command was sent on the openHAB
    // event bus goes here. This method is only called if one of the
    // BindingProviders provide a binding for the given 'itemName'.
    logger.debug("internalReceiveCommand() is called! for " + itemName + " with " + command);
    TellstickBindingConfig config = findTellstickBindingConfig(itemName);
    if (config != null) {
        if (!controllerThread.isAlive()) {
            controllerThread.start();
        }
        TellstickDevice dev = findDevice(config);
        Long eventTime = System.currentTimeMillis();
        synchronized (messageQue) {
            messageQue.put(dev, new TellstickSendEvent(config, dev, command, eventTime));
            messageQue.notify();
        }
    }
}
Also used : TellstickDevice(org.openhab.binding.tellstick.internal.device.TellstickDevice) TellstickBindingConfig(org.openhab.binding.tellstick.TellstickBindingConfig)

Example 3 with TellstickDevice

use of org.openhab.binding.tellstick.internal.device.TellstickDevice in project openhab1-addons by openhab.

the class TellstickGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    TellstickBindingConfig config = new TellstickBindingConfig();
    config.setItemName(item.getName());
    String[] configParts = bindingConfig.trim().split(":");
    if (configParts.length < 1) {
        throw new BindingConfigParseException("Tellstick binding must contain two parts separated by ':'");
    }
    TellstickDevice device;
    try {
        device = findDevice(configParts[0].trim());
    } catch (SupportedMethodsException e) {
        throw new BindingConfigParseException(e.getMessage());
    }
    validateBinding(item, configParts, device);
    if (device == null) {
        config.setId(Integer.valueOf(configParts[0].trim()));
    } else {
        config.setId(device.getId());
    }
    config.setValueSelector(TellstickValueSelector.getValueSelector(configParts[1].trim()));
    if (configParts.length > 2 && configParts[2].trim().length() > 0) {
        config.setUsageSelector(TellstickValueSelector.getValueSelector(configParts[2].trim()));
    }
    if (configParts.length > 3) {
        if (isIntegerRegex(configParts[3])) {
            config.setResend(Integer.parseInt(configParts[3]));
        } else if (configParts[3].matches("^([0-9]+)/([0-9]+)$")) {
            // Parse ie '3/300' into resend=3 and resendInterval=300
            String[] resendParts = configParts[3].split("/");
            config.setResend(Integer.parseInt(resendParts[0]));
            config.setResendInterval(Long.parseLong(resendParts[1]));
        } else {
            config.setProtocol(configParts[3]);
        }
    }
    logger.debug("Context:" + context + " Item " + item + " Conf:" + config);
    addBindingConfig(item, config);
}
Also used : SupportedMethodsException(org.openhab.binding.tellstick.internal.device.SupportedMethodsException) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) TellstickDevice(org.openhab.binding.tellstick.internal.device.TellstickDevice) TellstickBindingConfig(org.openhab.binding.tellstick.TellstickBindingConfig)

Example 4 with TellstickDevice

use of org.openhab.binding.tellstick.internal.device.TellstickDevice in project openhab1-addons by openhab.

the class TellstickBinding method handleDeviceEvent.

private void handleDeviceEvent(TellstickDeviceEvent event) {
    TellstickDevice device = event.getDevice();
    controller.setLastSend(System.currentTimeMillis());
    logger.debug("Got deviceEvent for " + device + " name:" + device + " method " + event.getMethod());
    if (device != null) {
        State cmd = resolveCommand(event.getMethod(), event.getData());
        TellstickBindingConfig conf = findTellstickBindingConfig(device.getId(), null, null);
        if (conf != null) {
            sendToOpenHab(conf.getItemName(), cmd);
        } else {
            logger.info("Could not find config for " + device);
        }
    }
}
Also used : State(org.openhab.core.types.State) TellstickDevice(org.openhab.binding.tellstick.internal.device.TellstickDevice) TellstickBindingConfig(org.openhab.binding.tellstick.TellstickBindingConfig)

Example 5 with TellstickDevice

use of org.openhab.binding.tellstick.internal.device.TellstickDevice in project openhab1-addons by openhab.

the class TellstickBinding method refreshFromTellstick.

private void refreshFromTellstick() {
    logger.trace("Update with telldus state");
    for (TellstickBindingProvider prov : providers) {
        for (String name : prov.getItemNames()) {
            TellstickDevice dev = prov.getDevice(name);
            if (dev != null) {
                Method method = Method.getMethodById(dev.getStatus());
                sendToOpenHab(name, resolveCommand(method, dev.getData()));
            }
        }
    }
    lastRefresh = System.currentTimeMillis();
}
Also used : TellstickDevice(org.openhab.binding.tellstick.internal.device.TellstickDevice) Method(org.openhab.binding.tellstick.internal.JNA.Method) TellstickBindingProvider(org.openhab.binding.tellstick.TellstickBindingProvider)

Aggregations

TellstickDevice (org.openhab.binding.tellstick.internal.device.TellstickDevice)5 TellstickBindingConfig (org.openhab.binding.tellstick.TellstickBindingConfig)4 TellstickBindingProvider (org.openhab.binding.tellstick.TellstickBindingProvider)1 Method (org.openhab.binding.tellstick.internal.JNA.Method)1 SupportedMethodsException (org.openhab.binding.tellstick.internal.device.SupportedMethodsException)1 State (org.openhab.core.types.State)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1