/**
  * Returns the {@link SocketSession} for this {@link Bridge}. The default implementation is to
  * look in the parent {@link #getBridge()} for the {@link SocketSession}
  *
  * @return a {@link SocketSession} or null if none exists
  */
 @SuppressWarnings("rawtypes")
 public SocketSession getSocketSession() {
   final Bridge bridge = getBridge();
   if (bridge.getHandler() instanceof AbstractBridgeHandler) {
     return ((AbstractBridgeHandler) bridge.getHandler()).getSocketSession();
   }
   return null;
 }
  /**
   * Finds and returns a child thing for a given UID of this bridge.
   *
   * @param uid uid of the child thing
   * @return child thing with the given uid or null if thing was not found
   */
  public Thing getThingByUID(ThingUID uid) {

    Bridge bridge = getThing();

    List<Thing> things = bridge.getThings();

    for (Thing thing : things) {
      if (thing.getUID().equals(uid)) {
        return thing;
      }
    }

    return null;
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.smarthome.core.thing.binding.BaseThingHandler#
  * bridgeHandlerDisposed
  * (org.eclipse.smarthome.core.thing.binding.ThingHandler,
  * org.eclipse.smarthome.core.thing.Bridge)
  */
 @Override
 public void bridgeHandlerDisposed(ThingHandler thingHandler, Bridge bridge) {
   logger.debug(
       "Bridge {} disposed for device: {}",
       bridge.getUID().toString(),
       getThing().getUID().toString());
   bridgeHandler = null;
   forceRefresh = true;
   super.bridgeHandlerDisposed(thingHandler, bridge);
 }
  private synchronized MaxCubeBridgeHandler getMaxCubeBridgeHandler() {

    if (this.bridgeHandler == null) {
      Bridge bridge = getBridge();
      if (bridge == null) {
        logger.debug("Required bridge not defined for device {}.", maxDeviceSerial);
        return null;
      }
      ThingHandler handler = bridge.getHandler();
      if (handler instanceof MaxCubeBridgeHandler) {
        this.bridgeHandler = (MaxCubeBridgeHandler) handler;
        this.bridgeHandler.registerDeviceStatusListener(this);
        forceRefresh = true;
      } else {
        logger.debug(
            "No available bridge handler found for {} bridge {} .",
            maxDeviceSerial,
            bridge.getUID());
        return null;
      }
    }
    return this.bridgeHandler;
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.smarthome.core.thing.binding.BaseThingHandler#
  * bridgeHandlerInitialized
  * (org.eclipse.smarthome.core.thing.binding.ThingHandler,
  * org.eclipse.smarthome.core.thing.Bridge)
  */
 @Override
 public void bridgeHandlerInitialized(ThingHandler thingHandler, Bridge bridge) {
   logger.debug(
       "Bridge {} initialized for device: {}",
       bridge.getUID().toString(),
       getThing().getUID().toString());
   if (bridgeHandler != null) {
     bridgeHandler.unregisterDeviceStatusListener(this);
     bridgeHandler = null;
   }
   this.bridgeHandler = (MaxCubeBridgeHandler) thingHandler;
   this.bridgeHandler.registerDeviceStatusListener(this);
   forceRefresh = true;
   super.bridgeHandlerInitialized(thingHandler, bridge);
 }