]> git.basschouten.com Git - openhab-addons.git/blob
0f1cee6658dbe5ba68fb0b455d995c9f18d02509
[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.boschshc.internal.services;
14
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.TimeoutException;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.boschshc.internal.devices.bridge.BridgeHandler;
20 import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState;
21
22 /**
23  * Abstract implementation for services that allow setting states via HTTP POST requests containing a JSON request body.
24  * State-less services can not receive any states from the bridge.
25  * <p>
26  * An example of such a service is the <code>arm</code> action of the intrusion detection system.
27  * <p>
28  * The services of the devices and their official APIs can be found
29  * <a href="https://apidocs.bosch-smarthome.com/local/">here</a>.
30  * 
31  * @param <TRequest> Type to represent JSON requests sent by this service
32  * 
33  * @author David Pace - Initial contribution
34  */
35 @NonNullByDefault
36 public abstract class AbstractStatelessBoschSHCServiceWithRequestBody<TRequest extends BoschSHCServiceState>
37         extends AbstractStatelessBoschSHCService {
38
39     protected AbstractStatelessBoschSHCServiceWithRequestBody(String serviceName, String endpoint) {
40         super(serviceName, endpoint);
41     }
42
43     /**
44      * Sends a HTTP POST request containing the serialized request body to the endpoint specified by
45      * {@link #getEndpoint()}.
46      * 
47      * @param request a JSON object representing the request body
48      * @throws InterruptedException
49      * @throws TimeoutException
50      * @throws ExecutionException
51      */
52     public void postAction(TRequest request) throws InterruptedException, TimeoutException, ExecutionException {
53         BridgeHandler bridgeHandler = getBridgeHandler();
54         if (bridgeHandler == null) {
55             return;
56         }
57
58         bridgeHandler.postAction(getEndpoint(), request);
59     }
60 }