]> git.basschouten.com Git - openhab-addons.git/blob
a474b4c59a37a4898f32b836ab5cb3aa91f91cf9
[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 static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Status;
19 import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Type;
20 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
21 import org.openhab.core.thing.ThingUID;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * The {@link PhoneConfigurationBuilder} is responsible for holding configuration informations associated the phone
27  * lines (DECT and FXS / landline)
28  *
29  * @author GaĆ«l L'hopital - Initial contribution
30  */
31 @NonNullByDefault
32 public class PhoneConfigurationBuilder {
33     private static final PhoneConfigurationBuilder BUILDER_INSTANCE = new PhoneConfigurationBuilder();
34
35     private final Logger logger = LoggerFactory.getLogger(PhoneConfigurationBuilder.class);
36
37     private PhoneConfigurationBuilder() {
38     }
39
40     public static PhoneConfigurationBuilder getInstance() {
41         return BUILDER_INSTANCE;
42     }
43
44     public DiscoveryResultBuilder configure(ThingUID bridgeUID, Status config) {
45         ThingUID thingUID;
46         String label;
47         if (Type.DECT.equals(config.type())) {
48             thingUID = new ThingUID(THING_TYPE_DECT, bridgeUID, Integer.toString(config.id()));
49             label = "DECT Phone";
50         } else {
51             thingUID = new ThingUID(THING_TYPE_FXS, bridgeUID, Integer.toString(config.id()));
52             label = "Landline Phone";
53         }
54
55         logger.debug("Adding new Freebox Phone {} to inbox", thingUID);
56
57         return DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
58                 .withProperty(ClientConfiguration.ID, config.id()).withLabel(label)
59                 .withRepresentationProperty(ClientConfiguration.ID);
60     }
61 }