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.handler;
15 import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
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;
28 * The {@link DectHandler} is responsible for handling DECT specifics of the Telephony API
30 * @author Gaƫl L'hopital - Initial contribution
33 public class DectHandler extends FxsHandler {
35 public DectHandler(Thing thing) {
40 protected void updateConfigChannels(Config config) {
41 super.updateConfigChannels(config);
42 updateChannelOnOff(DECT_ACTIVE, config.dectEnabled());
43 updateChannelOnOff(ALTERNATE_RING, config.dectRingOnOff());
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()));
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);
61 } else if (DECT_ACTIVE.equals(channelId)) {
62 phoneManager.setStatus(status);
64 } else if (ALTERNATE_RING.equals(channelId)) {
65 phoneManager.alternateRing(status);
69 if (command instanceof PercentType percentCommand) {
70 if (GAIN_RX.equals(channelId)) {
71 phoneManager.setGainRx(getClientId(), percentCommand.intValue());
72 updateIfActive(GAIN_RX, percentCommand);
74 } else if (GAIN_TX.equals(channelId)) {
75 phoneManager.setGainTx(getClientId(), percentCommand.intValue());
76 updateIfActive(GAIN_RX, percentCommand);
80 return super.internalHandleCommand(channelId, command);