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.devices;
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.exceptions.BoschSHCException;
21 import org.openhab.core.thing.Thing;
22 import org.openhab.core.thing.ThingStatus;
23 import org.openhab.core.thing.ThingStatusDetail;
26 * Handler for physical Bosch devices with configurable IDs (as opposed to system services, which have static IDs).
28 * The device ID of physical devices has to be configured in the thing configuration.
30 * Examples for physical device IDs are:
33 * hdm:Cameras:d20354de-44b5-3acc-924c-24c98d59da42
34 * hdm:ZigBee:000d6f0016d1cdae
37 * @author Stefan Kästle - Initial contribution
38 * @author Christian Oeing - refactorings of e.g. server registration
39 * @author David Pace - Handler abstraction
43 public abstract class BoschSHCDeviceHandler extends BoschSHCHandler {
46 * Bosch SHC configuration loaded from openHAB configuration.
48 private @Nullable BoschSHCConfiguration config;
50 public BoschSHCDeviceHandler(Thing thing) {
55 public void initialize() {
56 var config = this.config = getConfigAs(BoschSHCConfiguration.class);
58 String deviceId = config.id;
59 if (deviceId == null || deviceId.isBlank()) {
60 this.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
61 "@text/offline.conf-error.empty-device-id");
65 // Try to get device info to make sure the device exists
67 var bridgeHandler = this.getBridgeHandler();
68 var info = bridgeHandler.getDeviceInfo(deviceId);
69 logger.trace("Device initialized:\n{}", info);
70 } catch (TimeoutException | ExecutionException | BoschSHCException e) {
71 this.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
73 } catch (InterruptedException e) {
74 Thread.currentThread().interrupt();
75 this.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
83 * Returns the unique id of the Bosch device.
85 * @return Unique id of the Bosch device.
88 public @Nullable String getBoschID() {