]> git.basschouten.com Git - openhab-addons.git/blob
1e7809b7897309494be61abb84e9eb40cde1a20d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.NewStatesEvent;
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 list of states changed since last state read.
24  *
25  * @author Krzysztof Goworek - Initial contribution
26  */
27 @NonNullByDefault
28 public class NewStatesCommand extends SatelCommandBase {
29
30     private final Logger logger = LoggerFactory.getLogger(NewStatesCommand.class);
31
32     public static final byte COMMAND_CODE = 0x7f;
33
34     /**
35      * Creates new command class instance.
36      *
37      * @param extended if <code>true</code> command will be sent as extended (256 zones or outputs)
38      */
39     public NewStatesCommand(boolean extended) {
40         super(COMMAND_CODE, extended);
41     }
42
43     @Override
44     protected boolean isResponseValid(SatelMessage response) {
45         // validate response
46         if (response.getPayload().length < 5 || response.getPayload().length > 6) {
47             logger.debug("Invalid payload length: {}", response.getPayload().length);
48             return false;
49         }
50         return true;
51     }
52
53     @Override
54     protected void handleResponseInternal(final EventDispatcher eventDispatcher) {
55         // dispatch event
56         eventDispatcher.dispatchEvent(new NewStatesEvent(getResponse().getPayload()));
57     }
58 }