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;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Handler for physical Bosch devices with configurable IDs (as opposed to system services, which have static IDs).
30 * The device ID of physical devices has to be configured in the thing configuration.
32 * Examples for physical device IDs are:
35 * hdm:Cameras:d20354de-44b5-3acc-924c-24c98d59da42
36 * hdm:ZigBee:000d6f0016d1cdae
39 * @author Stefan Kästle - Initial contribution
40 * @author Christian Oeing - refactorings of e.g. server registration
41 * @author David Pace - Handler abstraction
45 public abstract class BoschSHCDeviceHandler extends BoschSHCHandler {
47 private final Logger logger = LoggerFactory.getLogger(getClass());
50 * Bosch SHC configuration loaded from openHAB configuration.
52 private @Nullable BoschSHCConfiguration config;
54 protected BoschSHCDeviceHandler(Thing thing) {
59 public void initialize() {
60 var config = this.config = getConfigAs(BoschSHCConfiguration.class);
62 String deviceId = config.id;
63 if (deviceId == null || deviceId.isBlank()) {
64 this.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
65 "@text/offline.conf-error.empty-device-id");
69 // Try to get device info to make sure the device exists
71 var bridgeHandler = this.getBridgeHandler();
72 var info = bridgeHandler.getDeviceInfo(deviceId);
73 logger.trace("Device initialized:\n{}", info);
74 } catch (TimeoutException | ExecutionException | BoschSHCException e) {
75 this.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
77 } catch (InterruptedException e) {
78 Thread.currentThread().interrupt();
79 this.updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
87 * Returns the unique id of the Bosch device.
89 * @return Unique id of the Bosch device.
92 public @Nullable String getBoschID() {