Skip to content

Commit

Permalink
[miele] Fix mDNS issue where hub repeatedly disappears from, resp. re…
Browse files Browse the repository at this point in the history
…appears in, the Inbox. (openhab#11834)

Signed-off-by: Andrew Fiddian-Green <[email protected]>
  • Loading branch information
andrewfg authored and Nemer_Daud committed Jan 28, 2022
1 parent e892b61 commit 4a32945
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
11 changes: 11 additions & 0 deletions bundles/org.openhab.binding.miele/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,14 +44,45 @@
* @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);
private static final String PATH_TO_CHECK_FOR_XGW3000 = "/rest/";
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);
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 4a32945

Please sign in to comment.