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;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants;
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.ThingTypeUID;
23 import org.openhab.core.types.Command;
24 import org.openwebnet4j.message.BaseOpenMessage;
25 import org.openwebnet4j.message.Scenario.WhatScenario;
26 import org.openwebnet4j.message.Where;
27 import org.openwebnet4j.message.WhereLightAutom;
28 import org.openwebnet4j.message.Who;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link OpenWebNetScenarioBasicHandler} is responsible for handling Basic Scenario (WHO=0) messages.
34 * It extends the abstract {@link OpenWebNetThingHandler}.
36 * @author Massimo Valla - Initial contribution
39 public class OpenWebNetScenarioBasicHandler extends OpenWebNetThingHandler {
41 private final Logger logger = LoggerFactory.getLogger(OpenWebNetScenarioBasicHandler.class);
43 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.SCENARIO_BASIC_SUPPORTED_THING_TYPES;
45 public OpenWebNetScenarioBasicHandler(Thing thing) {
47 logger.debug("created Basic Scenario device for thing: {}", getThing().getUID());
51 protected String ownIdPrefix() {
52 return Who.SCENARIO.value().toString();
56 protected void handleMessage(BaseOpenMessage msg) {
57 super.handleMessage(msg);
58 if (msg.isCommand()) {
59 WhatScenario scenario = (WhatScenario) msg.getWhat();
60 if (scenario == null) {
61 logger.warn("Invalid Basic Scenario: {}. Ignoring message {}", scenario, msg);
64 logger.debug("Basic Scenario {} has been activated", scenario);
65 triggerChannel(OpenWebNetBindingConstants.CHANNEL_SCENARIO, scenario.toString());
67 logger.debug("handleMessage() Ignoring unsupported DIM for thing {}. Frame={}", getThing().getUID(), msg);
72 protected void handleChannelCommand(ChannelUID channel, Command command) {
73 logger.debug("Basic Scenario are read-only channels. Ignoring command {} for channel {}", command, channel);
77 protected void requestChannelState(ChannelUID channel) {
78 logger.debug("requestChannelState() Basic Scenario channels are trigger channels and do not have state.");
82 protected void refreshDevice(boolean refreshAll) {
83 logger.debug("Basic Scenario channels are trigger channels and do not have state. Setting it ONLINE");
84 // put basic scenario things to ONLINE automatically as they do not have state
85 ThingStatus ts = getThing().getStatus();
86 if (ThingStatus.ONLINE != ts && ThingStatus.REMOVING != ts && ThingStatus.REMOVED != ts) {
87 updateStatus(ThingStatus.ONLINE);
92 protected Where buildBusWhere(String wStr) throws IllegalArgumentException {
93 return new WhereLightAutom(wStr);