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.satel.internal.handler;
15 import static org.openhab.binding.satel.internal.SatelBindingConstants.THING_TYPE_OUTPUT;
17 import java.util.Optional;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.satel.internal.command.ControlObjectCommand;
22 import org.openhab.binding.satel.internal.command.SatelCommand;
23 import org.openhab.binding.satel.internal.types.OutputControl;
24 import org.openhab.binding.satel.internal.types.OutputState;
25 import org.openhab.binding.satel.internal.types.StateType;
26 import org.openhab.core.library.types.OnOffType;
27 import org.openhab.core.thing.ChannelUID;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.types.Command;
33 * The {@link SatelOutputHandler} is responsible for handling commands, which are
34 * sent to one of the channels of an output device.
36 * @author Krzysztof Goworek - Initial contribution
39 public class SatelOutputHandler extends WirelessChannelsHandler {
41 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_OUTPUT);
43 public SatelOutputHandler(Thing thing) {
48 protected Optional<SatelCommand> convertCommand(ChannelUID channel, Command command) {
49 if (command instanceof OnOffType && getStateType(channel.getId()) == OutputState.STATE) {
50 final SatelBridgeHandler bridgeHandler = getBridgeHandler();
51 boolean switchOn = (command == OnOffType.ON);
52 int size = bridgeHandler.getIntegraType().hasExtPayload() ? 32 : 16;
53 byte[] outputs = getObjectBitset(size, getThingConfig().getId());
54 boolean newState = switchOn ^ getThingConfig().isStateInverted();
55 return Optional.of(new ControlObjectCommand(newState ? OutputControl.ON : OutputControl.OFF, outputs,
56 bridgeHandler.getUserCode(), scheduler));
59 return Optional.empty();
63 @SuppressWarnings("PMD.CompareObjectsWithEquals")
64 protected StateType getStateType(String channelId) {
65 StateType result = super.getStateType(channelId);
66 if (result == StateType.NONE) {
67 result = OutputState.valueOf(channelId.toUpperCase());