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.PercentResponse;
17 import org.openhab.core.library.types.PercentType;
20 * This command is the base command to handle percent type commands (0-100) in hex format on the wire.
22 * @author Richard Lavoie - Initial contribution
25 public abstract class BasePercentCommand extends BaseLGSerialCommand {
27 protected BasePercentCommand(char command1, char command2, int setId) {
28 super(command1, command2, setId, true);
32 protected String computeSerialDataFrom(Object data) {
33 return Integer.toHexString(((PercentType) data).intValue());
37 protected LGSerialResponse createResponse(int set, boolean success, String data) {
38 String decimalValue = Integer.toString(Integer.parseInt(data, 16));
39 return new PercentResponse(set, success, PercentType.valueOf(decimalValue));