]> git.basschouten.com Git - openhab-addons.git/blob
ea8905f9efae17b3afc5be870632bd2240db4c6a
[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.responses;
14
15 import org.openhab.binding.lgtvserial.internal.protocol.serial.LGSerialResponse;
16 import org.openhab.core.library.types.OnOffType;
17 import org.openhab.core.library.types.StringType;
18 import org.openhab.core.types.State;
19
20 /**
21  * This class represents an ON/OFF response.
22  *
23  * @author Richard Lavoie - Initial contribution
24  *
25  */
26 public class OnOffResponse implements LGSerialResponse {
27
28     private int setId;
29
30     private boolean success;
31
32     private State state;
33
34     public OnOffResponse(int setId, boolean success, String data) {
35         this.setId = setId;
36         this.success = success;
37
38         if (success) {
39             state = "01".equals(data) ? OnOffType.ON : OnOffType.OFF;
40         } else {
41             state = new StringType(data);
42         }
43     }
44
45     @Override
46     public int getSetID() {
47         return setId;
48     }
49
50     @Override
51     public State getState() {
52         return state;
53     }
54
55     @Override
56     public boolean isSuccess() {
57         return success;
58     }
59 }