]> git.basschouten.com Git - openhab-addons.git/blob
0de2a2f02f4c1f9e51bf0c779eb8d0cd3f287440
[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.freeboxos.internal.config;
14
15 import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.freeboxos.internal.api.rest.FreeplugManager.Freeplug;
19 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.ThingUID;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import inet.ipaddr.mac.MACAddress;
26
27 /**
28  * The {@link FreeplugConfigurationBuilder} is responsible for holding configuration informations associated to a
29  * Freeplug
30  *
31  * @author GaĆ«l L'hopital - Initial contribution
32  */
33 @NonNullByDefault
34 public class FreeplugConfigurationBuilder {
35     private static final FreeplugConfigurationBuilder BUILDER_INSTANCE = new FreeplugConfigurationBuilder();
36
37     private final Logger logger = LoggerFactory.getLogger(FreeplugConfigurationBuilder.class);
38
39     private FreeplugConfigurationBuilder() {
40     }
41
42     public static FreeplugConfigurationBuilder getInstance() {
43         return BUILDER_INSTANCE;
44     }
45
46     public DiscoveryResultBuilder configure(ThingUID bridgeUID, Freeplug plug) {
47         MACAddress mac = plug.id();
48         String uid = mac.toHexString(false);
49         ThingUID thingUID = new ThingUID(THING_TYPE_FREEPLUG, bridgeUID, uid);
50
51         logger.debug("Adding new {} {} to inbox", THING_FREEPLUG, thingUID);
52
53         return DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
54                 .withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS)
55                 .withLabel("%s (%s) %s".formatted(THING_FREEPLUG, plug.netRole().name(), uid))
56                 .withProperty(Thing.PROPERTY_MAC_ADDRESS, mac.toColonDelimitedString());
57     }
58 }