]> git.basschouten.com Git - openhab-addons.git/blob
4ba56e706885958341dfca257573f2a278251ad1
[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.CHANGE_CONFIGURATION_URL;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jetty.client.api.Request;
19 import org.eclipse.jetty.client.util.StringContentProvider;
20 import org.eclipse.jetty.http.HttpMethod;
21 import org.openhab.binding.easee.internal.command.AbstractWriteCommand;
22 import org.openhab.binding.easee.internal.handler.EaseeThingHandler;
23 import org.openhab.binding.easee.internal.model.ValidationException;
24 import org.openhab.core.thing.Channel;
25 import org.openhab.core.types.Command;
26
27 /**
28  * implements the settings api call of the charger.
29  *
30  * @author Alexander Friese - initial contribution
31  */
32 @NonNullByDefault
33 public class ChangeConfiguration extends AbstractWriteCommand {
34     private final String url;
35
36     public ChangeConfiguration(EaseeThingHandler handler, String chargerId, Channel channel, Command command) {
37         super(handler, channel, command, RetryOnFailure.YES, ProcessFailureResponse.YES);
38         this.url = CHANGE_CONFIGURATION_URL.replaceAll("\\{id\\}", chargerId);
39     }
40
41     @Override
42     protected Request prepareWriteRequest(Request requestToPrepare) throws ValidationException {
43         StringContentProvider cp = new StringContentProvider(getJsonContent());
44         requestToPrepare.content(cp);
45         requestToPrepare.method(HttpMethod.POST);
46
47         return requestToPrepare;
48     }
49
50     @Override
51     protected String getURL() {
52         return url;
53     }
54 }