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.openwebnet.internal.handler;
15 import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_AUX;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants;
21 import org.openhab.core.library.types.StringType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingStatus;
25 import org.openhab.core.thing.ThingStatusDetail;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.types.Command;
28 import org.openwebnet4j.communication.OWNException;
29 import org.openwebnet4j.message.Auxiliary;
30 import org.openwebnet4j.message.BaseOpenMessage;
31 import org.openwebnet4j.message.MalformedFrameException;
32 import org.openwebnet4j.message.OpenMessage;
33 import org.openwebnet4j.message.UnsupportedFrameException;
34 import org.openwebnet4j.message.Where;
35 import org.openwebnet4j.message.WhereAuxiliary;
36 import org.openwebnet4j.message.Who;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * The {@link OpenWebNetAuxiliaryHandler} is responsible for sending Auxiliary (AUX) commands/messages to the bus
42 * It extends the abstract {@link OpenWebNetThingHandler}.
44 * NOTICE: Support for handling messages from the bus regarding alarm control has to be implemented
46 * @author Giovanni Fabiani - Initial contribution
50 public class OpenWebNetAuxiliaryHandler extends OpenWebNetThingHandler {
52 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.AUX_SUPPORTED_THING_TYPES;
53 private final Logger logger = LoggerFactory.getLogger(OpenWebNetAuxiliaryHandler.class);
55 public OpenWebNetAuxiliaryHandler(Thing thing) {
60 * Handles Auxiliary command for a channel
62 * @param channel the channel
63 * @param command the Command
66 protected void handleChannelCommand(ChannelUID channel, Command command) {
67 logger.debug("handleAuxiliaryCommand() (command={} - channel={})", command, channel);
68 Where w = deviceWhere;
70 if (channel.getId().equals(CHANNEL_AUX)) {
71 if (command instanceof StringType) {
73 if (command.toString().equals(Auxiliary.WhatAuxiliary.ON.name())) {
74 send(Auxiliary.requestTurnOn(w.value()));
75 } else if (command.toString().equals(Auxiliary.WhatAuxiliary.OFF.name())) {
76 send(Auxiliary.requestTurnOff(w.value()));
78 } catch (OWNException e) {
79 logger.debug("Exception while processing command {}: {}", command, e.getMessage());
82 logger.debug("Unsupported command {} for channel {}", command, channel);
85 logger.debug("Unsupported ChannelUID {}", channel);
91 protected void requestChannelState(ChannelUID channel) {
93 * NOTICE: It is not possible to get the state of a
94 * WHO=9 command. To get state of the Alarm system use WHO=5 instead
97 super.requestChannelState(channel);
98 Where w = deviceWhere;
101 OpenMessage msg = BaseOpenMessage.parse("*#9##");
104 } catch (MalformedFrameException | UnsupportedFrameException | OWNException e) {
105 logger.debug("Exception while processing command: {}", e.getMessage());
106 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
112 protected void refreshDevice(boolean refreshAll) {
114 * NOTICE: It is not possible to refresh the state of a
115 * WHO=9 command. To refresh the state of the Alarm system use WHO=5 instead
118 logger.debug("--- refreshDevice() : refreshing SINGLE... ({})", thing.getUID());
119 requestChannelState(new ChannelUID(thing.getUID(), CHANNEL_AUX));
123 protected Where buildBusWhere(String wStr) throws IllegalArgumentException {
124 return new WhereAuxiliary(wStr);
128 protected String ownIdPrefix() {
129 return Who.AUX.value().toString();