]> git.basschouten.com Git - openhab-addons.git/blob
dadc7dc548e42ee4d3c6ba4d516266798798f85d
[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 StateHevCycleResponse extends Packet {
26
27     public static final int TYPE = 0x90;
28
29     public static final Field<Long> FIELD_DURATION = new UInt32Field().little();
30     public static final Field<Long> FIELD_REMAINING = new UInt32Field().little();
31     public static final Field<Boolean> FIELD_LAST_POWER = new BoolIntField();
32
33     private long duration;
34     private long remaining;
35     private boolean lastPower;
36
37     public Duration getDuration() {
38         return Duration.ofSeconds(duration);
39     }
40
41     public Duration getRemaining() {
42         return Duration.ofSeconds(remaining);
43     }
44
45     public boolean isLastPower() {
46         return lastPower;
47     }
48
49     @Override
50     public int packetType() {
51         return TYPE;
52     }
53
54     @Override
55     protected int packetLength() {
56         return 9;
57     }
58
59     @Override
60     protected void parsePacket(ByteBuffer bytes) {
61         duration = FIELD_DURATION.value(bytes);
62         remaining = FIELD_REMAINING.value(bytes);
63         lastPower = FIELD_LAST_POWER.value(bytes);
64     }
65
66     @Override
67     protected ByteBuffer packetBytes() {
68         return ByteBuffer.allocate(packetLength()).put(FIELD_DURATION.bytes(duration))
69                 .put(FIELD_REMAINING.bytes(remaining)).put(FIELD_LAST_POWER.bytes(lastPower));
70     }
71
72     @Override
73     public int[] expectedResponses() {
74         return new int[] {};
75     }
76 }