]> git.basschouten.com Git - openhab-addons.git/blob
0bf8fd763b4903c29454ae78426470111cfafc0a
[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_DAYLIGHT_SAVING_STATUS;
16
17 import java.time.ZonedDateTime;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
22  * The {@link VelbusSetDaylightSavingsStatusPacket} represents a Velbus packet that can be used to
23  * set the daylight saving status of the given Velbus module.
24  *
25  * @author Cedric Boon - Initial contribution
26  */
27 @NonNullByDefault
28 public class VelbusSetDaylightSavingsStatusPacket extends VelbusPacket {
29     private ZonedDateTime zonedDateTime;
30
31     public VelbusSetDaylightSavingsStatusPacket(byte address, ZonedDateTime zonedDateTime) {
32         super(address, PRIO_LOW);
33
34         this.zonedDateTime = zonedDateTime;
35     }
36
37     public boolean isDaylightSavings() {
38         return zonedDateTime.getZone().getRules().isDaylightSavings(zonedDateTime.toInstant());
39     }
40
41     @Override
42     protected byte[] getDataBytes() {
43         return new byte[] { COMMAND_DAYLIGHT_SAVING_STATUS, (byte) (isDaylightSavings() ? 0x01 : 0x00) };
44     }
45 }