コード例 #1
0
  @Override
  public void onDeviceMessageReceived(ThingUID bridge, RFXComMessage message) {
    logger.trace("Received: bridge: {} message: {}", bridge, message);

    try {
      RFXComBaseMessage msg = (RFXComBaseMessage) message;
      String id = message.getDeviceId();
      ThingTypeUID uid = RFXComBindingConstants.packetTypeThingMap.get(msg.packetType);
      ThingUID thingUID =
          new ThingUID(uid, bridge, id.replace(RFXComBaseMessage.ID_DELIMITER, "_"));
      if (thingUID != null) {
        logger.trace("Adding new RFXCOM {} with id '{}' to smarthome inbox", thingUID, id);
        String subType = msg.convertSubType(String.valueOf(msg.subType)).toString();
        String label = msg.packetType + "-" + id;
        DiscoveryResult discoveryResult =
            DiscoveryResultBuilder.create(thingUID)
                .withLabel(label)
                .withProperty(RFXComBindingConstants.DEVICE_ID, id)
                .withProperty(RFXComBindingConstants.SUB_TYPE, subType)
                .withBridge(bridge)
                .build();
        thingDiscovered(discoveryResult);
      }
    } catch (Exception e) {
      logger.debug("Error occurred during device discovery", e);
    }
  }
コード例 #2
0
  @Override
  public DiscoveryResult createResult(ServiceInfo service) {

    if (service.getApplication().contains("mieleathome")) {
      ThingUID uid = getThingUID(service);

      if (uid != null) {
        Map<String, Object> properties = new HashMap<>(2);

        InetAddress[] addresses = service.getInetAddresses();
        if (addresses.length > 0 && addresses[0] != null) {
          properties.put(MieleBindingConstants.HOST, addresses[0].getHostAddress());

          Socket socket = null;
          try {
            socket = new Socket(addresses[0], 80);
            InetAddress ourAddress = socket.getLocalAddress();
            properties.put(MieleBindingConstants.INTERFACE, ourAddress.getHostAddress());
          } catch (IOException e) {
            logger.error(
                "An exception occurred while connecting to the Miele Gateway : '{}'",
                e.getMessage());
          }
        }

        return DiscoveryResultBuilder.create(uid)
            .withProperties(properties)
            .withRepresentationProperty(uid.getId())
            .withLabel("Miele XGW3000 Gateway")
            .build();
      }
    }
    return null;
  }
コード例 #3
0
  private void addDiscoveredThing(
      ThingUID thingUID, Map<String, Object> properties, String displayLabel) {
    DiscoveryResult discoveryResult =
        DiscoveryResultBuilder.create(thingUID)
            .withProperties(properties)
            .withBridge(netatmoBridgeHandler.getThing().getUID())
            .withLabel(displayLabel)
            .build();

    thingDiscovered(discoveryResult);
  }
コード例 #4
0
  private void addThing(ThingUID bridgeUID, String thingType, String thingID) {
    logger.trace("Adding new Vitotronic thing: {}", thingID);
    ThingUID thingUID = null;
    switch (thingType) {
      case VitotronicBindingConstants.THING_ID_HEATING:
        thingUID =
            new ThingUID(VitotronicBindingConstants.THING_TYPE_UID_HEATING, bridgeUID, thingID);
        break;
      case VitotronicBindingConstants.THING_ID_PELLETBURNER:
        thingUID =
            new ThingUID(
                VitotronicBindingConstants.THING_TYPE_UID_PELLETBURNER, bridgeUID, thingID);
        break;
      case VitotronicBindingConstants.THING_ID_STORAGETANK:
        thingUID =
            new ThingUID(VitotronicBindingConstants.THING_TYPE_UID_STORAGETANK, bridgeUID, thingID);
        break;
      case VitotronicBindingConstants.THING_ID_CIRCUIT:
        thingUID =
            new ThingUID(VitotronicBindingConstants.THING_TYPE_UID_CIRCUIT, bridgeUID, thingID);
        break;
      case VitotronicBindingConstants.THING_ID_SOLAR:
        thingUID =
            new ThingUID(VitotronicBindingConstants.THING_TYPE_UID_SOLAR, bridgeUID, thingID);
        break;
    }

    if (thingUID != null) {
      logger.trace(
          "Adding new Discovery thingType: {} bridgeType: {}",
          thingUID.getThingTypeId(),
          bridgeUID.getThingTypeId());

      DiscoveryResult discoveryResult =
          DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID).withLabel(thingID).build();
      logger.trace(
          "call register: {} label: {}",
          discoveryResult.getBindingId(),
          discoveryResult.getLabel());
      thingDiscovered(discoveryResult);
    } else {
      logger.debug("Discovered Thing is unsupported: type '{}'", thingID);
    }
  }