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 static org.openhab.core.library.unit.SIUnits.CELSIUS;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.cbus.CBusBindingConstants;
19 import org.openhab.core.library.types.QuantityType;
20 import org.openhab.core.thing.Channel;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.thing.ThingStatus;
24 import org.openhab.core.thing.ThingStatusDetail;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.RefreshType;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import com.daveoxley.cbus.CGateException;
31 import com.daveoxley.cbus.Group;
34 * The {@link CBusTemperatureHandler} is responsible for handling commands, which are
35 * sent to one of the channels.
37 * @author Scott Linton - Initial contribution
40 public class CBusTemperatureHandler extends CBusGroupHandler {
42 private final Logger logger = LoggerFactory.getLogger(CBusTemperatureHandler.class);
44 public CBusTemperatureHandler(Thing thing) {
45 super(thing, CBusBindingConstants.CBUS_APPLICATION_TEMPERATURE);
49 public void handleCommand(ChannelUID channelUID, Command command) {
50 // Read only thing - no commands to handle
51 if (command instanceof RefreshType) {
53 Group group = this.group;
55 int level = group.getLevel();
56 logger.debug("handle RefreshType Command for Chanell {} Group {} level {}", channelUID, groupId,
58 if (channelUID.getId().equals(CBusBindingConstants.CHANNEL_TEMP)) {
59 updateState(channelUID, new QuantityType<>(level, CELSIUS));
62 } catch (CGateException e) {
63 logger.debug("Failed to getLevel for group {}", groupId, e);
64 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication Error");
70 public void updateGroup(int updateApplicationId, int updateGroupId, String value) {
71 if (updateGroupId == groupId && updateApplicationId == applicationId) {
72 Thing thing = getThing();
73 Channel channel = thing.getChannel(CBusBindingConstants.CHANNEL_TEMP);
75 if (channel != null) {
76 ChannelUID channelUID = channel.getUID();
77 updateState(channelUID, new QuantityType<>(Double.parseDouble(value), CELSIUS));
78 logger.trace("Updating CBus Temperature Group {} with value {}", thing.getUID(), value);
80 logger.trace("Failed to Update CBus Temperature Group {} with value {}: No Channel", thing.getUID(),