2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.plugwise.internal.protocol;
15 import static java.time.ZoneOffset.UTC;
16 import static org.openhab.binding.plugwise.internal.protocol.field.MessageType.REAL_TIME_CLOCK_SET_REQUEST;
18 import java.time.LocalDateTime;
19 import java.time.ZoneId;
20 import java.time.ZonedDateTime;
22 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
25 * Sets the real-time clock value of a Circle+. The Circle+ is the only device that holds a real-time clock value.
27 * @author Wouter Born - Initial contribution
29 public class RealTimeClockSetRequestMessage extends Message {
31 private ZonedDateTime utcDateTime;
33 public RealTimeClockSetRequestMessage(MACAddress macAddress, LocalDateTime localDateTime) {
34 super(REAL_TIME_CLOCK_SET_REQUEST, macAddress);
35 this.utcDateTime = localDateTime.atZone(ZoneId.systemDefault()).withZoneSameInstant(UTC);
39 protected String payloadToHexString() {
40 // Real-time clock values in the message are decimals and not hexadecimals
41 String second = String.format("%02d", utcDateTime.getSecond());
42 String minute = String.format("%02d", utcDateTime.getMinute());
43 String hour = String.format("%02d", utcDateTime.getHour());
44 // Monday = 0, ... , Sunday = 6
45 String dayOfWeek = String.format("%02d", utcDateTime.getDayOfWeek().getValue() - 1);
46 String day = String.format("%02d", utcDateTime.getDayOfMonth());
47 String month = String.format("%02d", utcDateTime.getMonthValue());
48 String year = String.format("%02d", utcDateTime.getYear() - 2000);
50 return second + minute + hour + dayOfWeek + day + month + year;