]> git.basschouten.com Git - openhab-addons.git/blob
6a9e9afdd13d76024687d9406cc3d2cd65da20ef
[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.bluetooth.am43.internal.command;
14
15 import java.util.Calendar;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link SetTimeCommand} set the current time to the motor, which it uses for scheduled activation.
21  *
22  * @author Connor Petty - Initial contribution
23  */
24 @NonNullByDefault
25 public class SetTimeCommand extends AM43Command {
26
27     private static final byte COMMAND = (byte) 0x14;
28
29     public SetTimeCommand() {
30         super(COMMAND, createContent());
31     }
32
33     private static byte[] createContent() {
34         Calendar instance = Calendar.getInstance();
35         int hour = instance.get(Calendar.HOUR);
36         if (instance.get(Calendar.AM_PM) != 0) {
37             hour += 12;
38         }
39         int minute = instance.get(Calendar.MINUTE);
40         int second = instance.get(Calendar.SECOND);
41         int dayOfWeek = instance.get(Calendar.DAY_OF_WEEK) - 1;
42         return new byte[] { (byte) dayOfWeek, (byte) hour, (byte) minute, (byte) second };
43     }
44 }