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