2 * Copyright (c) 2010-2022 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.bluetooth.am43.internal.command;
15 import java.util.Calendar;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * The {@link SetTimeCommand} set the current time to the motor, which it uses for scheduled activation.
22 * @author Connor Petty - Initial contribution
25 public class SetTimeCommand extends AM43Command {
27 private static final byte COMMAND = (byte) 0x14;
29 public SetTimeCommand() {
30 super(COMMAND, createContent());
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) {
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 };