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.LocalDateTime;
16 import java.time.format.DateTimeFormatter;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
21 * Command class for command to set RTC clock.
23 * @author Krzysztof Goworek - Initial contribution
26 public class SetClockCommand extends ControlCommand {
28 public static final byte COMMAND_CODE = (byte) 0x8e;
30 private static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
33 * Creates new command class instance.
35 * @param dateTime date and time to set
36 * @param userCode code of the user on behalf the control is made
38 public SetClockCommand(LocalDateTime dateTime, String userCode) {
39 super(COMMAND_CODE, getDateTimeBytes(dateTime), userCode);
42 private static byte[] getDateTimeBytes(LocalDateTime dateTime) {
43 return DATETIME_FORMAT.format(dateTime).getBytes();