2 * Copyright (c) 2010-2020 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.LocalDateTime;
16 import java.time.format.DateTimeFormatter;
18 import org.apache.commons.lang.ArrayUtils;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
22 * Command class for command to set RTC clock.
24 * @author Krzysztof Goworek - Initial contribution
27 public class SetClockCommand extends ControlCommand {
29 public static final byte COMMAND_CODE = (byte) 0x8e;
31 private static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
34 * Creates new command class instance.
36 * @param dateTime date and time to set
37 * @param userCode code of the user on behalf the control is made
39 public SetClockCommand(LocalDateTime dateTime, String userCode) {
40 super(COMMAND_CODE, ArrayUtils.addAll(userCodeToBytes(userCode), getDateTimeBytes(dateTime)));
43 private static byte[] getDateTimeBytes(LocalDateTime dateTime) {
44 return DATETIME_FORMAT.format(dateTime).getBytes();