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.max.internal.command;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.max.internal.Utils;
19 * The {@link ZCommand} send a wakeup request to MAX! devices.
21 * @author Marcel Verpaalen - Initial Contribution
24 public class ZCommand extends CubeCommand {
26 public enum WakeUpType {
32 private static final int DEFAULT_WAKETIME = 30;
34 private final String address;
35 private final WakeUpType wakeUpType;
36 private final int wakeUpTime;
38 public ZCommand(WakeUpType wakeUpType, String address, int wakeupTime) {
39 this.address = address;
40 this.wakeUpType = wakeUpType;
41 this.wakeUpTime = wakeupTime;
44 public static ZCommand wakeupRoom(int roomId) {
45 return new ZCommand(WakeUpType.ROOM, String.format("%02d", roomId), DEFAULT_WAKETIME);
48 public static ZCommand wakeupRoom(int roomId, int wakeupTime) {
49 return new ZCommand(WakeUpType.ROOM, String.format("%02d", roomId), wakeupTime);
52 public static ZCommand wakeupDevice(String rfAddress) {
53 return new ZCommand(WakeUpType.DEVICE, rfAddress, DEFAULT_WAKETIME);
56 public static ZCommand wakeupDevice(String rfAddress, int wakeupTime) {
57 return new ZCommand(WakeUpType.DEVICE, rfAddress, wakeupTime);
60 public static ZCommand wakeupAllDevices() {
61 return new ZCommand(WakeUpType.ALL, "0", DEFAULT_WAKETIME);
64 public static ZCommand wakeupAllDevices(int wakeupTime) {
65 return new ZCommand(WakeUpType.ALL, "0", wakeupTime);
69 public String getCommandString() {
70 final String commandString;
76 commandString = "G," + address;
79 commandString = "D," + address;
82 throw new IllegalStateException("Unknown wakeup type: " + wakeUpType);
85 return "z:" + Utils.toHex(wakeUpTime) + "," + commandString + '\r' + '\n';
89 public String getReturnStrings() {