Beispiel #1
0
  /* (non-Javadoc)
   * @see org.openhab.core.binding.AbstractBinding#deactivate()
   */
  public void deactivate() {
    super.deactivate();

    logger.debug("eBus binding has been stopped.");

    if (connector != null && connector.isAlive()) {
      connector.interrupt();
      connector = null;
    }

    if (commandProcessor != null) {
      commandProcessor.deactivate();
      commandProcessor = null;
    }
  }
Beispiel #2
0
  /* (non-Javadoc)
   * @see org.openhab.core.binding.AbstractBinding#internalReceiveCommand(java.lang.String, org.openhab.core.types.Command)
   */
  @Override
  protected void internalReceiveCommand(String itemName, Command command) {

    final String type = command.toString().toLowerCase();

    for (EBusBindingProvider provider : providers) {
      byte[] data = commandProcessor.composeSendData(provider, itemName, type);

      connector.send(data);
    }
  }
Beispiel #3
0
  /* (non-Javadoc)
   * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
   */
  @Override
  public void updated(Dictionary<String, ?> properties) throws ConfigurationException {

    logger.info("Update eBus Binding configuration ...");

    try {
      // stop last thread if active
      if (connector != null && connector.isAlive()) {
        connector.interrupt();
      }

      // check to ensure that it is available
      checkConfigurationProvider();

      // clear current configuration
      configurationProvider.clear();

      // load parser from default url
      parser = new EBusTelegramParser(configurationProvider);

      URL configurationUrl = null;
      String parsers = (String) properties.get("parsers");

      if (StringUtils.isEmpty(parsers)) {
        // set to current stable configurations as default
        parsers = "common,wolf";
      }

      for (String elem : parsers.split(",")) {
        configurationUrl = null;

        // check for keyword custom to load custom configuration
        if (elem.trim().equals("custom")) {
          String parserUrl = (String) properties.get("parserUrl");
          if (parserUrl != null) {
            logger.debug("Load custom eBus Parser with url {}", parserUrl);
            configurationUrl = new URL(parserUrl);
          }

        } else {
          logger.debug("Load eBus Parser Configuration \"{}\" ...", elem.trim());
          configurationUrl = this.getClass().getResource("/" + elem.trim() + "-configuration.json");
        }

        if (configurationUrl != null) {
          configurationProvider.loadConfigurationFile(configurationUrl);
        }
      }

      // check minimal config
      if (properties.get("serialPort") != null && properties.get("hostname") != null) {
        throw new ConfigurationException(
            "hostname", "Set property serialPort or hostname, not both!");
      }

      if (StringUtils.isNotEmpty((String) properties.get("serialPort"))) {

        // use the serial connector
        connector = new EBusSerialConnector((String) properties.get("serialPort"));

      } else if (StringUtils.isNotEmpty((String) properties.get("hostname"))) {

        // use the tcp-ip connector
        connector =
            new EBusTCPConnector(
                (String) properties.get("hostname"),
                Integer.parseInt((String) properties.get("port")));
      }

      // Set eBus sender id or default 0xFF
      if (StringUtils.isNotEmpty((String) properties.get("senderId"))) {
        connector.setSenderId(EBusUtils.toByte((String) properties.get("senderId")));
      }

      // add event listener
      connector.addEBusEventListener(this);

      // start thread
      connector.start();

      // set the new connector
      commandProcessor.setConnector(connector);
      commandProcessor.setConfigurationProvider(configurationProvider);

    } catch (MalformedURLException e) {
      logger.error(e.toString(), e);
    } catch (IOException e) {
      throw new ConfigurationException("general", e.toString(), e);
    }
  }