use of org.openhab.core.thing.binding.BridgeHandler in project openhab-addons by openhab.
the class CurtainHandler method initialize.
@Override
public void initialize() {
Bridge bridge = getBridge();
if (bridge == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Bridge not present");
return;
}
BridgeHandler handler = bridge.getHandler();
if (handler == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Bridge has no handler");
return;
}
bus = ((BusHandler) handler).getBus();
config = getConfigAs(CurtainConfiguration.class);
updateStatus(ThingStatus.UNKNOWN);
logger.trace("Successfully initialized, starting poll");
pollFuture = scheduler.scheduleWithFixedDelay(this::poll, 1, config.pollInterval, TimeUnit.SECONDS);
}
use of org.openhab.core.thing.binding.BridgeHandler in project openhab-addons by openhab.
the class VehicleHandler method initialize.
@Override
public void initialize() {
callbackCounter = Optional.of(new ArrayList<ResponseCallback>());
updateStatus(ThingStatus.UNKNOWN);
final VehicleConfiguration config = getConfigAs(VehicleConfiguration.class);
configuration = Optional.of(config);
Bridge bridge = getBridge();
if (bridge != null) {
BridgeHandler handler = bridge.getHandler();
if (handler != null) {
bridgeHandler = Optional.of(((ConnectedDriveBridgeHandler) handler));
proxy = ((ConnectedDriveBridgeHandler) handler).getProxy();
remote = proxy.map(prox -> prox.getRemoteServiceHandler(this));
} else {
logger.debug("Bridge Handler null");
}
} else {
logger.debug("Bridge null");
}
// get Image after init with config values
synchronized (imageProperties) {
imageProperties = new ImageProperties(config.imageViewport, config.imageSize);
}
updateChannel(CHANNEL_GROUP_VEHICLE_IMAGE, IMAGE_VIEWPORT, StringType.valueOf((config.imageViewport)));
updateChannel(CHANNEL_GROUP_VEHICLE_IMAGE, IMAGE_SIZE, new DecimalType((config.imageSize)));
// check imperial setting is different to AutoDetect
if (!UNITS_AUTODETECT.equals(config.units)) {
imperial = UNITS_IMPERIAL.equals(config.units);
}
// start update schedule
startSchedule(config.refreshInterval);
}
use of org.openhab.core.thing.binding.BridgeHandler in project openhab-addons by openhab.
the class QueryHandler method updateStateWithParentBridgeStatus.
private void updateStateWithParentBridgeStatus() {
@Nullable final Bridge bridge = getBridge();
DatabaseBridgeHandler databaseBridgeHandler;
if (bridge != null) {
@Nullable BridgeHandler bridgeHandler = bridge.getHandler();
if (bridgeHandler instanceof DatabaseBridgeHandler) {
databaseBridgeHandler = (DatabaseBridgeHandler) bridgeHandler;
database = databaseBridgeHandler.getDatabase();
if (bridge.getStatus() == ThingStatus.ONLINE) {
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED);
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED);
}
}
use of org.openhab.core.thing.binding.BridgeHandler in project openhab-addons by openhab.
the class DaliRgbHandler method getBridgeHandler.
protected DaliserverBridgeHandler getBridgeHandler() throws DaliException {
Bridge bridge = this.getBridge();
if (bridge == null) {
throw new DaliException("No bridge was found");
}
BridgeHandler handler = bridge.getHandler();
if (handler == null) {
throw new DaliException("No handler was found");
}
return (DaliserverBridgeHandler) handler;
}
use of org.openhab.core.thing.binding.BridgeHandler in project openhab-addons by openhab.
the class BeaconBluetoothHandler method initialize.
@Override
public void initialize() {
try {
address = new BluetoothAddress(getConfig().get(BluetoothBindingConstants.CONFIGURATION_ADDRESS).toString());
} catch (IllegalArgumentException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getLocalizedMessage());
return;
}
Bridge bridge = getBridge();
if (bridge == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Not associated with any bridge");
return;
}
BridgeHandler bridgeHandler = bridge.getHandler();
if (!(bridgeHandler instanceof BluetoothAdapter)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Associated with an unsupported bridge");
return;
}
adapter = (BluetoothAdapter) bridgeHandler;
try {
deviceLock.lock();
device = adapter.getDevice(address);
device.addListener(this);
} finally {
deviceLock.unlock();
}
ThingBuilder builder = editThing();
boolean changed = false;
for (Channel channel : createDynamicChannels()) {
// we only want to add each channel, not replace all of them
if (getThing().getChannel(channel.getUID()) == null) {
builder.withChannel(channel);
changed = true;
}
}
if (changed) {
updateThing(builder.build());
}
updateStatus(ThingStatus.UNKNOWN);
}
Aggregations