@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;
  }
Пример #2
0
 @Override
 public void serviceAdded(ServiceEvent event) {
   Log.d(TAG, "serviceAdded:" + event);
   ZeroServiceInfo zsi = new ZeroServiceInfo(null, event);
   String name = event.getName();
   if (mName.equals(name)) {
     mZsinfo = zsi;
     if (null != mServiceListener) {
       mServiceListener.onServiceRegistered(zsi);
     }
   } else {
     ServiceInfo sinfo = event.getInfo();
     if (null != sinfo) {
       InetAddress[] addrs = sinfo.getInetAddresses();
       if (null != addrs && addrs.length > 0) {
         for (InetAddress addr : addrs) {
           Log.d(TAG, "the addr is:" + addr.getHostName());
         }
         if (null != mDiscoverListener) {
           mDiscoverListener.onServiceFound(zsi);
         }
       }
     }
   }
 }