2 * Copyright (c) 2010-2021 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.rfxcom.internal.messages;
15 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_BATTERY_LEVEL;
17 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
18 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
19 import org.openhab.core.library.types.DecimalType;
20 import org.openhab.core.types.State;
23 * A base class for all battery device messages
25 * @author Martin van Wingerden - Initial contribution
27 abstract class RFXComBatteryDeviceMessage<T> extends RFXComDeviceMessageImpl<T> {
30 RFXComBatteryDeviceMessage(PacketType packetType) {
34 RFXComBatteryDeviceMessage() {
39 public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
41 case CHANNEL_BATTERY_LEVEL:
42 return convertBatteryLevelToSystemWideLevel(batteryLevel);
45 return super.convertToState(channelId, deviceState);
50 * Convert internal battery level (0-9) to system wide battery level (0-100%).
52 * @param batteryLevel Internal battery level
53 * @return Battery level in system wide level
55 private State convertBatteryLevelToSystemWideLevel(int batteryLevel) {
56 int ohLevel = (batteryLevel + 1) * 10;
57 return new DecimalType(ohLevel);