Search in sources :

Example 11 with Request

use of org.openhab.binding.stiebelheatpump.protocol.Request in project openhab1-addons by openhab.

the class CommunicationService method categorizeHeatPumpConfiguration.

/**
     * This method categorize the heat pump configuration into setting, sensor
     * and status
     * 
     * @return true if heat pump configuration for version could be found and
     *         loaded
     */
private boolean categorizeHeatPumpConfiguration() {
    for (Request request : heatPumpConfiguration) {
        logger.debug("Request : Name -> {}, Description -> {} , RequestByte -> {}", request.getName(), request.getDescription(), DatatypeConverter.printHexBinary(new byte[] { request.getRequestByte() }));
        if (request.getName().equalsIgnoreCase("Version")) {
            versionRequest = request;
            logger.debug("Loaded Request : " + versionRequest.getDescription());
            continue;
        }
        for (RecordDefinition record : request.getRecordDefinitions()) {
            if (record.getDataType() == Type.Settings && !heatPumpSettingConfiguration.contains(request)) {
                heatPumpSettingConfiguration.add(request);
            }
            if (record.getDataType() == Type.Status && !heatPumpStatusConfiguration.contains(request)) {
                heatPumpStatusConfiguration.add(request);
            }
            if (record.getDataType() == Type.Sensor && !heatPumpSensorConfiguration.contains(request)) {
                heatPumpSensorConfiguration.add(request);
            }
        }
    }
    if (versionRequest == null) {
        logger.debug("version request could not be found in configuration");
        return false;
    }
    return true;
}
Also used : Request(org.openhab.binding.stiebelheatpump.protocol.Request) RecordDefinition(org.openhab.binding.stiebelheatpump.protocol.RecordDefinition)

Example 12 with Request

use of org.openhab.binding.stiebelheatpump.protocol.Request in project openhab1-addons by openhab.

the class ConfigParser method parseConfig.

/**
     * This method loads a List of Request objects from xml file
     *
     * @param fileName
     *            file object to load the object from
     * @return List of Requests
     */
public List<Request> parseConfig(String fileName) {
    logger.debug("Parsing  heat pump configuration file {}.", fileName);
    try {
        JAXBContext context = JAXBContext.newInstance(Requests.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        Requests configuration = (Requests) unmarshaller.unmarshal(stream);
        List<Request> requests = configuration.getRequests();
        return requests;
    } catch (JAXBException e) {
        logger.debug("Parsing  failed {}. " + e.toString(), fileName);
        throw new RuntimeException(e);
    }
}
Also used : InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) Request(org.openhab.binding.stiebelheatpump.protocol.Request) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requests(org.openhab.binding.stiebelheatpump.protocol.Requests)

Aggregations

Request (org.openhab.binding.stiebelheatpump.protocol.Request)12 HashMap (java.util.HashMap)5 RecordDefinition (org.openhab.binding.stiebelheatpump.protocol.RecordDefinition)5 Test (org.junit.Test)3 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 DateTime (org.joda.time.DateTime)1 Type (org.openhab.binding.stiebelheatpump.protocol.RecordDefinition.Type)1 Requests (org.openhab.binding.stiebelheatpump.protocol.Requests)1