]> git.basschouten.com Git - openhab-addons.git/blob
5a6c07ca6ecdb70ce1af39f49df7ff1299149afa
[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.circuit;
14
15 import static org.openhab.binding.easee.internal.EaseeBindingConstants.CIRCUIT_SETTINGS_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.command.JsonResultProcessor;
23 import org.openhab.binding.easee.internal.handler.EaseeThingHandler;
24 import org.openhab.binding.easee.internal.model.ValidationException;
25 import org.openhab.core.thing.Channel;
26 import org.openhab.core.types.Command;
27
28 /**
29  * implements the settings api call of the circuit.
30  *
31  * @author Alexander Friese - initial contribution
32  */
33 @NonNullByDefault
34 public class SetCircuitSettings extends AbstractWriteCommand {
35     private final String url;
36
37     public SetCircuitSettings(EaseeThingHandler handler, Channel channel, Command command, String circuitId,
38             JsonResultProcessor resultProcessor) {
39         super(handler, channel, command, RetryOnFailure.YES, ProcessFailureResponse.YES, resultProcessor);
40         String siteId = handler.getBridgeConfiguration().getSiteId();
41         this.url = CIRCUIT_SETTINGS_URL.replaceAll("\\{siteId\\}", siteId).replaceAll("\\{circuitId\\}", circuitId);
42     }
43
44     @Override
45     protected Request prepareWriteRequest(Request requestToPrepare) throws ValidationException {
46         requestToPrepare.method(HttpMethod.POST);
47         StringContentProvider cp = new StringContentProvider(getJsonContent());
48         requestToPrepare.content(cp);
49
50         return requestToPrepare;
51     }
52
53     @Override
54     protected String getURL() {
55         return url;
56     }
57 }