]> git.basschouten.com Git - openhab-addons.git/blob
6455e649beab5db6ec2d1b752c14092ac7d25b78
[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.IntegraVersionEvent;
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 Integra version and type.
24  *
25  * @author Krzysztof Goworek - Initial contribution
26  */
27 @NonNullByDefault
28 public class IntegraVersionCommand extends SatelCommandBase {
29
30     private final Logger logger = LoggerFactory.getLogger(IntegraVersionCommand.class);
31
32     public static final byte COMMAND_CODE = 0x7e;
33
34     /**
35      * Creates new command class instance.
36      */
37     public IntegraVersionCommand() {
38         super(COMMAND_CODE, false);
39     }
40
41     /**
42      * @return Integra firmware version and release date
43      */
44     public String getVersion() {
45         return getVersion(1);
46     }
47
48     /**
49      * @return Integra type
50      */
51     public byte getType() {
52         return getResponse().getPayload()[0];
53     }
54
55     /**
56      * @return firmware language
57      */
58     public byte getLanguage() {
59         return getResponse().getPayload()[12];
60     }
61
62     /**
63      * @return <code>true</code> if alarm settings are stored in flash memory
64      */
65     public boolean areSettingsInFlash() {
66         return getResponse().getPayload()[13] == (byte) 0xFF;
67     }
68
69     @Override
70     protected boolean isResponseValid(SatelMessage response) {
71         // validate response
72         if (response.getPayload().length != 14) {
73             logger.debug("Invalid payload length: {}", response.getPayload().length);
74             return false;
75         }
76         return true;
77     }
78
79     @Override
80     protected void handleResponseInternal(final EventDispatcher eventDispatcher) {
81         // dispatch version event
82         eventDispatcher
83                 .dispatchEvent(new IntegraVersionEvent(getType(), getVersion(), getLanguage(), areSettingsInFlash()));
84     }
85 }