]> git.basschouten.com Git - openhab-addons.git/blob
fe3611ef4729506fe1e7d94efa09bfb64d6a6a37
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.openwebnet.internal.handler;
14
15 import java.util.Set;
16
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;
31
32 /**
33  * The {@link OpenWebNetScenarioBasicHandler} is responsible for handling Basic Scenario (WHO=0) messages.
34  * It extends the abstract {@link OpenWebNetThingHandler}.
35  *
36  * @author Massimo Valla - Initial contribution
37  */
38 @NonNullByDefault
39 public class OpenWebNetScenarioBasicHandler extends OpenWebNetThingHandler {
40
41     private final Logger logger = LoggerFactory.getLogger(OpenWebNetScenarioBasicHandler.class);
42
43     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.SCENARIO_BASIC_SUPPORTED_THING_TYPES;
44
45     public OpenWebNetScenarioBasicHandler(Thing thing) {
46         super(thing);
47         logger.debug("created Basic Scenario device for thing: {}", getThing().getUID());
48     }
49
50     @Override
51     protected String ownIdPrefix() {
52         return Who.SCENARIO.value().toString();
53     }
54
55     @Override
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);
62                 return;
63             }
64             logger.debug("Basic Scenario {} has been activated", scenario);
65             triggerChannel(OpenWebNetBindingConstants.CHANNEL_SCENARIO, scenario.toString());
66         } else {
67             logger.debug("handleMessage() Ignoring unsupported DIM for thing {}. Frame={}", getThing().getUID(), msg);
68         }
69     }
70
71     @Override
72     protected void handleChannelCommand(ChannelUID channel, Command command) {
73         logger.debug("Basic Scenario are read-only channels. Ignoring command {} for channel {}", command, channel);
74     }
75
76     @Override
77     protected void requestChannelState(ChannelUID channel) {
78         logger.debug("requestChannelState() Basic Scenario channels are trigger channels and do not have state.");
79     }
80
81     @Override
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);
88         }
89     }
90
91     @Override
92     protected Where buildBusWhere(String wStr) throws IllegalArgumentException {
93         return new WhereLightAutom(wStr);
94     }
95 }