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