]> git.basschouten.com Git - openhab-addons.git/commitdiff
[miele] Fix mDNS issue where hub repeatedly disappears from, resp. reappears in,...
authorAndrew Fiddian-Green <software@whitebear.ch>
Tue, 28 Dec 2021 08:49:05 +0000 (08:49 +0000)
committerGitHub <noreply@github.com>
Tue, 28 Dec 2021 08:49:05 +0000 (09:49 +0100)
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
bundles/org.openhab.binding.miele/README.md
bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java
bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleMDNSDiscoveryParticipant.java

index 0c72e1bf27bc9ff48e40c0f85202ce9c8c549ffe..2fd46ae67db9945545e94e9f0e4b0b331d563472 100644 (file)
@@ -29,6 +29,17 @@ The types of appliances that are supported by this binding are:
 The binding is able to auto-discover the Miele XGW3000 gateway.
 When an XGW3000 gateway is discovered, all appliances can be subsequently discovered.
 
+### Note on Discovery
+
+The XGW3000 gateway is sometimes a few seconds late in re-announcing itself on the network.
+This means that it might repeatedly disappear from, and re-appear in, the Inbox.
+To avoid this, there is a discovery configuration parameter `removalGracePeriod` which delays such Inbox disappearances.
+The default value is 15 seconds.
+If you want to change this value just add the following line to your `$OPENHAB_CONF/services/runtime.cfg` file.
+
+```
+discovery.miele:removalGracePeriod=30
+```
 
 ## Thing Configuration
 
index 65e693f031c9087eb31c2dfa25d6632d6adb0b22..e83c66558cb38d1e040472bc174fb6fe599656b7 100644 (file)
@@ -114,4 +114,5 @@ public class MieleBindingConstants {
     public static final String USER_NAME = "userName";
     public static final String PASSWORD = "password";
     public static final String LANGUAGE = "language";
+    public static final String REMOVAL_GRACE_PERIOD = "removalGracePeriod";
 }
index 729065323c8ca1efdbe8717c3d061d3134b80187..d66ec0b93135ba7591a32075cfe81e3dd756689d 100644 (file)
@@ -22,13 +22,17 @@ import java.util.Set;
 
 import javax.jmdns.ServiceInfo;
 
+import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.miele.internal.MieleBindingConstants;
 import org.openhab.core.config.discovery.DiscoveryResult;
 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
 import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
+import org.openhab.core.config.discovery.mdns.internal.MDNSDiscoveryService;
 import org.openhab.core.thing.ThingTypeUID;
 import org.openhab.core.thing.ThingUID;
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Modified;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,7 +44,7 @@ import org.slf4j.LoggerFactory;
  * @author Martin Lepsy - Added check for Miele gateway for cleaner discovery
  * @author Jacob Laursen - Fixed multicast and protocol support (ZigBee/LAN)
  */
-@Component
+@Component(configurationPid = "discovery.miele")
 public class MieleMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant {
 
     private final Logger logger = LoggerFactory.getLogger(MieleMDNSDiscoveryParticipant.class);
@@ -48,6 +52,37 @@ public class MieleMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant {
     private static final String SERVICE_NAME = "mieleathome";
     private static final String PATH_PROPERTY_NAME = "path";
 
+    private long removalGracePeriodSeconds = 15;
+
+    @Activate
+    public void activate(@Nullable Map<String, Object> configProperties) {
+        updateRemovalGracePeriod(configProperties);
+    }
+
+    @Modified
+    public void modified(@Nullable Map<String, Object> configProperties) {
+        updateRemovalGracePeriod(configProperties);
+    }
+
+    /**
+     * Update the removalGracePeriodSeconds when the component is activates or modified.
+     *
+     * @param configProperties the passed configuration parameters.
+     */
+    private void updateRemovalGracePeriod(Map<String, Object> configProperties) {
+        if (configProperties != null) {
+            Object value = configProperties.get(MieleBindingConstants.REMOVAL_GRACE_PERIOD);
+            if (value != null) {
+                try {
+                    removalGracePeriodSeconds = Integer.parseInt(value.toString());
+                } catch (NumberFormatException e) {
+                    logger.warn("Configuration property '{}' has invalid value: {}",
+                            MieleBindingConstants.REMOVAL_GRACE_PERIOD, value);
+                }
+            }
+        }
+    }
+
     @Override
     public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
         return Collections.singleton(MieleBindingConstants.THING_TYPE_XGW3000);
@@ -113,4 +148,14 @@ public class MieleMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant {
         return service.getApplication().contains(SERVICE_NAME) && service.getPropertyString(PATH_PROPERTY_NAME) != null
                 && service.getPropertyString(PATH_PROPERTY_NAME).equalsIgnoreCase(PATH_TO_CHECK_FOR_XGW3000);
     }
+
+    /**
+     * Miele devices are sometimes a few seconds late in updating their mDNS announcements, which means that they are
+     * repeatedly removed from, and (re)added to, the Inbox. To prevent this, we override this method to specify an
+     * additional delay period (grace period) to wait before the device is removed from the Inbox.
+     */
+    @Override
+    public long getRemovalGracePeriodSeconds(ServiceInfo serviceInfo) {
+        return removalGracePeriodSeconds;
+    }
 }