]> git.basschouten.com Git - openhab-addons.git/blob
e6849562ef7d20ba519be21d551bb839712ad07d
[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.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * The {@link CommandGetversion} class implements the GlobalCache getversion command, which retrieves software
24  * version of the device.
25  *
26  * @author Mark Hilbush - Initial contribution
27  */
28 public class CommandGetversion extends AbstractCommand {
29
30     private final Logger logger = LoggerFactory.getLogger(CommandGetversion.class);
31
32     private String version;
33
34     public CommandGetversion(Thing thing, LinkedBlockingQueue<RequestMessage> requestQueue) {
35         super(thing, requestQueue, "getversion", CommandType.COMMAND);
36         deviceCommand = "getversion";
37     }
38
39     @Override
40     public void parseSuccessfulReply() {
41         if (deviceReply == null) {
42             return;
43         }
44         // decode response of form <textversionstring>
45         version = deviceReply;
46     }
47
48     public String getVersion() {
49         return version;
50     }
51
52     @Override
53     public void logSuccess() {
54         logger.debug("Execute '{}' succeeded on thing {} at {}, version={}", commandName, thing.getUID().getId(),
55                 ipAddress, version);
56     }
57
58     @Override
59     public void logFailure() {
60         logger.error("Execute '{}' failed for thing {} at {}, errorCode={}, errorMessage={}", commandName,
61                 thing.getUID().getId(), ipAddress, errorCode, errorMessage);
62     }
63 }