예제 #1
0
 /**
  * Post the state of an item to the event bus
  *
  * @param item
  */
 public void postUpdate(Ipx800Item item) {
   if (item.getPort().getCommandType() == Ipx800PortType.OUPUT) {
     eventPublisher.postUpdate(item.getItemName(), item.getState());
   } else {
     eventPublisher.postCommand(item.getItemName(), (Command) item.getState());
   }
 }
예제 #2
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);
         }
       }
     }
   }
 }
예제 #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);
        }
      }
    }
  }