// 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;
package com.github.niqdev.openwebnet.message;




/**
 * OpenWebNet Energy Management.
 *
 * <pre>
 * {@code
 *
 * // reads powers (best effort)
 * OpenWebNet
 *    .newClient(gateway("x.x.x.x", 20000, "12345"))
 *    .send(asList(
 *       EnergyManagement.requestInstantaneousPower("1", EnergyManagement.Version.MODEL_F523),
 *       EnergyManagement.requestDailyPower("1", EnergyManagement.Version.MODEL_F520),
 *       EnergyManagement.requestMonthlyPower("1", EnergyManagement.Version.MODEL_F522_A)))
 *    .map(EnergyManagement.handlePowers(System.out::println, () -> System.out.println("error")))
 *    .subscribe(System.out::println);
 * }
 * </pre>
 *
 */
public class EnergyManagement extends BaseOpenMessage {

    public enum Version {
        // Energy Management Central Unit, Pulse Counter, Power Meter
        // 5N 1-255
        MODEL_F520,
        MODEL_F523,
        MODEL_3522,
        // Energy Management Actuators
        // 7N#0 1-255
        MODEL_F522_A,
        MODEL_F523_A
    }

    private static final String FORMAT_DIMENSION_ENERGY = "*#%d*5%s*%d##";
    private static final String FORMAT_DIMENSION_ENERGY_A = "*#%d*7%s#0*%d##";
    private static final int INSTANTANEOUS_POWER = 113;
    private static final int DAILY_POWER = 54;
    private static final int MONTHLY_POWER = 53;
    private static final int WHERE_MIN_VALUE_ENERGY = 1;
    private static final int WHERE_MAX_VALUE_ENERGY = 255;
    private static final int WHO = ENERGY_MANAGEMENT.value();

    private EnergyManagement(String value) {
        super(value);
    }

    /**
     * OpenWebNet message request instantaneous power in Watt.
     *
     * @param where Value between 1 and 255
     * @param version Energy management {@link Version}
     * @return message
     */
    public static EnergyManagement requestInstantaneousPower(String where, Version version) {
        return buildRequestPower(where, version, INSTANTANEOUS_POWER);
    }

    /**
     * OpenWebNet message request daily power in Watt.
     *
     * @param where Value between 1 and 255
     * @param version Energy management {@link Version}
     * @return message
     */
    public static EnergyManagement requestDailyPower(String where, Version version) {
        return buildRequestPower(where, version, DAILY_POWER);
    }

    /**
     * OpenWebNet message request monthly power in Watt.
     *
     * @param where Value between 1 and 255
     * @param version Energy management {@link Version}
     * @return message
     */
    public static EnergyManagement requestMonthlyPower(String where, Version version) {
// 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;

package com.github.niqdev.openwebnet.message;




/**
 * OpenWebNet Energy Management.
 *
 * <pre>
 * {@code
 *
 * // reads powers (best effort)
 * OpenWebNet
 *    .newClient(gateway("x.x.x.x", 20000, "12345"))
 *    .send(asList(
 *       EnergyManagement.requestInstantaneousPower("1", EnergyManagement.Version.MODEL_F523),
 *       EnergyManagement.requestDailyPower("1", EnergyManagement.Version.MODEL_F520),
 *       EnergyManagement.requestMonthlyPower("1", EnergyManagement.Version.MODEL_F522_A)))
 *    .map(EnergyManagement.handlePowers(System.out::println, () -> System.out.println("error")))
 *    .subscribe(System.out::println);
 * }
 * </pre>
 *
 */
public class EnergyManagement extends BaseOpenMessage {

    public enum Version {
        // Energy Management Central Unit, Pulse Counter, Power Meter
        // 5N 1-255
        MODEL_F520,
        MODEL_F523,
        MODEL_3522,
        // Energy Management Actuators
        // 7N#0 1-255
        MODEL_F522_A,
        MODEL_F523_A
    }

    private static final String FORMAT_DIMENSION_ENERGY = "*#%d*5%s*%d##";
    private static final String FORMAT_DIMENSION_ENERGY_A = "*#%d*7%s#0*%d##";
    private static final int INSTANTANEOUS_POWER = 113;
    private static final int DAILY_POWER = 54;
    private static final int MONTHLY_POWER = 53;
    private static final int WHERE_MIN_VALUE_ENERGY = 1;
    private static final int WHERE_MAX_VALUE_ENERGY = 255;
    private static final int WHO = ENERGY_MANAGEMENT.value();

    private EnergyManagement(String value) {
        super(value);
    }

    /**
     * OpenWebNet message request instantaneous power in Watt.
     *
     * @param where Value between 1 and 255
     * @param version Energy management {@link Version}
     * @return message
     */
    public static EnergyManagement requestInstantaneousPower(String where, Version version) {
        return buildRequestPower(where, version, INSTANTANEOUS_POWER);
    }

    /**
     * OpenWebNet message request daily power in Watt.
     *
     * @param where Value between 1 and 255
     * @param version Energy management {@link Version}
     * @return message
     */
    public static EnergyManagement requestDailyPower(String where, Version version) {
        return buildRequestPower(where, version, DAILY_POWER);
    }

    /**
     * OpenWebNet message request monthly power in Watt.
     *
     * @param where Value between 1 and 255
     * @param version Energy management {@link Version}
     * @return message
     */
    public static EnergyManagement requestMonthlyPower(String where, Version version) {
        return buildRequestPower(where, version, MONTHLY_POWER);