Search in sources :

Example 1 with BridgeHandler

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);
}
Also used : BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) Bridge(org.openhab.core.thing.Bridge)

Example 2 with BridgeHandler

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);
}
Also used : ProfileKey(org.openhab.binding.bmwconnecteddrive.internal.utils.ChargeProfileWrapper.ProfileKey) ScheduledFuture(java.util.concurrent.ScheduledFuture) ChargeProfileUtils(org.openhab.binding.bmwconnecteddrive.internal.utils.ChargeProfileUtils) StringType(org.openhab.core.library.types.StringType) AllTripsContainer(org.openhab.binding.bmwconnecteddrive.internal.dto.statistics.AllTripsContainer) Converter(org.openhab.binding.bmwconnecteddrive.internal.utils.Converter) OnOffType(org.openhab.core.library.types.OnOffType) DateTimeType(org.openhab.core.library.types.DateTimeType) RemoteServiceUtils(org.openhab.binding.bmwconnecteddrive.internal.utils.RemoteServiceUtils) Nullable(org.eclipse.jdt.annotation.Nullable) ExecutionState(org.openhab.binding.bmwconnecteddrive.internal.handler.RemoteServiceHandler.ExecutionState) ChargeKeyDay(org.openhab.binding.bmwconnecteddrive.internal.utils.ChargeProfileUtils.ChargeKeyDay) HttpUtil(org.openhab.core.io.net.http.HttpUtil) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) Collection(java.util.Collection) Set(java.util.Set) BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) List(java.util.List) NetworkError(org.openhab.binding.bmwconnecteddrive.internal.dto.NetworkError) DestinationContainer(org.openhab.binding.bmwconnecteddrive.internal.dto.DestinationContainer) Optional(java.util.Optional) VehicleStatus(org.openhab.binding.bmwconnecteddrive.internal.dto.status.VehicleStatus) ThingHandlerService(org.openhab.core.thing.binding.ThingHandlerService) BMWConnectedDriveActions(org.openhab.binding.bmwconnecteddrive.internal.action.BMWConnectedDriveActions) RemoteService(org.openhab.binding.bmwconnecteddrive.internal.handler.RemoteServiceHandler.RemoteService) ArrayList(java.util.ArrayList) LastTrip(org.openhab.binding.bmwconnecteddrive.internal.dto.statistics.LastTrip) VehicleStatusContainer(org.openhab.binding.bmwconnecteddrive.internal.dto.status.VehicleStatusContainer) Thing(org.openhab.core.thing.Thing) VehicleAttributesContainer(org.openhab.binding.bmwconnecteddrive.internal.dto.compat.VehicleAttributesContainer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConnectedDriveConstants(org.openhab.binding.bmwconnecteddrive.internal.ConnectedDriveConstants) ChannelUID(org.openhab.core.thing.ChannelUID) DecimalType(org.openhab.core.library.types.DecimalType) ChargeProfileWrapper(org.openhab.binding.bmwconnecteddrive.internal.utils.ChargeProfileWrapper) Units(org.openhab.core.library.unit.Units) QuantityType(org.openhab.core.library.types.QuantityType) ThingStatus(org.openhab.core.thing.ThingStatus) Command(org.openhab.core.types.Command) JsonSyntaxException(com.google.gson.JsonSyntaxException) RefreshType(org.openhab.core.types.RefreshType) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) AllTrips(org.openhab.binding.bmwconnecteddrive.internal.dto.statistics.AllTrips) TimeUnit(java.util.concurrent.TimeUnit) RawType(org.openhab.core.library.types.RawType) VehicleConfiguration(org.openhab.binding.bmwconnecteddrive.internal.VehicleConfiguration) LastTripContainer(org.openhab.binding.bmwconnecteddrive.internal.dto.statistics.LastTripContainer) NavigationContainer(org.openhab.binding.bmwconnecteddrive.internal.dto.navigation.NavigationContainer) Constants(org.openhab.binding.bmwconnecteddrive.internal.utils.Constants) ImageProperties(org.openhab.binding.bmwconnecteddrive.internal.utils.ImageProperties) Bridge(org.openhab.core.thing.Bridge) BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) ImageProperties(org.openhab.binding.bmwconnecteddrive.internal.utils.ImageProperties) ArrayList(java.util.ArrayList) VehicleConfiguration(org.openhab.binding.bmwconnecteddrive.internal.VehicleConfiguration) DecimalType(org.openhab.core.library.types.DecimalType) Bridge(org.openhab.core.thing.Bridge)

Example 3 with BridgeHandler

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);
    }
}
Also used : BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) Nullable(org.eclipse.jdt.annotation.Nullable) Bridge(org.openhab.core.thing.Bridge)

Example 4 with BridgeHandler

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;
}
Also used : BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) Bridge(org.openhab.core.thing.Bridge)

Example 5 with BridgeHandler

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);
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) Channel(org.openhab.core.thing.Channel) Bridge(org.openhab.core.thing.Bridge)

Aggregations

BridgeHandler (org.openhab.core.thing.binding.BridgeHandler)35 Bridge (org.openhab.core.thing.Bridge)30 Nullable (org.eclipse.jdt.annotation.Nullable)16 Thing (org.openhab.core.thing.Thing)6 RefreshType (org.openhab.core.types.RefreshType)6 Test (org.junit.jupiter.api.Test)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 ThingUID (org.openhab.core.thing.ThingUID)4 ThingHandler (org.openhab.core.thing.binding.ThingHandler)4 OnOffType (org.openhab.core.library.types.OnOffType)3 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)3 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)3 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)3 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 TimeUnit (java.util.concurrent.TimeUnit)2 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)2 DeviceDTO (org.openhab.binding.myq.internal.dto.DeviceDTO)2