]> git.basschouten.com Git - openhab-addons.git/blob
98baae285a2d061cde7b3ac275a8bf77fbb7e6ca
[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 import com.google.gson.annotations.SerializedName;
19
20 /**
21  * Data class for setting the TP-Link Smart Dimmer (HS220) state and retrieving the result.
22  * Only setter methods as the values are set by gson based on the retrieved json.
23  *
24  * @author Hilbrand Bouwkamp - Initial contribution
25  */
26 public class SetSwitchState implements HasErrorResponse {
27
28     public static class State extends ErrorResponse {
29         @Expose(deserialize = false)
30         private int state;
31
32         @Override
33         public String toString() {
34             return "state:" + state;
35         }
36     }
37
38     public static class Dimmer {
39         @Expose
40         private State setSwitchState = new State();
41
42         @Override
43         public String toString() {
44             return "set_switch_state:{" + setSwitchState + "}";
45         }
46     }
47
48     @Expose
49     @SerializedName("smartlife.iot.dimmer")
50     private Dimmer dimmer = new Dimmer();
51
52     @Override
53     public ErrorResponse getErrorResponse() {
54         return dimmer.setSwitchState;
55     }
56
57     public void setSwitchState(OnOffType onOff) {
58         dimmer.setSwitchState.state = onOff == OnOffType.ON ? 1 : 0;
59     }
60
61     @Override
62     public String toString() {
63         return "SetSwitchState {smartlife.iot.dimmer:{" + dimmer + "}";
64     }
65 }