]> git.basschouten.com Git - openhab-addons.git/blob
8c023fc3570065b722799363d5b800abd318f6aa
[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.lifx.internal.dto;
14
15 import java.nio.ByteBuffer;
16 import java.time.Duration;
17
18 import org.openhab.binding.lifx.internal.fields.BoolIntField;
19 import org.openhab.binding.lifx.internal.fields.Field;
20 import org.openhab.binding.lifx.internal.fields.UInt32Field;
21
22 /**
23  * @author Wouter Born - Initial contribution
24  */
25 public class SetHevCycleConfigurationRequest extends Packet {
26
27     public static final int TYPE = 0x92;
28
29     public static final Field<Boolean> FIELD_INDICATION = new BoolIntField();
30     public static final Field<Long> FIELD_DURATION = new UInt32Field().little();
31
32     private boolean indication;
33     private long duration;
34
35     public boolean isIndication() {
36         return indication;
37     }
38
39     public Duration getDuration() {
40         return Duration.ofSeconds(duration);
41     }
42
43     public SetHevCycleConfigurationRequest() {
44         setAddressable(true);
45         setResponseRequired(true);
46     }
47
48     public SetHevCycleConfigurationRequest(boolean indication, Duration duration) {
49         this();
50         this.indication = indication;
51         this.duration = duration.toSeconds();
52     }
53
54     @Override
55     public int packetType() {
56         return TYPE;
57     }
58
59     @Override
60     protected int packetLength() {
61         return 5;
62     }
63
64     @Override
65     protected void parsePacket(ByteBuffer bytes) {
66         indication = FIELD_INDICATION.value(bytes);
67         duration = FIELD_DURATION.value(bytes);
68     }
69
70     @Override
71     protected ByteBuffer packetBytes() {
72         return ByteBuffer.allocate(packetLength()).put(FIELD_INDICATION.bytes(indication))
73                 .put(FIELD_DURATION.bytes(duration));
74     }
75
76     @Override
77     public int[] expectedResponses() {
78         return new int[] { StateHevCycleConfigurationResponse.TYPE };
79     }
80 }