Exemplo n.º 1
0
 /** @{inheritDoc */
 @Override
 protected void internalReceiveCommand(String itemName, Command command) {
   logger.debug("Received command item='{}', command='{}'", itemName, command.toString());
   for (Ipx800DeviceConnector device : devices.values()) {
     for (Ipx800Port slot : device.getAllPorts()) {
       Ipx800Item itemSlot = slot.getItemSlot(itemName);
       if (itemSlot != null) {
         itemSlot.setState((State) command);
         if (itemSlot instanceof Ipx800OutputItem) {
           device.setOutput((Ipx800OutputItem) itemSlot);
         }
       }
     }
   }
 }
Exemplo n.º 2
0
 @Override
 public void bindingChanged(BindingProvider prov, String itemName) {
   if (prov.getItemNames().contains(itemName)) {
     try {
       createInternalItem(itemName, prov);
     } catch (Ipx800UnknownDeviceException e) {
       logger.error("Item {} will be ignored", itemName);
     }
   } else {
     logger.debug("Removing item {}", itemName);
     for (String deviceName : devices.keySet()) {
       for (Ipx800Port slot : devices.get(deviceName).getAllPorts()) {
         slot.destroyItem(itemName);
       }
     }
   }
 }
Exemplo n.º 3
0
  /**
   * Create and attach new item to device
   *
   * @param itemName
   * @param provider
   * @throws Ipx800UnknownDeviceException
   */
  private void createInternalItem(String itemName, BindingProvider prov)
      throws Ipx800UnknownDeviceException {
    if (prov instanceof Ipx800GenericBindingProvider) {
      Ipx800GenericBindingProvider provider = (Ipx800GenericBindingProvider) prov;
      Ipx800BindingConfig config = provider.getBindingConfig(itemName);
      if (config != null) {
        Ipx800DeviceAndPort devPort =
            getDeviceAndPort(config.getDeviceName(), config.getPortField());
        Ipx800DeviceConnector device = devPort.getDevice();
        Ipx800Port port = devPort.getPort();

        Ipx800Item item;
        if (port.getCommandType() == Ipx800PortType.OUPUT) {
          boolean pulse = false;
          if (config.getExtra(0).equals("p")) {
            pulse = true;
          }
          item = new Ipx800OutputItem(pulse);
        } else if (port.getCommandType() == Ipx800PortType.COUNTER) {
          if (config.getExtra(0).equals("a")) {
            float unit = 1;
            if (!config.getExtra(1).equals("")) {
              unit = Float.parseFloat(config.getExtra(1));
            }
            Ipx800ConsumptionPeriod period = Ipx800ConsumptionPeriod.getPeriod(config.getExtra(2));
            item = new Ipx800Consumption(unit, period);
          } else {
            item = new Ipx800Counter();
          }
        } else {
          if (config.getExtra(0).equals("D")) {
            item = new Ipx800DoubleClic();
            port.switchToMultiHandler();
          } else if (config.getExtra(0).equals("d")) {
            item = new Ipx800SimpleClic();
            port.switchToMultiHandler();
          } else if (config.getExtra(0).equals("v")) {
            if (config.getExtra(1).equals("")) {
              item = new Ipx800Dimmer();
            } else {
              item = new Ipx800Dimmer(new Integer(config.getExtra(1)));
            }
            port.switchToMultiHandler();
          } else if (config.getExtra(0).equals("m")) {
            item = new Ipx800Mirror();
          } else {
            item = new Ipx800AstableSwitch();
          }
        }
        item.setBinding(this);
        item.setItemName(itemName);

        // If no to action set : null is returned
        String toDeviceName = config.getToDeviceName();
        if (toDeviceName.isEmpty()) {
          toDeviceName = config.getDeviceName();
        }
        Ipx800DeviceAndPort devToPort = getDeviceAndPort(toDeviceName, config.getToPortField());
        Ipx800DeviceConnector toDevice = devToPort.getDevice();
        Ipx800Port toPort = devToPort.getPort();
        Ipx800OutputItem toItem = null;
        if (toDevice != null && toPort != null) {
          toItem = new Ipx800OutputItem(config.isToPulse());
          toItem.setItemName(itemName + "-out");
          toItem.setBinding(this);
          toItem.setFromItem(item);
          item.setToItem(toItem);
          toPort.attachItem(itemName + "-out", toItem);
        }

        port.attachItem(itemName, item);
        if (toItem != null) {
          logger.info(
              "Item {} created using {}, attached to {} on port {} to item {}",
              itemName,
              item,
              device,
              port,
              toItem);
        } else {
          logger.info(
              "Item {} created using {}, attached to {} on port {}", itemName, item, device, port);
        }
      }
    }
  }