]> git.basschouten.com Git - openhab-addons.git/blob
7e61eb669f0f8f3cd6752aad106dafbcf52bd42c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.homematic.internal.discovery;
14
15 import static org.openhab.binding.homematic.internal.HomematicBindingConstants.THING_TYPE_BRIDGE;
16
17 import java.util.Collections;
18 import java.util.HashMap;
19 import java.util.Map;
20 import java.util.Set;
21
22 import org.jupnp.model.meta.DeviceDetails;
23 import org.jupnp.model.meta.RemoteDevice;
24 import org.openhab.core.config.discovery.DiscoveryResult;
25 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
26 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.ThingUID;
29 import org.osgi.service.component.annotations.Component;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * The {@link HomegearDiscoveryParticipant} is responsible for discovering new Homegear gateways on the network.
35  *
36  * @author Gerhard Riegler - Initial contribution
37  */
38 @Component
39 public class HomegearDiscoveryParticipant implements UpnpDiscoveryParticipant {
40     private final Logger logger = LoggerFactory.getLogger(HomegearDiscoveryParticipant.class);
41
42     @Override
43     public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
44         return Collections.singleton(THING_TYPE_BRIDGE);
45     }
46
47     @Override
48     public DiscoveryResult createResult(RemoteDevice device) {
49         ThingUID uid = getThingUID(device);
50         if (uid != null) {
51             DeviceDetails details = device.getDetails();
52             Map<String, Object> properties = new HashMap<>(3);
53             properties.put("gatewayAddress", details.getBaseURL().getHost());
54
55             logger.debug("Discovered a Homegear gateway with serial number '{}'", details.getSerialNumber());
56             return DiscoveryResultBuilder.create(uid).withProperties(properties)
57                     .withLabel(details.getModelDetails().getModelNumber()).build();
58         }
59         return null;
60     }
61
62     @Override
63     public ThingUID getThingUID(RemoteDevice device) {
64         DeviceDetails details = device.getDetails();
65         String modelName = details.getModelDetails().getModelName();
66         if ("HOMEGEAR".equalsIgnoreCase(modelName)) {
67             return new ThingUID(THING_TYPE_BRIDGE, details.getSerialNumber());
68         }
69         return null;
70     }
71 }