2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.insteon.internal.discovery;
15 import java.util.Arrays;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 import java.util.List;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.insteon.internal.InsteonBindingConstants;
23 import org.openhab.binding.insteon.internal.handler.InsteonNetworkHandler;
24 import org.openhab.core.config.discovery.AbstractDiscoveryService;
25 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
26 import org.openhab.core.thing.ThingUID;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * The {@link InsteonDeviceDiscoveryService} is responsible for device discovery.
33 * @author Rob Nielsen - Initial contribution
36 public class InsteonDeviceDiscoveryService extends AbstractDiscoveryService {
37 private static final String ADDRESS = "address";
39 private final Logger logger = LoggerFactory.getLogger(InsteonDeviceDiscoveryService.class);
41 public InsteonDeviceDiscoveryService(InsteonNetworkHandler handler) {
42 super(new HashSet<>(Arrays.asList(InsteonBindingConstants.DEVICE_THING_TYPE)), 0, false);
44 handler.setInsteonDeviceDiscoveryService(this);
46 logger.debug("Initializing InsteonNetworkDiscoveryService");
50 protected void startScan() {
53 public void addInsteonDevices(List<String> addresses, ThingUID bridgeUid) {
54 for (String address : addresses) {
55 String[] parts = address.split("\\.");
56 if (parts.length != 3) {
57 logger.warn("Address {} must be in the format XX.XX.XX", address);
62 String name = parts[0] + parts[1] + parts[2];
63 ThingUID uid = new ThingUID(InsteonBindingConstants.DEVICE_THING_TYPE, bridgeUid, name);
64 Map<String, Object> properties = new HashMap<>();
65 properties.put(ADDRESS, address);
68 DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel("Insteon Device " + name)
69 .withBridge(bridgeUid).withRepresentationProperty(ADDRESS).build());
71 logger.debug("Added Insteon device {} with the address {}", name, address);