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.freeboxos.internal.config;
15 import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
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;
25 import inet.ipaddr.mac.MACAddress;
28 * The {@link FreeplugConfigurationBuilder} is responsible for holding configuration informations associated to a
31 * @author Gaƫl L'hopital - Initial contribution
34 public class FreeplugConfigurationBuilder {
35 private static final FreeplugConfigurationBuilder BUILDER_INSTANCE = new FreeplugConfigurationBuilder();
37 private final Logger logger = LoggerFactory.getLogger(FreeplugConfigurationBuilder.class);
39 private FreeplugConfigurationBuilder() {
42 public static FreeplugConfigurationBuilder getInstance() {
43 return BUILDER_INSTANCE;
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);
51 logger.debug("Adding new {} {} to inbox", THING_FREEPLUG, thingUID);
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());