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.enocean.internal.eep.D2_03;
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
17 import java.util.function.Function;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
22 import org.openhab.binding.enocean.internal.messages.ERP1Message;
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.unit.Units;
26 import org.openhab.core.thing.CommonTriggerEvents;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
32 * @author Daniel Weber - Initial contribution
35 public class D2_03_0A extends _VLDMessage {
37 protected static final byte SHORT_PRESS = 0x01;
38 protected static final byte DOUBLE_PRESS = 0x02;
39 protected static final byte LONG_PRESS = 0x03;
40 protected static final byte LONG_RELEASE = 0x04;
46 public D2_03_0A(ERP1Message packet) {
51 protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
52 Configuration config) {
54 case CHANNEL_PUSHBUTTON:
55 return (bytes[1] == SHORT_PRESS) ? CommonTriggerEvents.PRESSED : null;
56 case CHANNEL_DOUBLEPRESS:
57 return (bytes[1] == DOUBLE_PRESS) ? CommonTriggerEvents.PRESSED : null;
58 case CHANNEL_LONGPRESS:
59 return (bytes[1] == LONG_PRESS) ? CommonTriggerEvents.PRESSED
60 : ((bytes[1] == LONG_RELEASE) ? CommonTriggerEvents.RELEASED : null);
67 public State convertToStateImpl(String channelId, String channelTypeId,
68 Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
69 if (CHANNEL_BATTERY_LEVEL.equals(channelId)) {
70 return new QuantityType<>(bytes[0] & 0xFF, Units.PERCENT);
73 return UnDefType.UNDEF;