]> git.basschouten.com Git - openhab-addons.git/blob
81992f917160af7786963bbb9c0dbbd14730228b
[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.easee.internal.command.charger;
14
15 import static org.openhab.binding.easee.internal.EaseeBindingConstants.COMMANDS_URL;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jetty.client.api.Request;
19 import org.eclipse.jetty.http.HttpMethod;
20 import org.openhab.binding.easee.internal.command.AbstractWriteCommand;
21 import org.openhab.binding.easee.internal.command.JsonResultProcessor;
22 import org.openhab.binding.easee.internal.handler.EaseeThingHandler;
23 import org.openhab.core.thing.Channel;
24 import org.openhab.core.types.Command;
25
26 /**
27  * implements the command api call of the charger.
28  *
29  * @author Alexander Friese - initial contribution
30  */
31 @NonNullByDefault
32 public class SendCommand extends AbstractWriteCommand {
33     String url = COMMANDS_URL;
34
35     /**
36      * general constructor.
37      *
38      * @param handler the ThingHandler which is responsible for the channel
39      * @param chargerId Id of the charger which is adressed by this command
40      * @param channel the channel that triggered this command
41      * @param command the command to be send
42      */
43     public SendCommand(EaseeThingHandler handler, String chargerId, Channel channel, Command command,
44             JsonResultProcessor resultProcessor) {
45         this(handler, channel, command, resultProcessor);
46         this.url = COMMANDS_URL.replaceAll("\\{id\\}", chargerId).replaceAll("\\{command\\}", getCommandValue());
47     }
48
49     /**
50      * this constructor should only be used by other command implementations that inherit this class.
51      *
52      * @param handler the ThingHandler which is responsible for the channel
53      * @param channel the channel that triggered this command
54      * @param command the command to be send
55      */
56     SendCommand(EaseeThingHandler handler, Channel channel, Command command, JsonResultProcessor resultProcessor) {
57         super(handler, channel, command, RetryOnFailure.YES, ProcessFailureResponse.YES, resultProcessor);
58     }
59
60     @Override
61     protected Request prepareWriteRequest(Request requestToPrepare) {
62         requestToPrepare.method(HttpMethod.POST);
63
64         return requestToPrepare;
65     }
66
67     @Override
68     protected String getURL() {
69         return url;
70     }
71 }