2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.boschshc.internal.services;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.TimeoutException;
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;
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.
28 * The endpoints to retrieve system states are different from the ones for physical devices, i.e. they do not follow the
32 * https://{IP}:8444/smarthome/devices/{deviceId}/services/{serviceName}/state
35 * Instead, system services have endpoints like
38 * /intrusion/states/system
42 * The services of the devices and their official APIs can be found
43 * <a href="https://apidocs.bosch-smarthome.com/local/">here</a>.
45 * @param <TState> type used for representing the service state
47 * @author David Pace - Initial contribution
50 public abstract class BoschSHCSystemService<TState extends BoschSHCServiceState> extends BoschSHCService<TState> {
52 private String endpoint;
55 * Constructs a system service instance.
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>
62 protected BoschSHCSystemService(String serviceName, Class<TState> stateClass, String endpoint) {
63 super(serviceName, stateClass);
64 this.endpoint = endpoint;
68 * Uses the endpoint directly instead of constructing a device-specific URL.
71 public @Nullable TState getState()
72 throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
74 BridgeHandler bridgeHandler = getBridgeHandler();
75 if (bridgeHandler == null) {
78 return bridgeHandler.getState(this.endpoint, getStateClass());