]> git.basschouten.com Git - openhab-addons.git/blob
10ac2f8d06b24512a4d580911e4f04b53eca7554
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.lgtvserial.internal.protocol.serial.commands;
14
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;
18
19 /**
20  * This command is the base command to handle percent type commands (0-100) in hex format on the wire.
21  *
22  * @author Richard Lavoie - Initial contribution
23  *
24  */
25 public abstract class BasePercentCommand extends BaseLGSerialCommand {
26
27     protected BasePercentCommand(char command1, char command2, int setId) {
28         super(command1, command2, setId, true);
29     }
30
31     @Override
32     protected String computeSerialDataFrom(Object data) {
33         return Integer.toHexString(((PercentType) data).intValue());
34     }
35
36     @Override
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));
40     }
41 }