]> git.basschouten.com Git - openhab-addons.git/blob
3d6d45e2dd1a6a6a9b2d63b2718db425f681c88e
[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.tplinksmarthome.internal.model;
14
15 import org.openhab.core.library.types.OnOffType;
16
17 import com.google.gson.annotations.Expose;
18
19 /**
20  * Data class for setting the TP-Link Smart Plug state and retrieving the result.
21  * Only setter methods as the values are set by gson based on the retrieved json.
22  *
23  * @author Hilbrand Bouwkamp - Initial contribution
24  */
25 public class SetRelayState extends ContextState implements HasErrorResponse {
26
27     public static class RelayState extends ErrorResponse {
28         @Expose(deserialize = false)
29         private int state;
30
31         @Override
32         public String toString() {
33             return "state:" + state;
34         }
35     }
36
37     public static class System {
38         @Expose
39         private RelayState setRelayState = new RelayState();
40
41         public void setRelayState(OnOffType onOff) {
42             setRelayState.state = onOff == OnOffType.ON ? 1 : 0;
43         }
44
45         @Override
46         public String toString() {
47             return "set_relay_state:{" + setRelayState + "}";
48         }
49     }
50
51     @Expose
52     private System system = new System();
53
54     @Override
55     public ErrorResponse getErrorResponse() {
56         return system.setRelayState;
57     }
58
59     public void setRelayState(OnOffType onOff) {
60         system.setRelayState(onOff);
61     }
62
63     @Override
64     public String toString() {
65         return "SetRelayState {system:{" + system + "}";
66     }
67 }