// 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 com.google.common.collect.Lists;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;
import java.util.List;
import static com.github.niqdev.openwebnet.message.Who.ENERGY_MANAGEMENT;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
     * @param version Energy management {@link Version}
     * @return message
     */
    public static EnergyManagement requestMonthlyPower(String where, Version version) {
        return buildRequestPower(where, version, MONTHLY_POWER);
    }

    private static EnergyManagement buildRequestPower(String where, Version version, int period) {
        checkRange(WHERE_MIN_VALUE_ENERGY, WHERE_MAX_VALUE_ENERGY, checkIsInteger(where));
        checkNotNull(version, "invalid null version");
        switch (version) {
            case MODEL_F520: case MODEL_F523: case MODEL_3522:
                return new EnergyManagement(format(FORMAT_DIMENSION_ENERGY, WHO, where, period));
            case MODEL_F522_A: case MODEL_F523_A:
                return new EnergyManagement(format(FORMAT_DIMENSION_ENERGY_A, WHO, where, period));
        }
        throw new IllegalArgumentException("invalid version");
    }

    /**
     * Handle response from {@link EnergyManagement#requestInstantaneousPower(String, Version)},
     * {@link EnergyManagement#requestDailyPower(String, Version)} and
     * {@link EnergyManagement#requestMonthlyPower(String, Version)}.
     *
     * This is a best effort: often the responses are incomplete or impossible to parse.
     *
     * @param onSuccess invoked if the powers have been read correctly
     * @param onError invoked otherwise
     * @return {@code Observable<List<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/EnergyManagement.java
import com.github.niqdev.openwebnet.OpenSession;
import com.google.common.collect.Lists;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;
import java.util.List;
import static com.github.niqdev.openwebnet.message.Who.ENERGY_MANAGEMENT;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;

     * @param version Energy management {@link Version}
     * @return message
     */
    public static EnergyManagement requestMonthlyPower(String where, Version version) {
        return buildRequestPower(where, version, MONTHLY_POWER);
    }

    private static EnergyManagement buildRequestPower(String where, Version version, int period) {
        checkRange(WHERE_MIN_VALUE_ENERGY, WHERE_MAX_VALUE_ENERGY, checkIsInteger(where));
        checkNotNull(version, "invalid null version");
        switch (version) {
            case MODEL_F520: case MODEL_F523: case MODEL_3522:
                return new EnergyManagement(format(FORMAT_DIMENSION_ENERGY, WHO, where, period));
            case MODEL_F522_A: case MODEL_F523_A:
                return new EnergyManagement(format(FORMAT_DIMENSION_ENERGY_A, WHO, where, period));
        }
        throw new IllegalArgumentException("invalid version");
    }

    /**
     * Handle response from {@link EnergyManagement#requestInstantaneousPower(String, Version)},
     * {@link EnergyManagement#requestDailyPower(String, Version)} and
     * {@link EnergyManagement#requestMonthlyPower(String, Version)}.
     *
     * This is a best effort: often the responses are incomplete or impossible to parse.
     *
     * @param onSuccess invoked if the powers have been read correctly
     * @param onError invoked otherwise
     * @return {@code Observable<List<OpenSession>>}
     */
    public static Func1<List<OpenSession>, List<OpenSession>> handlePowers(Action1<List<String>> onSuccess, Action0 onError) {