]> git.basschouten.com Git - openhab-addons.git/blob
2e786cd3a80502612983d5ddef7125596b4db3d5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.plugwise.internal.protocol;
14
15 import static org.openhab.binding.plugwise.internal.protocol.field.MessageType.POWER_LOG_INTERVAL_SET_REQUEST;
16
17 import java.time.Duration;
18
19 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
20
21 /**
22  * Sets the interval of historic power consumption and production measurements. These historic measurements are
23  * returned by the {@link PowerBufferRequestMessage}.
24  *
25  * @author Wouter Born - Initial contribution
26  */
27 public class PowerLogIntervalSetRequestMessage extends Message {
28
29     private Duration consumptionInterval;
30     private Duration productionInterval;
31
32     public PowerLogIntervalSetRequestMessage(MACAddress macAddress, Duration consumptionInterval,
33             Duration productionInterval) {
34         super(POWER_LOG_INTERVAL_SET_REQUEST, macAddress);
35         this.consumptionInterval = consumptionInterval;
36         this.productionInterval = productionInterval;
37     }
38
39     @Override
40     protected String payloadToHexString() {
41         String consumptionIntervalHex = String.format("%04X", consumptionInterval.toMinutes());
42         String productionIntervalHex = String.format("%04X", productionInterval.toMinutes());
43         return consumptionIntervalHex + productionIntervalHex;
44     }
45 }