// Path: lib/src/main/java/com/github/niqdev/openwebnet/OpenSession.java
// public class OpenSession {
// 
//     private final OpenMessage request;
//     private final List<OpenMessage> response = new ArrayList<>();
// 
//     private OpenSession(OpenMessage request) {
//         checkNotNull(request, "request can't be null");
//         this.request = request;
//     }
// 
//     /**
//      * Helper method to create a new session.
//      *
//      * @param request message
//      * @return session
//      */
//     public static OpenSession newSession(OpenMessage request) {
//         return new OpenSession(request);
//     }
// 
//     /**
//      * Update the response messages.
//      *
//      * @param response messages
//      * @return session
//      */
//     public OpenSession addAllResponse(List<OpenMessage> response) {
//         checkNotNull(response, "response can't be null");
//         this.response.addAll(response);
//         return this;
//     }
// 
//     /**
//      * Update the response messages.
//      *
//      * @param response messages
//      * @return session
//      */
//     public OpenSession addResponse(OpenMessage response) {
//         checkNotNull(response, "response can't be null");
//         this.response.add(response);
//         return this;
//     }
// 
//     /**
//      * Returns the initial request message.
//      *
//      * @return request
//      */
//     public OpenMessage getRequest() {
//         return request;
//     }
// 
//     /**
//      * Returns the response messages.
//      *
//      * @return response
//      */
//     public List<OpenMessage> getResponse() {
//         return response;
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(this)
//             .add("request", request.getValue())
//             .add("response", response)
//             .toString();
//     }
// }


import com.github.niqdev.openwebnet.OpenSession;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;
import java.text.DecimalFormat;
import java.util.List;
import static com.github.niqdev.openwebnet.message.Who.TEMPERATURE_CONTROL;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
package com.github.niqdev.openwebnet.message;




/**
 * OpenWebNet Heating.
 *
 * <pre>
 * {@code
 *
 * import static com.github.niqdev.openwebnet.OpenWebNet.defaultGateway;
 *
 * // reads temperature
 * OpenWebNet
 *    .newClient(defaultGateway("IP_ADDRESS"))
 *    .send(Heating.requestTemperature("WHERE"))
 *    .map(Heating.handleTemperature(value -> System.out.println(value), () -> System.out.println("error")))
 *    .subscribe(System.out::println);
 * }
 * </pre>
 */
public class Heating extends BaseOpenMessage {

    /**
     * Common temperature scale.
     */
    public enum TemperatureScale {
        CELSIUS, FAHRENHEIT, KELVIN
    }

    private static final int READ_TEMPERATURE = 0;
    private static final int WHERE_MAX_VALUE_TEMPERATURE = 899;
    private static final int WHO = TEMPERATURE_CONTROL.value();

    private final TemperatureScale temperatureScale;

    private Heating(String value, TemperatureScale scale) {
        super(value);
        this.temperatureScale = scale;
    }

    /**
     * OpenWebNet message request to read temperature with a specific {@link TemperatureScale} and value <b>*4*WHERE*0##</b>.
     *
     * @param where Value between 0 and 899
     * @param scale Temperature scale
     * @return message
     */
    public static Heating requestTemperature(String where, TemperatureScale scale) {
        checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE_TEMPERATURE, checkIsInteger(where));
        checkNotNull(scale, "invalid null scale");
        return new Heating(format(FORMAT_DIMENSION, WHO, where, READ_TEMPERATURE), scale);
    }

    /**
     * OpenWebNet message request to read temperature in {@link TemperatureScale#CELSIUS} and value <b>*4*WHERE*0##</b>.
     *
     * @param where Value between 0 and 899
     * @return message
     */
    public static Heating requestTemperature(String where) {
        return requestTemperature(where, TemperatureScale.CELSIUS);
    }

    /**
     * Handle response from {@link Heating#requestTemperature(String, TemperatureScale)}.
     *
     * @param onSuccess invoked if the temperature has been read correctly
     * @param onError   invoked otherwise
     * @return {@code Observable<OpenSession>}
     */
// Path: lib/src/main/java/com/github/niqdev/openwebnet/OpenSession.java
// public class OpenSession {
// 
//     private final OpenMessage request;
//     private final List<OpenMessage> response = new ArrayList<>();
// 
//     private OpenSession(OpenMessage request) {
//         checkNotNull(request, "request can't be null");
//         this.request = request;
//     }
// 
//     /**
//      * Helper method to create a new session.
//      *
//      * @param request message
//      * @return session
//      */
//     public static OpenSession newSession(OpenMessage request) {
//         return new OpenSession(request);
//     }
// 
//     /**
//      * Update the response messages.
//      *
//      * @param response messages
//      * @return session
//      */
//     public OpenSession addAllResponse(List<OpenMessage> response) {
//         checkNotNull(response, "response can't be null");
//         this.response.addAll(response);
//         return this;
//     }
// 
//     /**
//      * Update the response messages.
//      *
//      * @param response messages
//      * @return session
//      */
//     public OpenSession addResponse(OpenMessage response) {
//         checkNotNull(response, "response can't be null");
//         this.response.add(response);
//         return this;
//     }
// 
//     /**
//      * Returns the initial request message.
//      *
//      * @return request
//      */
//     public OpenMessage getRequest() {
//         return request;
//     }
// 
//     /**
//      * Returns the response messages.
//      *
//      * @return response
//      */
//     public List<OpenMessage> getResponse() {
//         return response;
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(this)
//             .add("request", request.getValue())
//             .add("response", response)
//             .toString();
//     }
// }


// Path: lib/src/main/java/com/github/niqdev/openwebnet/message/Heating.java
import com.github.niqdev.openwebnet.OpenSession;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;
import java.text.DecimalFormat;
import java.util.List;
import static com.github.niqdev.openwebnet.message.Who.TEMPERATURE_CONTROL;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;

package com.github.niqdev.openwebnet.message;




/**
 * OpenWebNet Heating.
 *
 * <pre>
 * {@code
 *
 * import static com.github.niqdev.openwebnet.OpenWebNet.defaultGateway;
 *
 * // reads temperature
 * OpenWebNet
 *    .newClient(defaultGateway("IP_ADDRESS"))
 *    .send(Heating.requestTemperature("WHERE"))
 *    .map(Heating.handleTemperature(value -> System.out.println(value), () -> System.out.println("error")))
 *    .subscribe(System.out::println);
 * }
 * </pre>
 */
public class Heating extends BaseOpenMessage {

    /**
     * Common temperature scale.
     */
    public enum TemperatureScale {
        CELSIUS, FAHRENHEIT, KELVIN
    }

    private static final int READ_TEMPERATURE = 0;
    private static final int WHERE_MAX_VALUE_TEMPERATURE = 899;
    private static final int WHO = TEMPERATURE_CONTROL.value();

    private final TemperatureScale temperatureScale;

    private Heating(String value, TemperatureScale scale) {
        super(value);
        this.temperatureScale = scale;
    }

    /**
     * OpenWebNet message request to read temperature with a specific {@link TemperatureScale} and value <b>*4*WHERE*0##</b>.
     *
     * @param where Value between 0 and 899
     * @param scale Temperature scale
     * @return message
     */
    public static Heating requestTemperature(String where, TemperatureScale scale) {
        checkRange(WHERE_MIN_VALUE, WHERE_MAX_VALUE_TEMPERATURE, checkIsInteger(where));
        checkNotNull(scale, "invalid null scale");
        return new Heating(format(FORMAT_DIMENSION, WHO, where, READ_TEMPERATURE), scale);
    }

    /**
     * OpenWebNet message request to read temperature in {@link TemperatureScale#CELSIUS} and value <b>*4*WHERE*0##</b>.
     *
     * @param where Value between 0 and 899
     * @return message
     */
    public static Heating requestTemperature(String where) {
        return requestTemperature(where, TemperatureScale.CELSIUS);
    }

    /**
     * Handle response from {@link Heating#requestTemperature(String, TemperatureScale)}.
     *
     * @param onSuccess invoked if the temperature has been read correctly
     * @param onError   invoked otherwise
     * @return {@code Observable<OpenSession>}
     */
    public static Func1<OpenSession, OpenSession> handleTemperature(Action1<Double> onSuccess, Action0 onError) {