]> git.basschouten.com Git - openhab-addons.git/blob
3b2a88d70faceddd2ee05e0a62dc705f5826b156
[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.avmfritz.internal.hardware.callbacks;
14
15 import static org.eclipse.jetty.http.HttpMethod.GET;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.avmfritz.internal.hardware.FritzAhaWebInterface;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * Callback implementation for updating hue, saturation and duration. Supports reauthorization
24  *
25  * @author Christoph Weitkamp - Initial contribution
26  */
27 @NonNullByDefault
28 public class FritzAhaSetColorCallback extends FritzAhaReauthCallback {
29
30     private static final String WEBSERVICE_SET_COLOR_COMMAND = "switchcmd=setcolor";
31     private static final String WEBSERVICE_SET_UNMAPPED_COLOR_COMMAND = "switchcmd=setunmappedcolor";
32
33     private final Logger logger = LoggerFactory.getLogger(FritzAhaSetColorCallback.class);
34
35     private final String ain;
36
37     /**
38      * Constructor
39      *
40      * @param webIface Interface to FRITZ!Box
41      * @param ain AIN of the device that should be switched
42      * @param hue New hue
43      * @param saturation New saturation
44      * @param duration Duration of the change in 100ms. 0 immediately.
45      */
46     public FritzAhaSetColorCallback(FritzAhaWebInterface webIface, String ain, int hue, int saturation, int duration) {
47         this(webIface, ain, hue, saturation, duration, true);
48     }
49
50     /**
51      * Constructor
52      *
53      * @param webIface Interface to FRITZ!Box
54      * @param ain AIN of the device that should be switched
55      * @param hue New hue
56      * @param saturation New saturation
57      * @param duration Duration of the change in 100ms. 0 immediately.
58      * @param mapped Use mapped or unmapped color command
59      */
60     public FritzAhaSetColorCallback(FritzAhaWebInterface webIface, String ain, int hue, int saturation, int duration,
61             boolean mapped) {
62         super(WEBSERVICE_PATH,
63                 mapped ? WEBSERVICE_SET_COLOR_COMMAND
64                         : WEBSERVICE_SET_UNMAPPED_COLOR_COMMAND + "&ain=" + ain + "&hue=" + hue + "&saturation="
65                                 + saturation + "&duration=" + duration,
66                 webIface, GET, 1);
67         this.ain = ain;
68     }
69
70     @Override
71     public void execute(int status, String response) {
72         super.execute(status, response);
73         if (isValidRequest()) {
74             logger.debug("Received response '{}' for item '{}'", response, ain);
75         }
76     }
77 }