diff --git a/bundles/org.openhab.binding.miele/README.md b/bundles/org.openhab.binding.miele/README.md index 0c72e1bf27bc9..2fd46ae67db99 100644 --- a/bundles/org.openhab.binding.miele/README.md +++ b/bundles/org.openhab.binding.miele/README.md @@ -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 diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java index 65e693f031c90..e83c66558cb38 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/MieleBindingConstants.java @@ -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"; } diff --git a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleMDNSDiscoveryParticipant.java b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleMDNSDiscoveryParticipant.java index 729065323c8ca..d66ec0b93135b 100644 --- a/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleMDNSDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/discovery/MieleMDNSDiscoveryParticipant.java @@ -22,13 +22,17 @@ 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 @@ * @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 configProperties) { + updateRemovalGracePeriod(configProperties); + } + + @Modified + public void modified(@Nullable Map configProperties) { + updateRemovalGracePeriod(configProperties); + } + + /** + * Update the removalGracePeriodSeconds when the component is activates or modified. + * + * @param configProperties the passed configuration parameters. + */ + private void updateRemovalGracePeriod(Map 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 getSupportedThingTypeUIDs() { return Collections.singleton(MieleBindingConstants.THING_TYPE_XGW3000); @@ -113,4 +148,14 @@ private boolean isMieleGateway(ServiceInfo service) { 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; + } }