]> git.basschouten.com Git - openhab-addons.git/blob
4df8799773fd9b84f1587c8bab169c38650f8a9d
[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.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.boschshc.internal.devices.bridge.BridgeHandler;
21 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
22 import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState;
23
24 /**
25  * Abstract implementation of a system service that does not represent a physical device.
26  * Examples for system services are the intrusion detection system and the water detection system.
27  * <p>
28  * The endpoints to retrieve system states are different from the ones for physical devices, i.e. they do not follow the
29  * pattern
30  * 
31  * <pre>
32  * https://{IP}:8444/smarthome/devices/{deviceId}/services/{serviceName}/state
33  * </pre>
34  * 
35  * Instead, system services have endpoints like
36  * 
37  * <pre>
38  * /intrusion/states/system
39  * </pre>
40  * 
41  * <p>
42  * The services of the devices and their official APIs can be found
43  * <a href="https://apidocs.bosch-smarthome.com/local/">here</a>.
44  *
45  * @param <TState> type used for representing the service state
46  * 
47  * @author David Pace - Initial contribution
48  */
49 @NonNullByDefault
50 public abstract class BoschSHCSystemService<TState extends BoschSHCServiceState> extends BoschSHCService<TState> {
51
52     private String endpoint;
53
54     /**
55      * Constructs a system service instance.
56      * 
57      * @param serviceName name of the service, such as <code>intrusionDetectionService</code>
58      * @param stateClass the class representing states of the system
59      * @param endpoint the part of the URL after <code>https://{IP}:8444/smarthome/</code>, e.g.
60      *            <code>intrusion/states/system</code>
61      */
62     protected BoschSHCSystemService(String serviceName, Class<TState> stateClass, String endpoint) {
63         super(serviceName, stateClass);
64         this.endpoint = endpoint;
65     }
66
67     /**
68      * Uses the endpoint directly instead of constructing a device-specific URL.
69      */
70     @Override
71     public @Nullable TState getState()
72             throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
73
74         BridgeHandler bridgeHandler = getBridgeHandler();
75         if (bridgeHandler == null) {
76             return null;
77         }
78         return bridgeHandler.getState(this.endpoint, getStateClass());
79     }
80 }