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.openhab.binding.enocean.internal.eep.Base._4BSMessage;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.PercentType;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.library.unit.Units;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
30 * @author Dominik Krickl-Vorreiter - Initial contribution
32 public class A5_11_03 extends _4BSMessage {
34 public A5_11_03(ERP1Message packet) {
38 protected boolean isErrorState() {
41 int state = (db1 >> 4) & 0x03;
44 // TODO: display error state on thing
51 protected State getPositionData() {
53 boolean pvf = getBit(db1, 7);
58 boolean motp = getBit(db0, 6);
59 int bsp = getDB_3Value();
61 if ((bsp >= 0) && (bsp <= 100)) {
62 return new PercentType(motp ? 100 - bsp : bsp);
66 return UnDefType.UNDEF;
69 protected State getAngleData() {
71 boolean avf = getBit(db1, 6);
76 boolean as = getBit(db2, 7);
77 int an = (db2 & 0x7F) * 2;
79 if ((an >= 0) && (an <= 180)) {
80 return new QuantityType<>(as ? an * -1 : an, Units.DEGREE_ANGLE);
84 return UnDefType.UNDEF;
88 protected State convertToStateImpl(String channelId, String channelTypeId,
89 Function<String, State> getCurrentStateFunc, Configuration config) {
91 return UnDefType.UNDEF;
95 case CHANNEL_ROLLERSHUTTER:
96 return getPositionData();
98 return getAngleData();
101 return UnDefType.UNDEF;