]> git.basschouten.com Git - openhab-addons.git/blob
03d8312fea762820e7422501484701f2fd7e1cd4
[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.velbus.internal.packets;
14
15 import static org.openhab.binding.velbus.internal.VelbusBindingConstants.COMMAND_SET_REALTIME_DATE;
16
17 import java.time.ZonedDateTime;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
22  * The {@link VelbusSetDatePacket} represents a Velbus packet that can be used to
23  * set the date of the given Velbus module.
24  *
25  * @author Cedric Boon - Initial contribution
26  */
27 @NonNullByDefault
28 public class VelbusSetDatePacket extends VelbusPacket {
29     private ZonedDateTime zonedDateTime;
30
31     public VelbusSetDatePacket(byte address, ZonedDateTime zonedDateTime) {
32         super(address, PRIO_LOW);
33
34         this.zonedDateTime = zonedDateTime;
35     }
36
37     public byte getDay() {
38         return (byte) this.zonedDateTime.getDayOfMonth();
39     }
40
41     public byte getMonth() {
42         return (byte) this.zonedDateTime.getMonthValue();
43     }
44
45     public byte getYearHighByte() {
46         return (byte) ((zonedDateTime.getYear() & 0xff00) / 0x100);
47     }
48
49     public byte getYearLowByte() {
50         return (byte) (zonedDateTime.getYear() & 0xff);
51     }
52
53     @Override
54     protected byte[] getDataBytes() {
55         return new byte[] { COMMAND_SET_REALTIME_DATE, getDay(), getMonth(), getYearHighByte(), getYearLowByte() };
56     }
57 }