|
| 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.elkm1.internal.elk.message; |
| 14 | + |
| 15 | +import org.openhab.binding.elkm1.internal.elk.ElkCommand; |
| 16 | +import org.openhab.binding.elkm1.internal.elk.ElkMessage; |
| 17 | +import org.slf4j.Logger; |
| 18 | +import org.slf4j.LoggerFactory; |
| 19 | + |
| 20 | +/** |
| 21 | + * The Send Elk Command class, to put the elk into armed away mode. |
| 22 | + * |
| 23 | + * @author Matt Myers - Initial Contribution |
| 24 | + * |
| 25 | + */ |
| 26 | +public class DisplayTextOnLedScreen extends ElkMessage { |
| 27 | + private final Logger logger = LoggerFactory.getLogger(DisplayTextOnLedScreen.class); |
| 28 | + private int keypadArea; |
| 29 | + private int messageClear; |
| 30 | + private int beep; |
| 31 | + private int timeToDisplay; |
| 32 | + private String line1; |
| 33 | + private String line2; |
| 34 | + |
| 35 | + public DisplayTextOnLedScreen(String command) throws Exception { |
| 36 | + super(ElkCommand.DisplayTextOnLedScreen); |
| 37 | + |
| 38 | + if (command.length() != 42) { |
| 39 | + this.validElkCommand = false; |
| 40 | + logger.error("Invalid Command length of {}: {}", command.length(), command); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + String keypadArea = command.substring(2, 3); |
| 45 | + String messageClear = command.substring(3, 4); |
| 46 | + String beep = command.substring(4, 5); |
| 47 | + String timeToDisplay = command.substring(5, 10); |
| 48 | + String line1 = command.substring(10, 26); |
| 49 | + String line2 = command.substring(26, 42); |
| 50 | + |
| 51 | + this.keypadArea = Integer.valueOf(keypadArea); |
| 52 | + if (this.keypadArea < 1 || this.keypadArea > 8) { |
| 53 | + this.validElkCommand = false; |
| 54 | + } |
| 55 | + |
| 56 | + this.messageClear = Integer.valueOf(messageClear); |
| 57 | + if (this.messageClear < 0 || this.messageClear > 2) { |
| 58 | + this.validElkCommand = false; |
| 59 | + } |
| 60 | + |
| 61 | + this.beep = Integer.valueOf(beep); |
| 62 | + if (this.beep < 0 || this.beep > 1) { |
| 63 | + this.validElkCommand = false; |
| 64 | + } |
| 65 | + |
| 66 | + this.timeToDisplay = Integer.valueOf(timeToDisplay); |
| 67 | + if (this.timeToDisplay < 0 || this.timeToDisplay > 65535) { |
| 68 | + this.validElkCommand = false; |
| 69 | + } |
| 70 | + |
| 71 | + if (!this.validElkCommand) { |
| 72 | + logger.error("Invalid Command: {}", command); |
| 73 | + } |
| 74 | + |
| 75 | + this.line1 = line1; |
| 76 | + this.line2 = line2; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public String getData() { |
| 81 | + return String.format("%01d", keypadArea) + String.format("%01d", messageClear) + String.format("%01d", beep) |
| 82 | + + String.format("%05d", timeToDisplay) + line1 + line2; |
| 83 | + } |
| 84 | +} |
0 commit comments