Search in sources :

Example 1 with Thing

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

the class ZWaveConfigProvider method getConfigDescription.

@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
    if (!"thing".equals(uri.getScheme()) && !"thing-type".equals(uri.getScheme())) {
        return null;
    }
    ThingTypeUID thingTypeUID = new ThingTypeUID(uri.getSchemeSpecificPart());
    // Is this a zwave thing?
    if (!thingTypeUID.getBindingId().equals(ZWaveBindingConstants.BINDING_ID)) {
        return null;
    }
    List<ConfigDescriptionParameter> parameters = new ArrayList<ConfigDescriptionParameter>();
    if ("thing-type".equals(uri.getScheme())) {
        if (uri.getSchemeSpecificPart().equals(ZWaveBindingConstants.CONTROLLER_SERIAL.toString())) {
            return null;
        }
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_NODEID, Type.INTEGER).withLabel("Node ID").withMinimum(new BigDecimal("1")).withMaximum(new BigDecimal("232")).withAdvanced(true).withReadOnly(true).withRequired(true).withDescription("Sets the node ID<BR/>" + "The node ID is assigned by the controller and can not be changed.").withGroupName("thingcfg").build());
        return ConfigDescriptionBuilder.create(uri).withParameters(parameters).build();
    }
    ThingUID thingUID = new ThingUID(uri.getSchemeSpecificPart());
    Thing thing = getThing(thingUID);
    if (thing == null) {
        logger.debug("No thing found in getConfigDescription {}", uri);
        return null;
    }
    ThingUID bridgeUID = thing.getBridgeUID();
    if (bridgeUID == null) {
        logger.debug("No bridgeUID found in getConfigDescription {}", uri);
        return null;
    }
    // Get the controller for this thing
    Thing bridge = getThing(bridgeUID);
    if (bridge == null) {
        logger.debug("No bridge found in getConfigDescription {}", uri);
        return null;
    }
    final BigDecimal cfgNodeId = (BigDecimal) thing.getConfiguration().get(ZWaveBindingConstants.CONFIGURATION_NODEID);
    if (cfgNodeId == null) {
        logger.debug("No nodeId found in getConfigDescription {}", uri);
        return null;
    }
    int nodeId = cfgNodeId.intValue();
    // Get its handler and node
    ZWaveControllerHandler handler = (ZWaveControllerHandler) bridge.getHandler();
    if (handler == null) {
        logger.debug("NODE {}: No bridge handler found in getConfigDescription", nodeId);
        return null;
    }
    ZWaveNode node = handler.getNode(nodeId);
    if (node == null) {
        logger.debug("NODE {}: Node not found in getConfigDescription", nodeId);
        return null;
    }
    List<ConfigDescriptionParameterGroup> groups = new ArrayList<ConfigDescriptionParameterGroup>();
    groups.add(ConfigDescriptionParameterGroupBuilder.create("actions").withLabel("Actions").withDescription("Actions").build());
    groups.add(ConfigDescriptionParameterGroupBuilder.create("thingcfg").withContext("home").withLabel("Device Configuration").withDescription("Device Configuration").build());
    List<ParameterOption> options = new ArrayList<ParameterOption>();
    options.add(new ParameterOption("600", "10 Minutes"));
    options.add(new ParameterOption("1800", "30 Minutes"));
    options.add(new ParameterOption("3600", "1 Hour"));
    options.add(new ParameterOption("7200", "2 Hours"));
    options.add(new ParameterOption("10800", "3 Hours"));
    options.add(new ParameterOption("21600", "6 Hours"));
    options.add(new ParameterOption("43200", "12 Hours"));
    options.add(new ParameterOption("86400", "1 Day"));
    options.add(new ParameterOption("172800", "2 Days"));
    options.add(new ParameterOption("864000", "10 Days"));
    parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_POLLPERIOD, Type.INTEGER).withLabel(ZWaveBindingConstants.CONFIG_BINDING_POLLINGPERIOD_LABEL).withDescription(ZWaveBindingConstants.CONFIG_BINDING_POLLINGPERIOD_DESC).withDefault("86400").withMinimum(new BigDecimal(15)).withMaximum(new BigDecimal(864000)).withOptions(options).withLimitToOptions(false).withGroupName("thingcfg").build());
    options = new ArrayList<ParameterOption>();
    options.add(new ParameterOption("0", "Disabled"));
    parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_CMDREPOLLPERIOD, Type.INTEGER).withLabel(ZWaveBindingConstants.CONFIG_BINDING_CMDREPOLLPERIOD_LABEL).withDescription(ZWaveBindingConstants.CONFIG_BINDING_CMDREPOLLPERIOD_DESC).withDefault("1500").withMinimum(new BigDecimal(100)).withMaximum(new BigDecimal(15000)).withOptions(options).withLimitToOptions(false).withGroupName("thingcfg").build());
    // If we support the wakeup class, then add the configuration
    ZWaveWakeUpCommandClass wakeupCmdClass = (ZWaveWakeUpCommandClass) node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_WAKE_UP);
    if (wakeupCmdClass != null) {
        groups.add(ConfigDescriptionParameterGroupBuilder.create("wakeup").withContext("sleep").withLabel("Wakeup Configuration").withDescription("Configuration for wakeup parameters on battery devices").build());
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_WAKEUPINTERVAL, Type.INTEGER).withLabel("Wakeup Interval").withMinimum(new BigDecimal(wakeupCmdClass.getMinInterval())).withMaximum(new BigDecimal(wakeupCmdClass.getMaxInterval())).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.").withGroupName("wakeup").build());
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_WAKEUPNODE, Type.INTEGER).withLabel("Wakeup Node").withAdvanced(true).withMinimum(new BigDecimal(1)).withMaximum(new BigDecimal(232)).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.").withGroupName("wakeup").build());
    }
    // If we support the node name class, then add the configuration
    if (node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_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").build());
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_NODELOCATION, Type.TEXT).withDescription("Sets a string for the device location").withLabel("Node Location").withGroupName("thingcfg").build());
    }
    // If we support the switch_all class, then add the configuration
    if (node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_SWITCH_ALL) != null) {
        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.INTEGER).withLabel("Switch All Mode").withDescription("Set the mode for the switch when receiving SWITCH ALL commands.").withDefault("0").withGroupName("thingcfg").withOptions(options).withLimitToOptions(true).build());
    }
    // If we support DOOR_LOCK - add options
    if (node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_DOOR_LOCK) != null) {
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_DOORLOCKTIMEOUT, Type.INTEGER).withLabel("Lock Timeout").withDescription("Set the timeout on the lock.").withDefault("30").withGroupName("thingcfg").build());
    }
    ZWaveUserCodeCommandClass userCodeClass = (ZWaveUserCodeCommandClass) node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_USER_CODE);
    if (userCodeClass != null && userCodeClass.getNumberOfSupportedCodes() > 0) {
        groups.add(ConfigDescriptionParameterGroupBuilder.create("usercode").withContext("lock").withLabel("User Code").withDescription("Define the user codes for locks").build());
        for (int code = 1; code <= userCodeClass.getNumberOfSupportedCodes(); code++) {
            UserCode userCode = userCodeClass.getCachedUserCode(code);
            boolean readOnly = false;
            if (userCode != null) {
                readOnly = userCode.getState() == UserIdStatusType.RESERVED_BY_ADMINISTRATOR;
            }
            parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_USERCODE_LABEL + code, Type.TEXT).withLabel("Code " + code + " Label").withDescription("Name for user code " + code).withGroupName("usercode").build());
            parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_USERCODE_CODE + code, Type.TEXT).withLabel("Code " + code).withDescription("Set the user code (4 to 10 numbers)").withReadOnly(readOnly).withGroupName("usercode").build());
        }
    }
    // If we're FAILED, allow removing from the controller
    // if (node.getNodeState() == ZWaveNodeState.FAILED) {
    parameters.add(ConfigDescriptionParameterBuilder.create("action_remove", Type.BOOLEAN).withLabel("Remove device from controller").withAdvanced(true).withOptions(options).withDefault("false").withGroupName("actions").build());
    // } else {
    // Otherwise, allow us to put this on the failed list
    parameters.add(ConfigDescriptionParameterBuilder.create("action_failed", Type.BOOLEAN).withLabel("Set device as FAILed").withAdvanced(true).withOptions(options).withDefault("false").withGroupName("actions").build());
    if (node.isInitializationComplete() == true) {
        parameters.add(ConfigDescriptionParameterBuilder.create("action_reinit", Type.BOOLEAN).withLabel("Reinitialise the device").withAdvanced(true).withOptions(options).withDefault("false").withGroupName("actions").build());
    }
    parameters.add(ConfigDescriptionParameterBuilder.create("action_heal", Type.BOOLEAN).withLabel("Heal the device").withAdvanced(true).withOptions(options).withDefault("false").withGroupName("actions").build());
    return ConfigDescriptionBuilder.create(uri).withParameters(parameters).withParameterGroups(groups).build();
}
Also used : ZWaveUserCodeCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveUserCodeCommandClass) ArrayList(java.util.ArrayList) UserCode(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveUserCodeCommandClass.UserCode) BigDecimal(java.math.BigDecimal) ZWaveEndpoint(org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass) ConfigDescriptionParameterGroup(org.openhab.core.config.core.ConfigDescriptionParameterGroup) ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ParameterOption(org.openhab.core.config.core.ParameterOption) ThingUID(org.openhab.core.thing.ThingUID) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Thing(org.openhab.core.thing.Thing) ZWaveControllerHandler(org.openhab.binding.zwave.handler.ZWaveControllerHandler)

Example 2 with Thing

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

the class ZWaveThingHandlerTest method doConfigurationUpdate.

private ZWaveThingHandler doConfigurationUpdate(String param, Object value) {
    ThingType thingType = ThingTypeBuilder.instance("bindingId", "thingTypeId", "label").build();
    Thing thing = ThingBuilder.create(thingType.getUID(), new ThingUID(thingType.getUID(), "thingId")).withConfiguration(new Configuration()).build();
    ZWaveNode node = Mockito.mock(ZWaveNode.class);
    ZWaveController controller = Mockito.mock(ZWaveController.class);
    ZWaveControllerHandler controllerHandler = Mockito.mock(ZWaveControllerHandler.class);
    Mockito.when(controllerHandler.isControllerMaster()).thenReturn(false);
    ThingHandlerCallback thingCallback = Mockito.mock(ThingHandlerCallback.class);
    ZWaveThingHandler thingHandler = new ZWaveThingHandlerForTest(thing);
    thingHandler.setCallback(thingCallback);
    payloadCaptor = ArgumentCaptor.forClass(ZWaveCommandClassTransactionPayload.class);
    Field fieldControllerHandler;
    try {
        ZWaveWakeUpCommandClass wakeupClass = new ZWaveWakeUpCommandClass(node, controller, null);
        ZWaveAssociationCommandClass associationClass = new ZWaveAssociationCommandClass(node, controller, null);
        ZWaveNodeNamingCommandClass namingClass = new ZWaveNodeNamingCommandClass(node, controller, null);
        Mockito.doNothing().when(node).sendMessage(payloadCaptor.capture());
        fieldControllerHandler = ZWaveThingHandler.class.getDeclaredField("controllerHandler");
        fieldControllerHandler.setAccessible(true);
        fieldControllerHandler.set(thingHandler, controllerHandler);
        Mockito.when(controller.getOwnNodeId()).thenReturn(1);
        Mockito.when(controllerHandler.getOwnNodeId()).thenReturn(1);
        Mockito.when(controllerHandler.getNode(ArgumentMatchers.anyInt())).thenReturn(node);
        Mockito.when(node.getNodeId()).thenReturn(1);
        Mockito.when(node.getAssociationGroup(ArgumentMatchers.anyInt())).thenReturn(new ZWaveAssociationGroup(1));
        Mockito.when(node.getCommandClass(ArgumentMatchers.eq(CommandClass.COMMAND_CLASS_WAKE_UP))).thenReturn(wakeupClass);
        Mockito.when(node.getCommandClass(ArgumentMatchers.eq(CommandClass.COMMAND_CLASS_ASSOCIATION))).thenReturn(associationClass);
        Mockito.when(node.getCommandClass(ArgumentMatchers.eq(CommandClass.COMMAND_CLASS_NODE_NAMING))).thenReturn(namingClass);
    } catch (NoSuchFieldException | SecurityException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(param, value);
    thingHandler.handleConfigurationUpdate(config);
    configResult = thingHandler.getThing().getConfiguration();
    return thingHandler;
}
Also used : Configuration(org.openhab.core.config.core.Configuration) HashMap(java.util.HashMap) ThingHandlerCallback(org.openhab.core.thing.binding.ThingHandlerCallback) ThingType(org.openhab.core.thing.type.ThingType) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass) ZWaveAssociationCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass) Field(java.lang.reflect.Field) Thing(org.openhab.core.thing.Thing) ZWaveAssociationGroup(org.openhab.binding.zwave.internal.protocol.ZWaveAssociationGroup) ZWaveNodeNamingCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveNodeNamingCommandClass) ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ZWaveCommandClassTransactionPayload(org.openhab.binding.zwave.internal.protocol.transaction.ZWaveCommandClassTransactionPayload) ThingUID(org.openhab.core.thing.ThingUID) ZWaveController(org.openhab.binding.zwave.internal.protocol.ZWaveController)

Example 3 with Thing

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

the class ADBridgeHandler method notifyChildHandlersPanelReady.

/**
 * Notify child thing handlers that the alarm panel is in the ready state. Since there is no way to poll, all
 * contact channels are initialized into the UNDEF state. This method is called when there is reason to assume that
 * there are no faulted zones, because the alarm panel is in state READY. Zone handlers that have not yet received
 * updates can then set their contact states to CLOSED. Only executes the first time panel is ready after bridge
 * connect/reconnect.
 */
private void notifyChildHandlersPanelReady() {
    if (!panelReadyReceived) {
        panelReadyReceived = true;
        logger.trace("Notifying child handlers that panel is in ready state");
        // Notify child zone handlers by calling notifyPanelReady() for each
        for (Thing thing : getThing().getThings()) {
            ADThingHandler handler = (ADThingHandler) thing.getHandler();
            if (handler != null) {
                handler.notifyPanelReady();
            }
        }
    }
}
Also used : Thing(org.openhab.core.thing.Thing)

Example 4 with Thing

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

the class Cm11aBridgeHandler method receivedX10Data.

/*
     * (non-Javadoc)
     *
     * @see org.openhab.binding.cm11a.handler.ReceivedDataListener#receivedX10Data(org.openhab.binding.cm11a.internal.
     * X10ReceivedData)
     */
@Override
public void receivedX10Data(X10ReceivedData rd) {
    logger.debug("Cm11aReceivedDataManager received the following data: {}", rd);
    List<Thing> things = bridge.getThings();
    // which is the one that should be updated.
    synchronized (rd) {
        for (Thing thing : things) {
            String houseUnitCode = (String) thing.getConfiguration().get("houseUnitCode");
            for (String messageHouseUnitCode : rd.getAddr()) {
                if (messageHouseUnitCode.equals(houseUnitCode)) {
                    // The channel we want should end in "switchstatus" or "lightlevel". In reality there is
                    // probably only one channel since these things only define one channel
                    ChannelUID desiredChannelUid = findX10Channel(thing.getChannels());
                    if (desiredChannelUid == null) {
                        return;
                    }
                    X10COMMAND cmd = rd.getCmd();
                    int dims = rd.getDims();
                    updateX10State(thing, desiredChannelUid, cmd, dims);
                }
            }
        }
    }
}
Also used : X10COMMAND(org.openhab.binding.cm11a.internal.X10ReceivedData.X10COMMAND) ChannelUID(org.openhab.core.thing.ChannelUID) Thing(org.openhab.core.thing.Thing)

Example 5 with Thing

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

the class CBusLightHandler method updateGroup.

public void updateGroup(int updateApplicationId, int updateGroupId, String value) {
    if (updateGroupId == groupId && updateApplicationId == applicationId) {
        Thing thing = getThing();
        Channel channel = thing.getChannel(CBusBindingConstants.CHANNEL_STATE);
        Channel channelLevel = thing.getChannel(CBusBindingConstants.CHANNEL_LEVEL);
        if (channel != null && channelLevel != null) {
            ChannelUID channelUID = channel.getUID();
            ChannelUID channelLevelUID = channelLevel.getUID();
            logger.debug("channel UID {} level UID {}", channelUID, channelLevelUID);
            if ("on".equalsIgnoreCase(value) || "255".equalsIgnoreCase(value)) {
                updateState(channelUID, OnOffType.ON);
                updateState(channelLevelUID, new PercentType(100));
            } else if ("off".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) {
                updateState(channelUID, OnOffType.OFF);
                updateState(channelLevelUID, new PercentType(0));
            } else {
                try {
                    int v = Integer.parseInt(value);
                    updateState(channelUID, v > 0 ? OnOffType.ON : OnOffType.OFF);
                    updateState(channelLevelUID, new PercentType((int) (v * 100 / 255.0)));
                } catch (NumberFormatException e) {
                    logger.warn("Invalid value presented to channel {}. Received {}, expected On/Off", channelUID, value);
                }
            }
            logger.debug("Updating CBus Lighting Group {} with value {}", thing.getUID(), value);
        } else {
            logger.debug("Failed to Update CBus Lighting Group {} with value {}: No Channel", thing.getUID(), value);
        }
    }
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) PercentType(org.openhab.core.library.types.PercentType) Thing(org.openhab.core.thing.Thing)

Aggregations

Thing (org.openhab.core.thing.Thing)504 Test (org.junit.jupiter.api.Test)214 ThingUID (org.openhab.core.thing.ThingUID)154 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)127 ChannelUID (org.openhab.core.thing.ChannelUID)123 Configuration (org.openhab.core.config.core.Configuration)93 Nullable (org.eclipse.jdt.annotation.Nullable)89 ThingHandler (org.openhab.core.thing.binding.ThingHandler)89 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)75 Channel (org.openhab.core.thing.Channel)68 Bridge (org.openhab.core.thing.Bridge)66 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)54 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)50 HashMap (java.util.HashMap)45 ThingStatus (org.openhab.core.thing.ThingStatus)39 ArrayList (java.util.ArrayList)38 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)37 Command (org.openhab.core.types.Command)36 List (java.util.List)33 Map (java.util.Map)33