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.A5_11;
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._4BSMessage;
22 import org.openhab.binding.enocean.internal.messages.ERP1Message;
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.library.types.PercentType;
25 import org.openhab.core.library.types.QuantityType;
26 import org.openhab.core.library.unit.Units;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
32 * @author Dominik Krickl-Vorreiter - Initial contribution
35 public class A5_11_03 extends _4BSMessage {
37 public A5_11_03(ERP1Message packet) {
41 protected boolean isErrorState() {
44 int state = (db1 >> 4) & 0x03;
46 // TODO: display error state on thing
50 protected State getPositionData() {
52 boolean pvf = getBit(db1, 7);
57 boolean motp = getBit(db0, 6);
58 int bsp = getDB3Value();
60 if ((bsp >= 0) && (bsp <= 100)) {
61 return new PercentType(motp ? 100 - bsp : bsp);
65 return UnDefType.UNDEF;
68 protected State getAngleData() {
70 boolean avf = getBit(db1, 6);
75 boolean as = getBit(db2, 7);
76 int an = (db2 & 0x7F) * 2;
78 if ((an >= 0) && (an <= 180)) {
79 return new QuantityType<>(as ? an * -1 : an, Units.DEGREE_ANGLE);
83 return UnDefType.UNDEF;
87 protected State convertToStateImpl(String channelId, String channelTypeId,
88 Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
90 return UnDefType.UNDEF;
94 case CHANNEL_ROLLERSHUTTER:
95 return getPositionData();
97 return getAngleData();
100 return UnDefType.UNDEF;