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 java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
22 import org.openhab.binding.freeboxos.internal.api.rest.HomeManager;
23 import org.openhab.binding.freeboxos.internal.api.rest.HomeManager.Endpoint;
24 import org.openhab.binding.freeboxos.internal.api.rest.HomeManager.EndpointState;
25 import org.openhab.core.config.core.Configuration;
26 import org.openhab.core.library.types.OpenClosedType;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.types.Command;
29 import org.openhab.core.types.State;
30 import org.openhab.core.types.UnDefType;
33 * The {@link BasicShutterHandler} is responsible for handling everything associated to
34 * any Freebox Home basic-shutter thing type.
36 * @author ben12 - Initial contribution
39 public class BasicShutterHandler extends HomeNodeHandler {
40 private static final Set<String> SHUTTER_ENDPOINTS = Set.of(SHUTTER_STOP, BASIC_SHUTTER_UP, BASIC_SHUTTER_DOWN);
42 public BasicShutterHandler(Thing thing) {
47 protected void internalConfigureChannel(String channelId, Configuration conf, List<Endpoint> endpoints) {
48 endpoints.stream().filter(ep -> channelId.equals(BASIC_SHUTTER_STATE) && SHUTTER_ENDPOINTS.contains(ep.name()))
49 .forEach(endPoint -> conf.put(endPoint.name(), endPoint.id()));
53 protected State getChannelState(HomeManager homeManager, String channelId, EndpointState state) {
54 String value = state.value();
55 return value != null && channelId.equals(BASIC_SHUTTER_STATE)
56 ? state.asBoolean() ? OpenClosedType.CLOSED : OpenClosedType.OPEN
61 protected boolean executeChannelCommand(HomeManager homeManager, String channelId, Command command,
62 Configuration config) throws FreeboxException {
63 Integer slot = getSlotId(config, command.toString().toLowerCase());
64 if (BASIC_SHUTTER_STATE.equals(channelId) && slot != null) {
65 return homeManager.putCommand(getClientId(), slot, true);