]> git.basschouten.com Git - openhab-addons.git/blob
c5ea61bf363ae79c7c1ab3ee42bab7f854d9f6ee
[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.handler;
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.FreeboxException;
19 import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager;
20 import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Config;
21 import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Status;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.library.types.PercentType;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.types.Command;
26
27 /**
28  * The {@link DectHandler} is responsible for handling DECT specifics of the Telephony API
29  *
30  * @author GaĆ«l L'hopital - Initial contribution
31  */
32 @NonNullByDefault
33 public class DectHandler extends FxsHandler {
34
35     public DectHandler(Thing thing) {
36         super(thing);
37     }
38
39     @Override
40     protected void updateConfigChannels(Config config) {
41         super.updateConfigChannels(config);
42         updateChannelOnOff(DECT_ACTIVE, config.dectEnabled());
43         updateChannelOnOff(ALTERNATE_RING, config.dectRingOnOff());
44     }
45
46     @Override
47     protected void updateStatusChannels(Status status) {
48         super.updateStatusChannels(status);
49         updateIfActive(GAIN_RX, new PercentType(status.gainRx()));
50         updateIfActive(GAIN_TX, new PercentType(status.gainTx()));
51     }
52
53     @Override
54     protected boolean internalHandleCommand(String channelId, Command command) throws FreeboxException {
55         PhoneManager phoneManager = getManager(PhoneManager.class);
56         if (command instanceof OnOffType) {
57             boolean status = OnOffType.ON.equals(command);
58             if (RINGING.equals(channelId)) {
59                 phoneManager.ringDect(status);
60                 return true;
61             } else if (DECT_ACTIVE.equals(channelId)) {
62                 phoneManager.setStatus(status);
63                 return true;
64             } else if (ALTERNATE_RING.equals(channelId)) {
65                 phoneManager.alternateRing(status);
66                 return true;
67             }
68         }
69         if (command instanceof PercentType percentCommand) {
70             if (GAIN_RX.equals(channelId)) {
71                 phoneManager.setGainRx(getClientId(), percentCommand.intValue());
72                 updateIfActive(GAIN_RX, percentCommand);
73                 return true;
74             } else if (GAIN_TX.equals(channelId)) {
75                 phoneManager.setGainTx(getClientId(), percentCommand.intValue());
76                 updateIfActive(GAIN_RX, percentCommand);
77                 return true;
78             }
79         }
80         return super.internalHandleCommand(channelId, command);
81     }
82 }