Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[miele] Fix mDNS issue where hub repeatedly disappears from, resp. reappears in, the Inbox. #11834

Merged
merged 10 commits into from
Dec 28, 2021
6 changes: 6 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,12 @@ 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.

## Binding Configuration

The XGW3000 gateway is sometimes a few seconds late in re-announcing itself on the network.
This means that it might repeatedly appear in, resp. and disappear from, the Inbox.
To avoid this, the binding has a configuration parameter `removalGracePeriod` which delays such Inbox disappearances.
The default value is 30 seconds.

## 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 @@ -16,19 +16,26 @@
import java.net.InetAddress;
import java.net.Socket;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
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.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -48,6 +55,14 @@ public class MieleMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant {
private static final String SERVICE_NAME = "mieleathome";
private static final String PATH_PROPERTY_NAME = "path";

private final ConfigurationAdmin configAdmin;
private long removalGracePeriodSeconds = 30;

@Activate
andrewfg marked this conversation as resolved.
Show resolved Hide resolved
public MieleMDNSDiscoveryParticipant(final @Reference ConfigurationAdmin configAdmin) {
this.configAdmin = configAdmin;
}

@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(MieleBindingConstants.THING_TYPE_XGW3000);
Expand Down Expand Up @@ -113,4 +128,27 @@ 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);
}

/*
andrewfg marked this conversation as resolved.
Show resolved Hide resolved
* 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 service) {
try {
Configuration conf = configAdmin.getConfiguration("binding.miele");
Dictionary<String, @Nullable Object> properties = conf.getProperties();
if (properties != null) {
Object property = properties.get(MieleBindingConstants.REMOVAL_GRACE_PERIOD);
if (property != null) {
removalGracePeriodSeconds = Long.parseLong(property.toString());
}
}
} catch (IOException | IllegalStateException | NumberFormatException e) {
// fall through to pre-initialised (default) value
}
logger.trace("getRemovalGracePeriodSeconds={}", removalGracePeriodSeconds);
return removalGracePeriodSeconds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
<name>Miele Binding</name>
<description>This is the binding for Miele@home appliances</description>

<config-description>
<parameter name="removalGracePeriod" type="integer" min="0" step="1" unit="s">
<label>Removal Grace Period</label>
<description>Extra grace period (seconds) that mDNS discovery shall wait before removing a lost Bridge from the
Inbox. Default is 30 seconds.</description>
<default>30</default>
</parameter>
</config-description>

</binding:binding>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
binding.miele.name = Miele Binding
binding.miele.description = This is the binding for Miele@home appliances

# binding config

binding.config.miele.removalGracePeriod.label = Removal Grace Period
binding.config.miele.removalGracePeriod.description = Extra grace period (seconds) that mDNS discovery shall wait before removing a lost Bridge from the Inbox. Default is 30 seconds.

# thing types

thing-type.miele.coffeemachine.label = Coffee Machine
Expand Down