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.openhab.binding.enocean.internal.eep.Base._VLDMessage;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.QuantityType;
23 import org.openhab.core.library.unit.Units;
24 import org.openhab.core.thing.CommonTriggerEvents;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
30 * @author Daniel Weber - Initial contribution
32 public class D2_03_0A extends _VLDMessage {
34 protected final byte ShortPress = 0x01;
35 protected final byte DoublePress = 0x02;
36 protected final byte LongPress = 0x03;
37 protected final byte LongRelease = 0x04;
43 public D2_03_0A(ERP1Message packet) {
48 protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
49 Configuration config) {
51 case CHANNEL_PUSHBUTTON:
52 return (bytes[1] == ShortPress) ? CommonTriggerEvents.PRESSED : null;
53 case CHANNEL_DOUBLEPRESS:
54 return (bytes[1] == DoublePress) ? CommonTriggerEvents.PRESSED : null;
55 case CHANNEL_LONGPRESS:
56 return (bytes[1] == LongPress) ? CommonTriggerEvents.PRESSED
57 : ((bytes[1] == LongRelease) ? CommonTriggerEvents.RELEASED : null);
64 public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
65 Configuration config) {
66 if (CHANNEL_BATTERY_LEVEL.equals(channelId)) {
67 return new QuantityType<>(bytes[0] & 0xFF, Units.PERCENT);
70 return UnDefType.UNDEF;