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.cbus.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.cbus.CBusBindingConstants;
17 import org.openhab.core.library.types.DecimalType;
18 import org.openhab.core.thing.Channel;
19 import org.openhab.core.thing.ChannelUID;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.ThingStatus;
22 import org.openhab.core.thing.ThingStatusDetail;
23 import org.openhab.core.types.Command;
24 import org.openhab.core.types.RefreshType;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.daveoxley.cbus.CGateException;
29 import com.daveoxley.cbus.Group;
32 * The {@link CBusTriggerHandler} is responsible for handling commands, which are
33 * sent to one of the channels.
35 * @author Scott Linton - Initial contribution
38 public class CBusTriggerHandler extends CBusGroupHandler {
40 private final Logger logger = LoggerFactory.getLogger(CBusTriggerHandler.class);
42 public CBusTriggerHandler(Thing thing) {
43 super(thing, CBusBindingConstants.CBUS_APPLICATION_TRIGGER);
47 public void handleCommand(ChannelUID channelUID, Command command) {
48 Group group = this.group;
52 if (command instanceof RefreshType) {
54 * Cgate cant provide the current value for a trigger group
56 logger.debug("Refresh for Trigger group not implemented");
58 if (channelUID.getId().equals(CBusBindingConstants.CHANNEL_VALUE)) {
59 logger.debug("Channel Value command for {}: {}", channelUID, command);
61 if (command instanceof DecimalType decimalCommand) {
62 group.TriggerEvent(decimalCommand.intValue());
64 } catch (CGateException e) {
65 logger.debug("Failed to send trigger command {} to {}", command, group, e);
66 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication Error");
73 public void updateGroup(int updateApplicationId, int updateGroupId, String value) {
74 if (updateGroupId == groupId && updateApplicationId == applicationId) {
75 Thing thing = getThing();
76 Channel channel = thing.getChannel(CBusBindingConstants.CHANNEL_VALUE);
77 if (channel != null) {
78 ChannelUID channelUID = channel.getUID();
79 DecimalType val = new DecimalType(value);
80 updateState(channelUID, val);
81 logger.trace("Updating CBus Trigger Group {} with value {}", thing.getUID(), value);