]> git.basschouten.com Git - openhab-addons.git/blob
aed0f493fff54291ce9f02e9a339caa49816a1db
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.globalcache.internal.command;
14
15 import java.util.concurrent.LinkedBlockingQueue;
16
17 import org.openhab.binding.globalcache.internal.GlobalCacheBindingConstants.CommandType;
18 import org.openhab.core.thing.Thing;
19 import org.openhab.core.types.Command;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * The {@link CommandSendir} class implements the GlobalCache sendir command, which sends
25  * an infrared command to the device.
26  *
27  * @author Mark Hilbush - Initial contribution
28  */
29 public class CommandSendir extends AbstractCommand {
30
31     private final Logger logger = LoggerFactory.getLogger(CommandSendir.class);
32
33     private String rcvCounter;
34     Command command;
35
36     public CommandSendir(Thing thing, Command command, LinkedBlockingQueue<RequestMessage> queue, String mod,
37             String con, String code, int sendCounter) {
38         super(thing, queue, "sendir", CommandType.COMMAND);
39
40         this.command = command;
41         deviceCommand = "sendir," + mod + ":" + con + "," + String.valueOf(sendCounter) + "," + code;
42     }
43
44     @Override
45     public void parseSuccessfulReply() {
46         if (deviceReply == null) {
47             return;
48         }
49
50         // decode response of form completeir,1:1,<ID>
51         if (deviceReply.startsWith("completeir")) {
52             setModule(deviceReply.substring(11, 12));
53             setConnector(deviceReply.substring(13, 14));
54             setRcvCounter(deviceReply.substring(15));
55         }
56     }
57
58     private void setRcvCounter(String c) {
59         rcvCounter = c;
60     }
61
62     public String getRcvCounter() {
63         return rcvCounter;
64     }
65
66     @Override
67     public void logSuccess() {
68         logger.debug("Execute '{}' succeeded for command {} on thing {} at {}", commandName, command.toString(),
69                 thing.getUID().getId(), ipAddress);
70     }
71
72     @Override
73     public void logFailure() {
74         logger.error("Execute '{}' failed on thing {} at {}: errorCode={}, errorMessage={}", commandName,
75                 thing.getUID().getId(), ipAddress, errorCode, errorMessage);
76     }
77 }