Search in sources :

Example 1 with Bridge

use of org.openhab.core.thing.Bridge in project org.openhab.binding.zwave by openhab.

the class ZWaveThingHandler method initialize.

@Override
public void initialize() {
    logger.debug("Initializing ZWave thing handler {}.", getThing().getUID());
    final BigDecimal cfgNodeId = (BigDecimal) getConfig().get(ZWaveBindingConstants.CONFIGURATION_NODEID);
    if (cfgNodeId == null) {
        logger.debug("NodeID is not set in {}", getThing().getUID());
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, ZWaveBindingConstants.OFFLINE_NODEID_UNSET);
        return;
    }
    nodeId = cfgNodeId.intValue();
    if (nodeId < 1 || nodeId > 232) {
        logger.debug("NodeID ({}) out of range for {}", cfgNodeId, getThing().getUID());
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, ZWaveBindingConstants.OFFLINE_NODEID_INVALID);
        return;
    }
    // We need to set the status to OFFLINE so that the framework calls our notification handlers
    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, ZWaveBindingConstants.OFFLINE_CTLR_OFFLINE);
    // Make sure the thingType is set correctly from the database
    if (updateThingType() == true) {
        // The thing will have been disposed of so let's exit!
        return;
    }
    // TODO: Shouldn't the framework do this for us???
    Bridge bridge = getBridge();
    if (bridge != null) {
        ThingHandler handler = bridge.getHandler();
        if (handler instanceof ZWaveControllerHandler) {
            ZWaveControllerHandler bridgeHandler = (ZWaveControllerHandler) handler;
            if (bridgeHandler.getOwnNodeId() != 0) {
                bridgeStatusChanged(bridge.getStatusInfo());
            }
        }
    }
}
Also used : ConfigStatusThingHandler(org.openhab.core.thing.binding.ConfigStatusThingHandler) ThingHandler(org.openhab.core.thing.binding.ThingHandler) BigDecimal(java.math.BigDecimal) Bridge(org.openhab.core.thing.Bridge)

Example 2 with Bridge

use of org.openhab.core.thing.Bridge in project openhab-addons by openhab.

the class AlarmDecoderHandlerFactory method createHandler.

// Marked as Nullable only to fix incorrect redundant null check complaints from null annotations
@Override
@Nullable
protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();
    if (THING_TYPE_IPBRIDGE.equals(thingTypeUID)) {
        IPBridgeHandler bridgeHandler = new IPBridgeHandler((Bridge) thing);
        registerDiscoveryService(bridgeHandler);
        return bridgeHandler;
    } else if (THING_TYPE_SERIALBRIDGE.equals(thingTypeUID)) {
        SerialBridgeHandler bridgeHandler = new SerialBridgeHandler((Bridge) thing, serialPortManager);
        registerDiscoveryService(bridgeHandler);
        return bridgeHandler;
    } else if (THING_TYPE_ZONE.equals(thingTypeUID)) {
        return new ZoneHandler(thing);
    } else if (THING_TYPE_RFZONE.equals(thingTypeUID)) {
        return new RFZoneHandler(thing);
    } else if (THING_TYPE_VZONE.equals(thingTypeUID)) {
        return new VZoneHandler(thing);
    } else if (THING_TYPE_KEYPAD.equals(thingTypeUID)) {
        return new KeypadHandler(thing);
    } else if (THING_TYPE_LRR.equals(thingTypeUID)) {
        return new LRRHandler(thing);
    }
    return null;
}
Also used : SerialBridgeHandler(org.openhab.binding.alarmdecoder.internal.handler.SerialBridgeHandler) LRRHandler(org.openhab.binding.alarmdecoder.internal.handler.LRRHandler) RFZoneHandler(org.openhab.binding.alarmdecoder.internal.handler.RFZoneHandler) VZoneHandler(org.openhab.binding.alarmdecoder.internal.handler.VZoneHandler) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) KeypadHandler(org.openhab.binding.alarmdecoder.internal.handler.KeypadHandler) IPBridgeHandler(org.openhab.binding.alarmdecoder.internal.handler.IPBridgeHandler) Bridge(org.openhab.core.thing.Bridge) RFZoneHandler(org.openhab.binding.alarmdecoder.internal.handler.RFZoneHandler) ZoneHandler(org.openhab.binding.alarmdecoder.internal.handler.ZoneHandler) VZoneHandler(org.openhab.binding.alarmdecoder.internal.handler.VZoneHandler) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with Bridge

use of org.openhab.core.thing.Bridge in project openhab-addons by openhab.

the class ADThingHandler method initDeviceState.

/**
 * Initialize device state and set status for handler. Should be called at the end of initialize(). Also called by
 * bridgeStatusChanged() when bridge status changes from OFFLINE to ONLINE. Calls initChannelState() to initialize
 * channels if setting status to ONLINE.
 */
protected void initDeviceState() {
    logger.trace("Initializing device state");
    Bridge bridge = getBridge();
    if (bridge == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No bridge configured");
    } else if (bridge.getStatus() == ThingStatus.ONLINE) {
        initChannelState();
        updateStatus(ThingStatus.ONLINE);
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
    }
}
Also used : Bridge(org.openhab.core.thing.Bridge)

Example 4 with Bridge

use of org.openhab.core.thing.Bridge in project openhab-addons by openhab.

the class Cm11aLampHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.debug("**** Cm11aLampHandler handleCommand command = {}, channelUID = {}", command.toString(), channelUID.getAsString());
    x10Function = 0;
    Bridge bridge = getBridge();
    if (bridge == null) {
        logger.debug("Unable to handle command. Bridge is null.");
        return;
    }
    this.channelUID = channelUID;
    Cm11aBridgeHandler cm11aHandler = (Cm11aBridgeHandler) bridge.getHandler();
    if (cm11aHandler != null && cm11aHandler.getThing().getStatus().equals(ThingStatus.ONLINE)) {
        if (OnOffType.ON.equals(command)) {
            desiredState = OnOffType.ON;
        } else if (OnOffType.OFF.equals(command)) {
            desiredState = OnOffType.OFF;
        } else if (command instanceof PercentType) {
            desiredState = (PercentType) command;
        } else if (command instanceof RefreshType) {
            // Refresh is triggered by framework during startup.
            // Force the lamp off by indicating it is currently on and we want it off
            // Start with it off
            desiredState = PercentType.ZERO;
            logger.info("Received REFRESH command for switch {}", houseUnitCode);
        } else {
            logger.error("Ignoring unknown command received for device: {}", houseUnitCode);
        }
        if (!(desiredState instanceof UnDefType)) {
            X10Interface x10Interface = cm11aHandler.getX10Interface();
            x10Interface.scheduleHWUpdate(this);
        }
    } else {
        logger.error("Attempted to change switch {} cm11a is not online", houseUnitCode);
    }
}
Also used : X10Interface(org.openhab.binding.cm11a.internal.X10Interface) UnDefType(org.openhab.core.types.UnDefType) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) Bridge(org.openhab.core.thing.Bridge)

Example 5 with Bridge

use of org.openhab.core.thing.Bridge in project openhab-addons by openhab.

the class CBusGroupHandler method getCBusNetworkHandler.

@Nullable
private CBusNetworkHandler getCBusNetworkHandler() {
    Bridge bridge = getBridge();
    if (bridge == null) {
        logger.debug("Required bridge not defined for device .");
        return null;
    }
    ThingHandler handler = bridge.getHandler();
    if (handler instanceof CBusNetworkHandler) {
        return (CBusNetworkHandler) handler;
    }
    logger.debug("No available bridge handler found for bridge: {}", bridge.getUID());
    return null;
}
Also used : ThingHandler(org.openhab.core.thing.binding.ThingHandler) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) Bridge(org.openhab.core.thing.Bridge) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Bridge (org.openhab.core.thing.Bridge)394 Nullable (org.eclipse.jdt.annotation.Nullable)95 Thing (org.openhab.core.thing.Thing)69 ThingHandler (org.openhab.core.thing.binding.ThingHandler)68 Test (org.junit.jupiter.api.Test)54 Configuration (org.openhab.core.config.core.Configuration)54 ChannelUID (org.openhab.core.thing.ChannelUID)49 BaseThingHandler (org.openhab.core.thing.binding.BaseThingHandler)43 ThingUID (org.openhab.core.thing.ThingUID)39 ArrayList (java.util.ArrayList)36 Channel (org.openhab.core.thing.Channel)32 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)30 ThingStatus (org.openhab.core.thing.ThingStatus)29 BridgeHandler (org.openhab.core.thing.binding.BridgeHandler)29 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)25 RefreshType (org.openhab.core.types.RefreshType)22 List (java.util.List)20 BeforeEach (org.junit.jupiter.api.BeforeEach)20 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)19 Command (org.openhab.core.types.Command)18