]> git.basschouten.com Git - openhab-addons.git/blob
0230d71d5b37878e2980816d1cf990a209176dd9
[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
21 /**
22  * Abstract implementation for services that only allow setting states via HTTP POST requests.
23  * State-less services can not receive any states from the bridge.
24  * <p>
25  * This implementation does not support request bodies when submitting the POST request.
26  * Request bodies are supported by the subclass {@link AbstractStatelessBoschSHCServiceWithRequestBody}.
27  * <p>
28  * Examples for this kind of service are the following actions of the intrusion detection system:
29  * 
30  * <pre>
31  * /intrusion/actions/arm
32  * /intrusion/actions/disarm
33  * /intrusion/actions/mute
34  * </pre>
35  * <p>
36  * The services of the devices and their official APIs can be found
37  * <a href="https://apidocs.bosch-smarthome.com/local/">here</a>.
38  * 
39  * @author David Pace - Initial contribution
40  */
41 @NonNullByDefault
42 public abstract class AbstractStatelessBoschSHCService extends AbstractBoschSHCService {
43
44     private String endpoint;
45
46     protected AbstractStatelessBoschSHCService(String serviceName, String endpoint) {
47         super(serviceName);
48         this.endpoint = endpoint;
49     }
50
51     /**
52      * Sends a HTTP POST request without request body to the endpoint specified by {@link #endpoint}.
53      * 
54      * @throws InterruptedException
55      * @throws TimeoutException
56      * @throws ExecutionException
57      */
58     public void postAction() throws InterruptedException, TimeoutException, ExecutionException {
59         BridgeHandler bridgeHandler = getBridgeHandler();
60         if (bridgeHandler == null) {
61             return;
62         }
63
64         bridgeHandler.postAction(endpoint);
65     }
66
67     public String getEndpoint() {
68         return endpoint;
69     }
70 }