]> git.basschouten.com Git - openhab-addons.git/blob
1dd61afe0a5d2d9bb5a2cc0d52920298d69826ed
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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 java.time.LocalDateTime;
16 import java.time.format.DateTimeFormatter;
17
18 import org.apache.commons.lang.ArrayUtils;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
22  * Command class for command to set RTC clock.
23  *
24  * @author Krzysztof Goworek - Initial contribution
25  */
26 @NonNullByDefault
27 public class SetClockCommand extends ControlCommand {
28
29     public static final byte COMMAND_CODE = (byte) 0x8e;
30
31     private static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
32
33     /**
34      * Creates new command class instance.
35      *
36      * @param dateTime date and time to set
37      * @param userCode code of the user on behalf the control is made
38      */
39     public SetClockCommand(LocalDateTime dateTime, String userCode) {
40         super(COMMAND_CODE, ArrayUtils.addAll(userCodeToBytes(userCode), getDateTimeBytes(dateTime)));
41     }
42
43     private static byte[] getDateTimeBytes(LocalDateTime dateTime) {
44         return DATETIME_FORMAT.format(dateTime).getBytes();
45     }
46 }