2 * Copyright (c) 2010-2024 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.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
21 import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager;
22 import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Config;
23 import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Status;
24 import org.openhab.core.library.types.OnOffType;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingStatus;
27 import org.openhab.core.types.Command;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The {@link FxsHandler} is responsible for handling everything associated to the landline associated with the
35 * @author Gaƫl L'hopital - Initial contribution
38 public class FxsHandler extends ApiConsumerHandler {
39 private final Logger logger = LoggerFactory.getLogger(FxsHandler.class);
41 public FxsHandler(Thing thing) {
46 void initializeProperties(Map<String, String> properties) throws FreeboxException {
47 getManager(PhoneManager.class).getStatus(getClientId())
48 .ifPresent(status -> properties.put(Thing.PROPERTY_VENDOR, status.vendor()));
52 protected void internalPoll() throws FreeboxException {
53 logger.debug("Polling landline status...");
55 Config config = getManager(PhoneManager.class).getConfig();
56 updateConfigChannels(config);
58 getManager(PhoneManager.class).getStatus(getClientId()).ifPresent(this::updateStatusChannels);
61 protected void updateConfigChannels(Config config) {
62 updateChannelString(TELEPHONY_SERVICE, config.network());
65 protected void updateStatusChannels(Status status) {
66 updateChannelOnOff(ONHOOK, status.onHook());
67 updateChannelOnOff(RINGING, status.isRinging());
68 updateChannelString(HARDWARE_STATUS, status.hardwareDefect() ? "KO" : "OK");
69 updateStatus(ThingStatus.ONLINE);
73 protected boolean internalHandleCommand(String channelId, Command command) throws FreeboxException {
74 if (RINGING.equals(channelId) && command instanceof OnOffType) {
75 getManager(PhoneManager.class).ringFxs(TRUE_COMMANDS.contains(command));
78 return super.internalHandleCommand(channelId, command);