2 * Copyright (c) 2010-2023 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.plex.internal.discovery;
15 import static org.openhab.binding.plex.internal.PlexBindingConstants.*;
17 import java.util.HashMap;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.plex.internal.handler.PlexServerHandler;
22 import org.openhab.core.config.discovery.AbstractDiscoveryService;
23 import org.openhab.core.config.discovery.DiscoveryResult;
24 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.ThingUID;
29 * @author Brian Homeyer - Initial contribution
30 * @author Aron Beurskens - Binding development
33 public class PlexDiscoveryService extends AbstractDiscoveryService {
34 private final PlexServerHandler bridgeHandler;
36 public PlexDiscoveryService(PlexServerHandler bridgeHandler) {
37 super(SUPPORTED_THING_TYPES_UIDS, 10, false);
38 this.bridgeHandler = bridgeHandler;
42 protected void startScan() {
43 for (String machineId : bridgeHandler.getAvailablePlayers()) {
44 ThingUID bridgeUID = bridgeHandler.getThing().getUID();
45 ThingTypeUID thingTypeUID = UID_PLAYER;
46 ThingUID playerThingUid = new ThingUID(UID_PLAYER, bridgeUID, machineId);
48 Map<String, Object> properties = new HashMap<>();
49 properties.put(CONFIG_PLAYER_ID, machineId);
51 DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(playerThingUid).withThingType(thingTypeUID)
52 .withProperties(properties).withBridge(bridgeUID).withRepresentationProperty(CONFIG_PLAYER_ID)
53 .withLabel("PLEX Player (" + machineId + ")").build();
55 thingDiscovered(discoveryResult);