]> git.basschouten.com Git - openhab-addons.git/blob
f02c649e53f8246edf706756c190cbb9590df3be
[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.plex.internal.discovery;
14
15 import static org.openhab.binding.plex.internal.PlexBindingConstants.*;
16
17 import java.util.HashMap;
18 import java.util.Map;
19
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;
27
28 /**
29  * @author Brian Homeyer - Initial contribution
30  * @author Aron Beurskens - Binding development
31  */
32 @NonNullByDefault
33 public class PlexDiscoveryService extends AbstractDiscoveryService {
34     private final PlexServerHandler bridgeHandler;
35
36     public PlexDiscoveryService(PlexServerHandler bridgeHandler) {
37         super(SUPPORTED_THING_TYPES_UIDS, 10, false);
38         this.bridgeHandler = bridgeHandler;
39     }
40
41     @Override
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);
47
48             Map<String, Object> properties = new HashMap<>();
49             properties.put(CONFIG_PLAYER_ID, machineId);
50
51             DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(playerThingUid).withThingType(thingTypeUID)
52                     .withProperties(properties).withBridge(bridgeUID).withRepresentationProperty(CONFIG_PLAYER_ID)
53                     .withLabel("PLEX Player (" + machineId + ")").build();
54
55             thingDiscovered(discoveryResult);
56         }
57     }
58 }