]> git.basschouten.com Git - openhab-addons.git/blob
3bedbfca03f69d4887cf6908eb48a542097f5dd5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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 SetHevCycleRequest extends Packet {
26
27     public static final int TYPE = 0x8F;
28
29     public static final Field<Boolean> FIELD_ENABLE = new BoolIntField();
30     public static final Field<Long> FIELD_DURATION = new UInt32Field().little();
31
32     private boolean enable;
33     private long duration;
34
35     public boolean isEnable() {
36         return enable;
37     }
38
39     public Duration getDuration() {
40         return Duration.ofSeconds(duration);
41     }
42
43     public SetHevCycleRequest() {
44         setTagged(false);
45         setAddressable(true);
46         setResponseRequired(true);
47     }
48
49     public SetHevCycleRequest(boolean enable) {
50         this();
51         this.enable = enable;
52     }
53
54     public SetHevCycleRequest(boolean enable, Duration duration) {
55         this();
56         this.enable = enable;
57         this.duration = duration.toSeconds();
58     }
59
60     @Override
61     public int packetType() {
62         return TYPE;
63     }
64
65     @Override
66     protected int packetLength() {
67         return 5;
68     }
69
70     @Override
71     protected void parsePacket(ByteBuffer bytes) {
72         enable = FIELD_ENABLE.value(bytes);
73         duration = FIELD_DURATION.value(bytes);
74     }
75
76     @Override
77     protected ByteBuffer packetBytes() {
78         return ByteBuffer.allocate(packetLength()).put(FIELD_ENABLE.bytes(enable)).put(FIELD_DURATION.bytes(duration));
79     }
80
81     @Override
82     public int[] expectedResponses() {
83         return new int[] { StateHevCycleResponse.TYPE };
84     }
85 }