]> git.basschouten.com Git - openhab-addons.git/blob
bd8e772f50930a8e50d19de5c65eb0ef4bbfeaba
[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.satel.internal.command;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.satel.internal.event.EventDispatcher;
17 import org.openhab.binding.satel.internal.event.ModuleVersionEvent;
18 import org.openhab.binding.satel.internal.protocol.SatelMessage;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * Command class for command that returns communication module version.
24  *
25  * @author Krzysztof Goworek - Initial contribution
26  */
27 @NonNullByDefault
28 public class ModuleVersionCommand extends SatelCommandBase {
29
30     private final Logger logger = LoggerFactory.getLogger(ModuleVersionCommand.class);
31
32     public static final byte COMMAND_CODE = 0x7c;
33
34     /**
35      * Creates new command class instance.
36      */
37     public ModuleVersionCommand() {
38         super(COMMAND_CODE, false);
39     }
40
41     /**
42      * @return communication module firmware version and release date
43      */
44     public String getVersion() {
45         return getVersion(0);
46     }
47
48     /**
49      * @return <code>true</code> if the module supports extended (32-bit) payload for zones/outputs
50      */
51     public boolean hasExtPayloadSupport() {
52         return (getResponse().getPayload()[11] & 0x01) != 0;
53     }
54
55     @Override
56     protected boolean isResponseValid(SatelMessage response) {
57         // validate response
58         if (response.getPayload().length != 12) {
59             logger.debug("Invalid payload length: {}", response.getPayload().length);
60             return false;
61         }
62         return true;
63     }
64
65     @Override
66     protected void handleResponseInternal(final EventDispatcher eventDispatcher) {
67         // dispatch version event
68         eventDispatcher.dispatchEvent(new ModuleVersionEvent(getVersion(), hasExtPayloadSupport()));
69     }
70 }