// when batteries are freshly changed, API may return a value superior to batteryMax ! private int getBatteryPercent() { if (batteryMax == 1) { initializeBatteryLevels(); } int correctedVp = Math.min(module.getBatteryVp(), batteryMax); return (100 * (correctedVp - batteryMin) / (batteryMax - batteryMin)); }
@Override protected State getNAThingProperty(String channelId) { if (module != null) { switch (channelId) { case CHANNEL_BATTERY_LEVEL: return ChannelTypeUtils.toDecimalType(getBatteryPercent()); case CHANNEL_LOW_BATTERY: return module.getBatteryVp() < batteryLow ? OnOffType.ON : OnOffType.OFF; case CHANNEL_LAST_MESSAGE: return ChannelTypeUtils.toDateTimeType(module.getLastMessage()); case CHANNEL_RF_STATUS: Integer rfStatus = module.getRfStatus(); return ChannelTypeUtils.toDecimalType(getSignalStrength(rfStatus)); } } return super.getNAThingProperty(channelId); }