Search in sources :

Example 1 with HmBattery

use of org.openhab.binding.homematic.internal.model.HmBattery in project openhab1-addons by openhab.

the class BaseHomematicClient method addBatteryInfo.

/**
     * Adds the battery info datapoint to the specified device if the device has
     * batteries.
     */
protected void addBatteryInfo(HmDevice device) throws HomematicClientException {
    HmBattery battery = HmBatteryTypeProvider.getBatteryType(device.getType());
    if (battery != null) {
        for (HmChannel channel : device.getChannels()) {
            if ("0".equals(channel.getNumber())) {
                try {
                    logger.debug("Adding battery type to device {}: {}", device.getType(), battery.getInfo());
                    HmDatapoint dp = new HmDatapoint();
                    FieldUtils.writeField(dp, "name", "BATTERY_TYPE", true);
                    FieldUtils.writeField(dp, "writeable", Boolean.FALSE, true);
                    FieldUtils.writeField(dp, "valueType", 20, true);
                    dp.setValue(battery.getInfo());
                    channel.addDatapoint(dp);
                } catch (IllegalAccessException ex) {
                    throw new HomematicClientException(ex.getMessage(), ex);
                }
            }
        }
    }
}
Also used : HmBattery(org.openhab.binding.homematic.internal.model.HmBattery) HmChannel(org.openhab.binding.homematic.internal.model.HmChannel) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Aggregations

HmBattery (org.openhab.binding.homematic.internal.model.HmBattery)1 HmChannel (org.openhab.binding.homematic.internal.model.HmChannel)1 HmDatapoint (org.openhab.binding.homematic.internal.model.HmDatapoint)1