2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lifx.internal.dto;
15 import java.nio.ByteBuffer;
16 import java.time.Duration;
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;
23 * @author Wouter Born - Initial contribution
25 public class SetHevCycleRequest extends Packet {
27 public static final int TYPE = 0x8F;
29 public static final Field<Boolean> FIELD_ENABLE = new BoolIntField();
30 public static final Field<Long> FIELD_DURATION = new UInt32Field().little();
32 private boolean enable;
33 private long duration;
35 public boolean isEnable() {
39 public Duration getDuration() {
40 return Duration.ofSeconds(duration);
43 public SetHevCycleRequest() {
45 setResponseRequired(true);
48 public SetHevCycleRequest(boolean enable) {
53 public SetHevCycleRequest(boolean enable, Duration duration) {
56 this.duration = duration.toSeconds();
60 public int packetType() {
65 protected int packetLength() {
70 protected void parsePacket(ByteBuffer bytes) {
71 enable = FIELD_ENABLE.value(bytes);
72 duration = FIELD_DURATION.value(bytes);
76 protected ByteBuffer packetBytes() {
77 return ByteBuffer.allocate(packetLength()).put(FIELD_ENABLE.bytes(enable)).put(FIELD_DURATION.bytes(duration));
81 public int[] expectedResponses() {
82 return new int[] { StateHevCycleResponse.TYPE };