예제 #1
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
    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"));