]> git.basschouten.com Git - openhab-addons.git/blob
5751067283eab912066c2b26e71ae0c95fc00914
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.tapocontrol.internal.dto;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 import com.google.gson.GsonBuilder;
18 import com.google.gson.annotations.Expose;
19
20 import io.reactivex.annotations.Nullable;
21
22 /**
23  * Holds data sent to device
24  *
25  * @author Christian Wild - Initial contribution
26  */
27 @NonNullByDefault
28 public record TapoRequest(@Expose String method, @Expose @Nullable Object params,
29         @Expose long requestTimeMils) implements TapoBaseRequestInterface {
30
31     /**
32      * Create request with command (method) and data (params) sent to device
33      */
34     public TapoRequest(String method, Object params) {
35         this(method, params, System.currentTimeMillis());
36     }
37
38     /**
39      * Create request with command (method) sent to device
40      */
41     public TapoRequest(String method) {
42         this(method, "", System.currentTimeMillis());
43     }
44
45     /***********************************************
46      * RETURN VALUES
47      **********************************************/
48
49     @Override
50     public String toString() {
51         return toJson();
52     }
53
54     public String toJson() {
55         return new GsonBuilder().disableHtmlEscaping().excludeFieldsWithoutExposeAnnotation().create().toJson(this);
56     }
57 }