]> git.basschouten.com Git - openhab-addons.git/blob
a2afc39c1b215fc95d3656ed7ea19d121f1ee232
[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.batterylevel;
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.devices.bridge.dto.DeviceServiceData;
22 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
23 import org.openhab.binding.boschshc.internal.services.BoschSHCService;
24
25 /**
26  * Service to retrieve battery levels.
27  *
28  * @author David Pace - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class BatteryLevelService extends BoschSHCService<DeviceServiceData> {
33
34     public BatteryLevelService() {
35         super("BatteryLevel", DeviceServiceData.class);
36     }
37
38     @Override
39     public @Nullable DeviceServiceData getState()
40             throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
41         String deviceId = getDeviceId();
42         if (deviceId == null) {
43             return null;
44         }
45         BridgeHandler bridgeHandler = getBridgeHandler();
46         if (bridgeHandler == null) {
47             return null;
48         }
49         return bridgeHandler.getServiceData(deviceId, getServiceName());
50     }
51 }