2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.satel.internal.command;
15 import java.time.DateTimeException;
16 import java.time.LocalDateTime;
17 import java.util.Optional;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.satel.internal.event.EventDispatcher;
21 import org.openhab.binding.satel.internal.event.IntegraStatusEvent;
22 import org.openhab.binding.satel.internal.protocol.SatelMessage;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Command class for command that returns Integra RTC and basic status.
29 * @author Krzysztof Goworek - Initial contribution
32 public class IntegraStatusCommand extends SatelCommandBase {
34 private final Logger logger = LoggerFactory.getLogger(IntegraStatusCommand.class);
36 public static final byte COMMAND_CODE = 0x1a;
39 * Creates new command class instance.
41 public IntegraStatusCommand() {
42 super(COMMAND_CODE, false);
46 * @return date and time
48 public Optional<LocalDateTime> getIntegraTime() {
49 // parse current date and time
51 final byte[] payload = getResponse().getPayload();
53 .of(LocalDateTime.of(bcdToInt(payload, 0, 2), bcdToInt(payload, 2, 1), bcdToInt(payload, 3, 1),
54 bcdToInt(payload, 4, 1), bcdToInt(payload, 5, 1), bcdToInt(payload, 6, 1)));
55 } catch (DateTimeException e) {
56 logger.debug("Invalid date/time set in the system", e);
57 return Optional.empty();
62 * @return first status byte
64 public byte getStatusByte1() {
65 return getResponse().getPayload()[7];
69 * @return second status byte
71 public byte getStatusByte2() {
72 return getResponse().getPayload()[8];
76 protected boolean isResponseValid(SatelMessage response) {
77 if (response.getPayload().length != 9) {
78 logger.debug("Invalid payload length: {}", response.getPayload().length);
85 protected void handleResponseInternal(final EventDispatcher eventDispatcher) {
86 // dispatch version event
87 eventDispatcher.dispatchEvent(new IntegraStatusEvent(getIntegraTime(), getStatusByte1(), getStatusByte2()));