Search in sources :

Example 1 with DevicelistModel

use of org.openhab.binding.fritzaha.internal.model.DevicelistModel in project openhab1-addons by openhab.

the class FritzahaWebserviceUpdateXmlCallback method execute.

/**
     * {@inheritDoc}
     */
@Override
public void execute(int status, String response) {
    super.execute(status, response);
    if (validRequest) {
        logger.trace("Received State response " + response + " for item " + itemName);
        try {
            JAXBContext jaxbContext = JAXBContext.newInstance(DevicelistModel.class);
            Unmarshaller jaxbUM = jaxbContext.createUnmarshaller();
            DevicelistModel model = (DevicelistModel) jaxbUM.unmarshal(new StringReader(response));
            ArrayList<DeviceModel> list = model.getDevicelist();
            for (DeviceModel device : list) {
                if (device.getIdentifier().equals(this.deviceAin)) {
                    BigDecimal meterValueScaled = new BigDecimal(0);
                    switch(type) {
                        case POWER:
                            meterValueScaled = device.getPowermeter().getPower().scaleByPowerOfTen(-3);
                            break;
                        case ENERGY:
                            meterValueScaled = device.getPowermeter().getEnergy();
                            break;
                        case TEMPERATURE:
                            meterValueScaled = device.getTemperature().getCelsius().scaleByPowerOfTen(-1);
                            break;
                        default:
                            logger.warn("unknown meter type: " + type);
                            break;
                    }
                    logger.debug(device.toString());
                    webIface.postUpdate(itemName, new DecimalType(meterValueScaled));
                } else {
                    logger.trace("device " + device.getIdentifier() + " was not requested");
                }
            }
        } catch (JAXBException e) {
            logger.error(e.getLocalizedMessage(), e);
        }
    }
}
Also used : DeviceModel(org.openhab.binding.fritzaha.internal.model.DeviceModel) JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) DecimalType(org.openhab.core.library.types.DecimalType) JAXBContext(javax.xml.bind.JAXBContext) DevicelistModel(org.openhab.binding.fritzaha.internal.model.DevicelistModel) Unmarshaller(javax.xml.bind.Unmarshaller) BigDecimal(java.math.BigDecimal)

Aggregations

StringReader (java.io.StringReader)1 BigDecimal (java.math.BigDecimal)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 DeviceModel (org.openhab.binding.fritzaha.internal.model.DeviceModel)1 DevicelistModel (org.openhab.binding.fritzaha.internal.model.DevicelistModel)1 DecimalType (org.openhab.core.library.types.DecimalType)1