Exemplo n.º 1
0
  /**
   * 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;
  }
Exemplo n.º 2
0
 protected void requestParentRefresh() {
   logger.debug("Updating parent modules of {}", configuration.getEquipmentId());
   for (Thing thing : getBridge().getThings()) {
     ThingHandler thingHandler = thing.getHandler();
     if (thingHandler instanceof NetatmoDeviceHandler) {
       @SuppressWarnings("unchecked")
       NetatmoDeviceHandler<NetatmoDeviceConfiguration> deviceHandler =
           (NetatmoDeviceHandler<NetatmoDeviceConfiguration>) thingHandler;
       NetatmoDeviceConfiguration deviceConfiguration = deviceHandler.configuration;
       if (deviceConfiguration.getEquipmentId().equalsIgnoreCase(configuration.getParentId())) {
         // I'm your father Luke
         thingHandler.handleCommand(null, RefreshType.REFRESH);
       }
     }
   }
 }
 @Override
 protected ThingHandler createHandler(Thing thing) {
   if (thing.getThingTypeUID().equals(TELLDUSCOREBRIDGE_THING_TYPE)) {
     TelldusCoreBridgeHandler handler = new TelldusCoreBridgeHandler((Bridge) thing);
     registerDeviceDiscoveryService(handler);
     return handler;
   } else if (thing.getThingTypeUID().equals(TELLDUSLIVEBRIDGE_THING_TYPE)) {
     TelldusLiveBridgeHandler handler = new TelldusLiveBridgeHandler((Bridge) thing);
     registerDeviceDiscoveryService(handler);
     return handler;
   } else if (supportsThingType(thing.getThingTypeUID())) {
     return new TelldusDevicesHandler(thing);
   } else {
     logger.debug("ThingHandler not found for {}", thing.getThingTypeUID());
     return null;
   }
 }
Exemplo n.º 4
0
  @Override
  protected ThingHandler createHandler(Thing thing) {

    ThingTypeUID thingTypeUID = thing.getThingTypeUID();

    if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
      return new EnOceanHandler(thing);
    }

    return null;
  }
  @Override
  protected ThingHandler createHandler(Thing thing) {

    ThingTypeUID thingTypeUID = thing.getThingTypeUID();

    if (thingTypeUID.equals(YahooWeatherBindingConstants.THING_TYPE_WEATHER)) {
      return new YahooWeatherHandler(thing);
    }

    return null;
  }
Exemplo n.º 6
0
  @Override
  protected ThingHandler createHandler(Thing thing) {

    ThingTypeUID thingTypeUID = thing.getThingTypeUID();

    if (thingTypeUID.equals(THING_TYPE_SAMPLE)) {
      return new nest2Handler(thing);
    }

    return null;
  }
  @Override
  protected ThingHandler createHandler(Thing thing) {

    ThingTypeUID thingTypeUID = thing.getThingTypeUID();

    if (thingTypeUID.equals(THING_TYPE_COMPUTER)) {
      return new SysteminfoHandler(thing);
    }

    return null;
  }
  private int getFreeId() {
    int id = 1;

    List<Number> takenIds = new ArrayList<Number>();

    // Which ids are taken in Thing list of OpenHAB
    Collection<Thing> thingList = thingRegistry.getAll();
    Iterator<Thing> iterator = thingList.iterator();

    while (iterator.hasNext()) {
      Thing thing = iterator.next();
      Configuration conf = thing.getConfiguration();
      if (conf != null) {
        Object nodeIdobj = conf.get("nodeId");
        if (nodeIdobj != null) {
          int nodeId = Integer.parseInt(nodeIdobj.toString());
          takenIds.add(nodeId);
        }
      }
    }

    // Which ids are already given by the binding, but not yet in the thing list?
    Iterator<Number> iteratorGiven = givenIds.iterator();
    while (iteratorGiven.hasNext()) {
      takenIds.add(iteratorGiven.next());
    }

    // generate new id
    boolean foundId = false;
    while (!foundId) {
      Random rand = new Random(System.currentTimeMillis());
      int newId = rand.nextInt((254 - 1) + 1) + 1;
      if (!takenIds.contains(newId)) {
        id = newId;
        foundId = true;
      }
    }

    return id;
  }
  @Override
  protected ThingHandler createHandler(Thing thing) {

    ThingTypeUID thingTypeUID = thing.getThingTypeUID();

    if (thingTypeUID.equals(URTSI_DEVICE_THING_TYPE) && thing instanceof Bridge) {
      return new UrtsiDeviceHandler((Bridge) thing);
    } else if (thingTypeUID.equals(RTS_DEVICE_THING_TYPE)) {
      return new RtsDeviceHandler(thing);
    }

    return null;
  }
Exemplo n.º 10
0
  /**
   * Maps thing into thing data transfer object (DTO).
   *
   * @param thing the thing
   * @return the thing DTO object
   */
  public static ThingDTO map(Thing thing) {
    List<ChannelDTO> channelDTOs = new ArrayList<>();
    for (Channel channel : thing.getChannels()) {
      ChannelDTO channelDTO = ChannelDTOMapper.map(channel);
      channelDTOs.add(channelDTO);
    }

    String thingTypeUID = thing.getThingTypeUID().getAsString();
    String thingUID = thing.getUID().toString();
    String bridgeUID = thing.getBridgeUID() != null ? thing.getBridgeUID().toString() : null;

    return new ThingDTO(
        thingTypeUID,
        thingUID,
        thing.getLabel(),
        bridgeUID,
        channelDTOs,
        thing.getConfiguration(),
        thing.getProperties(),
        thing.getLocation());
  }
  @Override
  protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();

    if (thingTypeUID.equals(SQUEEZEBOXPLAYER_THING_TYPE)) {
      return new SqueezeBoxPlayerHandler(thing);
    }

    if (thingTypeUID.equals(SQUEEZEBOXSERVER_THING_TYPE)) {
      logger.trace("Returning handler for bridge thing {}", thing);
      SqueezeBoxServerHandler handler = new SqueezeBoxServerHandler((Bridge) thing);
      registerSqueezeBoxPlayerDiscoveryService(handler);
      return handler;
    }

    return null;
  }
  @Override
  protected ThingHandler createHandler(Thing thing) {

    ThingTypeUID thingTypeUID = thing.getThingTypeUID();

    if (thingTypeUID.equals(THING_TYPE_IPBRIDGE)) {
      return new IPBridgeHandler((Bridge) thing);
    } else if (thingTypeUID.equals(THING_TYPE_DIMMER)) {
      return new DimmerHandler(thing);
    } else if (thingTypeUID.equals(THING_TYPE_SWITCH)) {
      return new SwitchHandler(thing);
    } else if (thingTypeUID.equals(THING_TYPE_OCCUPANCYSENSOR)) {
      return new OccupancySensorHandler(thing);
    } else if (thingTypeUID.equals(THING_TYPE_KEYPAD)) {
      return new KeypadHandler(thing);
    }

    return null;
  }
Exemplo n.º 13
0
  /** {@inheritDoc} */
  @Override
  public void dscAlarmEventReceived(EventObject event, Thing thing) {

    if (thing != null) {
      if (getThing() == thing) {
        DSCAlarmEvent dscAlarmEvent = (DSCAlarmEvent) event;
        DSCAlarmMessage apiMessage = dscAlarmEvent.getDSCAlarmMessage();

        ChannelUID channelUID = null;
        DSCAlarmCode apiCode =
            DSCAlarmCode.getDSCAlarmCodeValue(
                apiMessage.getMessageInfo(DSCAlarmMessageInfoType.CODE));
        String apiData = apiMessage.getMessageInfo(DSCAlarmMessageInfoType.DATA);

        logger.debug("dscAlarmEventRecieved(): Thing - {}   Command - {}", thing.getUID(), apiCode);

        switch (apiCode) {
          case KeypadLEDState: /* 510 */
          case KeypadLEDFlashState: /* 511 */
            keypadLEDStateEventHandler(event);
            break;
          case LEDStatus: /* 903 */
            int aData = Integer.parseInt(apiData.substring(0, 1));
            int state =
                Integer.parseInt(
                    apiMessage.getMessageInfo(DSCAlarmMessageInfoType.DATA).substring(1));
            switch (aData) {
              case 1:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_READY_LED);
                properties.setLEDState(LEDStateType.READY_LED_STATE, state);
                updateChannel(channelUID);
                break;
              case 2:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_ARMED_LED);
                properties.setLEDState(LEDStateType.ARMED_LED_STATE, state);
                updateChannel(channelUID);
                break;
              case 3:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_MEMORY_LED);
                properties.setLEDState(LEDStateType.MEMORY_LED_STATE, state);
                updateChannel(channelUID);
                break;
              case 4:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_BYPASS_LED);
                properties.setLEDState(LEDStateType.BYPASS_LED_STATE, state);
                updateChannel(channelUID);
                break;
              case 5:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_TROUBLE_LED);
                properties.setLEDState(LEDStateType.TROUBLE_LED_STATE, state);
                updateChannel(channelUID);
                break;
              case 6:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_PROGRAM_LED);
                properties.setLEDState(LEDStateType.PROGRAM_LED_STATE, state);
                updateChannel(channelUID);
                break;
              case 7:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_FIRE_LED);
                properties.setLEDState(LEDStateType.FIRE_LED_STATE, state);
                updateChannel(channelUID);
                break;
              case 8:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_BACKLIGHT_LED);
                properties.setLEDState(LEDStateType.BACKLIGHT_LED_STATE, state);
                updateChannel(channelUID);
                break;
              case 9:
                channelUID = new ChannelUID(getThing().getUID(), KEYPAD_AC_LED);
                properties.setLEDState(LEDStateType.AC_LED_STATE, state);
                updateChannel(channelUID);
                break;
              default:
                break;
            }
          default:
            break;
        }
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void dscAlarmEventReceived(EventObject event, Thing thing) {

    if (thing != null) {
      DSCAlarmEvent dscAlarmEvent = (DSCAlarmEvent) event;
      DSCAlarmMessage dscAlarmMessage = dscAlarmEvent.getDSCAlarmMessage();
      setTimeStampState(dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.TIME_STAMP));
      boolean suppressPanelMsg = false;

      if (getThing() == thing) {
        ChannelUID channelUID = null;
        DSCAlarmCode apiCode =
            DSCAlarmCode.getDSCAlarmCodeValue(
                dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.CODE));
        logger.debug("dscAlarmEventRecieved(): Thing - {}   Command - {}", thing.getUID(), apiCode);

        int state = 0;

        switch (apiCode) {
          case CommandAcknowledge: /* 500 */
            if (getSuppressAcknowledgementMsgs()) {
              suppressPanelMsg = true;
            }
            break;
          case SystemError: /* 502 */
            panelSystemError(dscAlarmMessage);
            break;
          case TimeDateBroadcast: /* 550 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_TIME);
            String panelTime = dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.DATA);
            updateProperties(channelUID, state, panelTime);
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_TIME_BROADCAST);
            updateProperties(channelUID, 1, "");
            updateChannel(channelUID);

            if (getSuppressAcknowledgementMsgs()) {
              suppressPanelMsg = true;
            }

            break;
          case FireKeyAlarm: /* 621 */
            state = 1;
          case FireKeyRestored: /* 622 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_FIRE_KEY_ALARM);
            updateProperties(channelUID, state, "");
            updateChannel(channelUID);
            break;
          case AuxiliaryKeyAlarm: /* 623 */
            state = 1;
          case AuxiliaryKeyRestored: /* 624 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_AUX_KEY_ALARM);
            updateProperties(channelUID, state, "");
            updateChannel(channelUID);
            break;
          case PanicKeyAlarm: /* 625 */
            state = 1;
          case PanicKeyRestored: /* 626 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_PANIC_KEY_ALARM);
            updateProperties(channelUID, state, "");
            updateChannel(channelUID);
            break;
          case AuxiliaryInputAlarm: /* 631 */
            state = 1;
          case AuxiliaryInputAlarmRestored: /* 632 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_AUX_INPUT_ALARM);
            updateProperties(channelUID, state, "");
            updateChannel(channelUID);
            break;
          case TroubleLEDOn: /* 840 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_TROUBLE_LED);
            updateProperties(channelUID, 1, "");
            updateChannel(channelUID);
            break;
          case TroubleLEDOff: /* 841 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_SERVICE_REQUIRED);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_AC_TROUBLE);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_TELEPHONE_TROUBLE);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_FTC_TROUBLE);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_ZONE_FAULT);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_ZONE_TAMPER);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_ZONE_LOW_BATTERY);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_TIME_LOSS);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);

            channelUID = new ChannelUID(getThing().getUID(), PANEL_TROUBLE_LED);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);
            break;
          case PanelBatteryTrouble: /* 800 */
          case PanelACTrouble: /* 802 */
          case SystemBellTrouble: /* 806 */
          case TLMLine1Trouble: /* 810 */
          case TLMLine2Trouble: /* 812 */
          case FTCTrouble: /* 814 */
          case GeneralDeviceLowBattery: /* 821 */
          case WirelessKeyLowBatteryTrouble: /* 825 */
          case HandheldKeypadLowBatteryTrouble: /* 827 */
          case GeneralSystemTamper: /* 829 */
          case HomeAutomationTrouble: /* 831 */
          case KeybusFault: /* 896 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_TROUBLE_MESSAGE);
            updateProperties(
                channelUID, 0, dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.DESCRIPTION));
            updateChannel(channelUID);
            break;
          case PanelBatteryTroubleRestore: /* 801 */
          case PanelACRestore: /* 803 */
          case SystemBellTroubleRestore: /* 807 */
          case TLMLine1TroubleRestore: /* 811 */
          case TLMLine2TroubleRestore: /* 813 */
          case GeneralDeviceLowBatteryRestore: /* 822 */
          case WirelessKeyLowBatteryTroubleRestore: /* 826 */
          case HandheldKeypadLowBatteryTroubleRestore: /* 828 */
          case GeneralSystemTamperRestore: /* 830 */
          case HomeAutomationTroubleRestore: /* 832 */
          case KeybusFaultRestore: /* 897 */
            channelUID = new ChannelUID(getThing().getUID(), PANEL_TROUBLE_MESSAGE);
            updateProperties(channelUID, 0, "");
            updateChannel(channelUID);
            break;
          case VerboseTroubleStatus: /* 849 */
            verboseTroubleStatusHandler(event);
            break;
          case CodeRequired: /* 900 */
            dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.CodeSend, getUserCode());
            break;
          default:
            break;
        }
      }

      if (!suppressPanelMsg) {
        setPanelMessage(dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.DESCRIPTION));
      }
    }
  }
    @Override
    public ConfigDescription getConfigDescription(URI uri, Locale locale) {
        if (uri == null) {
            return null;
        }

        if ("thing".equals(uri.getScheme()) == false) {
            return null;
        }

        ThingUID thingUID = new ThingUID(uri.getSchemeSpecificPart());
        ThingType thingType = thingTypeRegistry.getThingType(thingUID.getThingTypeUID());
        if (thingType == null) {
            return null;
        }

        // Is this a zwave thing?
        if (!thingUID.getBindingId().equals(ZWaveBindingConstants.BINDING_ID)) {
            return null;
        }

        // And make sure this is a node because we want to get the id off the end...
        if (!thingUID.getId().startsWith("node")) {
            return null;
        }
        int nodeId = Integer.parseInt(thingUID.getId().substring(4));

        Thing thing = getThing(thingUID);
        if (thing == null) {
            return null;
        }
        ThingUID bridgeUID = thing.getBridgeUID();

        // Get the controller for this thing
        Thing bridge = getThing(bridgeUID);
        if (bridge == null) {
            return null;
        }

        // Get its handler and node
        ZWaveControllerHandler handler = (ZWaveControllerHandler) bridge.getHandler();
        ZWaveNode node = handler.getNode(nodeId);

        List<ConfigDescriptionParameterGroup> groups = new ArrayList<ConfigDescriptionParameterGroup>();
        List<ConfigDescriptionParameter> parameters = new ArrayList<ConfigDescriptionParameter>();

        groups.add(new ConfigDescriptionParameterGroup("actions", "", false, "Actions", null));
        groups.add(new ConfigDescriptionParameterGroup("thingcfg", "home", false, "Device Configuration", null));

        parameters.add(ConfigDescriptionParameterBuilder
                .create(ZWaveBindingConstants.CONFIGURATION_POLLPERIOD, Type.INTEGER).withLabel("Polling Period")
                .withDescription("Set the minimum polling period for this device<BR/>"
                        + "Note that the polling period may be longer than set since the binding treats "
                        + "polls as the lowest priority data within the network.")
                .withDefault("1800").withGroupName("thingcfg").build());

        // If we support the wakeup class, then add the configuration
        if (node.getCommandClass(ZWaveCommandClass.CommandClass.WAKE_UP) != null) {
            groups.add(new ConfigDescriptionParameterGroup("wakeup", "sleep", false, "Wakeup Configuration", null));

            parameters.add(ConfigDescriptionParameterBuilder
                    .create(ZWaveBindingConstants.CONFIGURATION_WAKEUPINTERVAL, Type.TEXT).withLabel("Wakeup Interval")
                    .withDescription("Sets the number of seconds that the device will wakeup<BR/>"
                            + "Setting a shorter time will allow openHAB to configure the device more regularly, but may use more battery power.<BR>"
                            + "<B>Note:</B> This setting does not impact device notifications such as alarms.")
                    .withDefault("").withGroupName("wakeup").build());

            parameters.add(
                    ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_WAKEUPNODE, Type.TEXT)
                            .withLabel("Wakeup Node").withAdvanced(true)
                            .withDescription("Sets the wakeup node to which the device will send notifications.<BR/>"
                                    + "This should normally be set to the openHAB controller - "
                                    + "if it isn't, openHAB will not receive notifications when the device wakes up, "
                                    + "and will not be able to configure the device.")
                            .withDefault("").withGroupName("wakeup").build());
        }

        // If we support the node name class, then add the configuration
        if (node.getCommandClass(ZWaveCommandClass.CommandClass.NODE_NAMING) != null) {
            parameters.add(
                    ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_NODENAME, Type.TEXT)
                            .withLabel("Node Name").withDescription("Sets a string for the device name")
                            .withGroupName("thingcfg").withDefault("").build());
            parameters.add(ConfigDescriptionParameterBuilder
                    .create(ZWaveBindingConstants.CONFIGURATION_NODELOCATION, Type.TEXT)
                    .withDescription("Sets a string for the device location").withLabel("Node Location").withDefault("")
                    .withGroupName("thingcfg").build());
        }

        // If we support the switch_all class, then add the configuration
        if (node.getCommandClass(ZWaveCommandClass.CommandClass.SWITCH_ALL) != null) {
            List<ParameterOption> options = new ArrayList<ParameterOption>();
            options.add(new ParameterOption("0", "Exclude from All On and All Off groups"));
            options.add(new ParameterOption("1", "Include in All On group"));
            options.add(new ParameterOption("2", "Include in All Off group"));
            options.add(new ParameterOption("255", "Include in All On and All Off groups"));
            parameters.add(ConfigDescriptionParameterBuilder
                    .create(ZWaveBindingConstants.CONFIGURATION_SWITCHALLMODE, Type.TEXT).withLabel("Switch All Mode")
                    .withDescription("Set the mode for the switch when receiving SWITCH ALL commands.").withDefault("0")
                    .withGroupName("thingcfg").withOptions(options).build());
        }

        // If we support DOOR_LOCK - add options
        if (node.getCommandClass(ZWaveCommandClass.CommandClass.DOOR_LOCK) != null) {
            parameters.add(ConfigDescriptionParameterBuilder
                    .create(ZWaveBindingConstants.CONFIGURATION_DOORLOCKTIMEOUT, Type.TEXT).withLabel("Lock Timeout")
                    .withDescription("Set the timeout on the lock.").withDefault("30").withGroupName("thingcfg")
                    .build());
        }

        ZWaveUserCodeCommandClass userCodeClass = (ZWaveUserCodeCommandClass) node
                .getCommandClass(ZWaveCommandClass.CommandClass.USER_CODE);
        if (userCodeClass != null && userCodeClass.getNumberOfSupportedCodes() > 0) {
            groups.add(new ConfigDescriptionParameterGroup("usercode", "lock", false, "User Code", null));

            for (int code = 1; code <= userCodeClass.getNumberOfSupportedCodes(); code++) {
                parameters.add(ConfigDescriptionParameterBuilder
                        .create(ZWaveBindingConstants.CONFIGURATION_USERCODE + code, Type.TEXT)
                        .withLabel("Code " + code).withDescription("Set the user code (4 to 10 numbers)")
                        .withDefault("").withGroupName("usercode").build());
            }
        }

        List<ParameterOption> options = new ArrayList<ParameterOption>();
        options.add(new ParameterOption(ZWaveBindingConstants.ACTION_CHECK_VALUE.toString(), "Do"));