]> git.basschouten.com Git - openhab-addons.git/blob
350a0171b596e687ded31e46efe850e7f845397c
[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.modbus.sunspec.internal.discovery;
14
15 import static org.openhab.binding.modbus.sunspec.internal.SunSpecConstants.SUPPORTED_THING_TYPES_UIDS;
16
17 import java.util.HashSet;
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.modbus.discovery.ModbusDiscoveryListener;
22 import org.openhab.binding.modbus.discovery.ModbusDiscoveryParticipant;
23 import org.openhab.binding.modbus.handler.EndpointNotInitializedException;
24 import org.openhab.binding.modbus.handler.ModbusEndpointThingHandler;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.osgi.service.component.annotations.Component;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * Discovery service for sunspec
32  *
33  * @author Nagy Attila Gabor - initial contribution
34  *
35  */
36 @Component
37 @NonNullByDefault
38 public class SunspecDiscoveryParticipant implements ModbusDiscoveryParticipant {
39
40     private final Logger logger = LoggerFactory.getLogger(SunspecDiscoveryParticipant.class);
41
42     @Override
43     public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
44         return new HashSet<ThingTypeUID>(SUPPORTED_THING_TYPES_UIDS.values());
45     }
46
47     @Override
48     public void startDiscovery(ModbusEndpointThingHandler handler, ModbusDiscoveryListener listener) {
49         logger.trace("Starting sunspec discovery");
50         try {
51             new SunspecDiscoveryProcess(handler, listener).detectModel();
52         } catch (EndpointNotInitializedException ex) {
53             logger.debug("Could not start discovery process");
54             listener.discoveryFinished();
55         }
56     }
57 }