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.lgtvserial.internal.protocol.serial.commands;
15 import org.openhab.binding.lgtvserial.internal.protocol.serial.LGSerialResponse;
16 import org.openhab.binding.lgtvserial.internal.protocol.serial.responses.DecimalResponse;
17 import org.openhab.core.library.types.DecimalType;
20 * This command is the base command to handle decimal type commands in hex format on the wire.
22 * @author Richard Lavoie - Initial contribution
25 public abstract class BaseDecimalCommand extends BaseLGSerialCommand {
30 * @param command1 Command category
31 * @param command2 Command key
32 * @param setId TV Set id this command is tied to
33 * @param updatable Define if this command is one that can update the TV or can only ever be a read status command.
35 protected BaseDecimalCommand(char command1, char command2, int setId, boolean updatable) {
36 super(command1, command2, setId, updatable);
40 * Create a command that can update the TV.
42 * @param command1 Command category
43 * @param command2 Command key
44 * @param setId TV Set id this command is tied to
47 protected BaseDecimalCommand(char command1, char command2, int setId) {
48 super(command1, command2, setId, true);
52 protected String computeSerialDataFrom(Object data) {
53 return String.format("%02x", ((DecimalType) data).intValue());
57 protected LGSerialResponse createResponse(int set, boolean success, String data) {
58 String decimalValue = Integer.toString(Integer.parseInt(data, 16));
59 return new DecimalResponse(set, success, DecimalType.valueOf(decimalValue));