]> git.basschouten.com Git - openhab-addons.git/blob
87b265a775fab26a9bdc6943e1a2d5d8c1f3eb8a
[openhab-addons.git] /
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.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.StringResponse;
17
18 /**
19  * This command is the base command for the On/Off type command which translates to 00/01 on the wire.
20  *
21  * @author Richard Lavoie - Initial contribution
22  *
23  */
24 public abstract class BaseStringCommand extends BaseLGSerialCommand {
25
26     protected BaseStringCommand(char command1, char command2, int setId) {
27         super(command1, command2, setId, true);
28     }
29
30     public BaseStringCommand(char command1, char command2, int setId, boolean updatable) {
31         super(command1, command2, setId, updatable);
32     }
33
34     @Override
35     public LGSerialResponse parseResponse(String response) {
36         int set = Integer.parseInt(response.substring(2, 4), 16);
37         boolean success = 'O' == response.charAt(5) && 'K' == response.charAt(6);
38
39         return new StringResponse(set, success, response.substring(7));
40     }
41
42     @Override
43     protected String computeSerialDataFrom(Object data) {
44         return data.toString();
45     }
46
47     @Override
48     protected LGSerialResponse createResponse(int set, boolean success, String data) {
49         return new StringResponse(set, success, data);
50     }
51 }