]> git.basschouten.com Git - openhab-addons.git/blob
18e0c882f5759848f350c90cd5f3e2015bc334d4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.freeboxos.internal.config;
14
15 import java.util.Optional;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.freeboxos.internal.api.rest.HomeManager.Category;
19 import org.openhab.binding.freeboxos.internal.api.rest.HomeManager.HomeNode;
20 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
21 import org.openhab.core.thing.ThingUID;
22
23 /**
24  * The {@link NodeConfigurationBuilder} is responsible for holding configuration informations associated to a Freebox
25  * Home thing type
26  *
27  * @author ben12 - Initial contribution
28  */
29 @NonNullByDefault
30 public class NodeConfigurationBuilder {
31     private static final NodeConfigurationBuilder BUILDER_INSTANCE = new NodeConfigurationBuilder();
32
33     private NodeConfigurationBuilder() {
34     }
35
36     public static NodeConfigurationBuilder getInstance() {
37         return BUILDER_INSTANCE;
38     }
39
40     public Optional<DiscoveryResultBuilder> configure(ThingUID bridgeUID, HomeNode node) {
41         if (node.category() == Category.UNKNOWN) {
42             return Optional.empty();
43         }
44         ThingUID thingUID = new ThingUID(node.category().getThingTypeUID(), bridgeUID, Integer.toString(node.id()));
45         DiscoveryResultBuilder discoveryResultBuilder = DiscoveryResultBuilder.create(thingUID);
46         discoveryResultBuilder.withProperty(ClientConfiguration.ID, node.id()).withLabel(node.label())
47                 .withRepresentationProperty(ClientConfiguration.ID).withBridge(bridgeUID);
48         return Optional.of(discoveryResultBuilder);
49     }
50 }