Search in sources :

Example 16 with Configuration

use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.

the class FSInternetRadioHandlerJavaTest method offlineIfNullIp.

/**
 * Verify OFFLINE Thing status when the IP is NULL.
 */
@Test
public void offlineIfNullIp() {
    Configuration config = createConfiguration(null, DEFAULT_CONFIG_PROPERTY_PIN, String.valueOf(DEFAULT_CONFIG_PROPERTY_PORT), DEFAULT_CONFIG_PROPERTY_REFRESH);
    Thing radioThingWithNullIP = initializeRadioThing(config);
    testRadioThingConsideringConfiguration(radioThingWithNullIP);
}
Also used : Configuration(org.openhab.core.config.core.Configuration) Thing(org.openhab.core.thing.Thing) Test(org.junit.jupiter.api.Test) JavaTest(org.openhab.core.test.java.JavaTest)

Example 17 with Configuration

use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.

the class FSInternetRadioHandlerJavaTest method offlineIfWrongPIN.

/**
 * Verify OFFLINE Thing status when the PIN is wrong.
 */
@Test
public void offlineIfWrongPIN() {
    final String wrongPin = "5678";
    Configuration config = createConfiguration(DEFAULT_CONFIG_PROPERTY_IP, wrongPin, String.valueOf(DEFAULT_CONFIG_PROPERTY_PORT), DEFAULT_CONFIG_PROPERTY_REFRESH);
    initializeRadioThing(config);
    waitForAssert(() -> {
        String exceptionMessage = "Radio does not allow connection, maybe wrong pin?";
        verifyCommunicationError(exceptionMessage);
    });
}
Also used : Configuration(org.openhab.core.config.core.Configuration) Test(org.junit.jupiter.api.Test) JavaTest(org.openhab.core.test.java.JavaTest)

Example 18 with Configuration

use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.

the class FSInternetRadioHandlerJavaTest method createConfiguration.

private static Configuration createConfiguration(String ip, String pin, String port, String refresh) {
    Configuration config = new Configuration();
    config.put(FSInternetRadioBindingConstants.CONFIG_PROPERTY_IP, ip);
    config.put(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PIN, pin);
    config.put(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PORT, new BigDecimal(port));
    config.put(FSInternetRadioBindingConstants.CONFIG_PROPERTY_REFRESH, new BigDecimal(refresh));
    return config;
}
Also used : Configuration(org.openhab.core.config.core.Configuration) BigDecimal(java.math.BigDecimal)

Example 19 with Configuration

use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.

the class EthernetBridgeHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (!(command instanceof RefreshType)) {
        Channel channel = this.getThing().getChannel(channelUID.getId());
        if (channel != null) {
            Configuration channelConfiguration = channel.getConfiguration();
            if (channel.getChannelTypeUID() != null && channel.getChannelTypeUID().getId().equals(IRtransBindingConstants.BLASTER_CHANNEL_TYPE)) {
                if (command instanceof StringType) {
                    String remoteName = StringUtils.substringBefore(command.toString(), ",");
                    String irCommandName = StringUtils.substringAfter(command.toString(), ",");
                    IrCommand ircommand = new IrCommand();
                    ircommand.setRemote(remoteName);
                    ircommand.setCommand(irCommandName);
                    IrCommand thingCompatibleCommand = new IrCommand();
                    thingCompatibleCommand.setRemote((String) channelConfiguration.get(REMOTE));
                    thingCompatibleCommand.setCommand((String) channelConfiguration.get(COMMAND));
                    if (ircommand.matches(thingCompatibleCommand)) {
                        if (sendIRcommand(ircommand, Led.get((String) channelConfiguration.get(LED)))) {
                            logger.debug("Sent a matching infrared command '{}' for channel '{}'", command, channelUID);
                        } else {
                            logger.warn("An error occured whilst sending the infrared command '{}' for Channel '{}'", command, channelUID);
                        }
                    }
                }
            }
            if (channel.getAcceptedItemType() != null && channel.getAcceptedItemType().equals(IRtransBindingConstants.RECEIVER_CHANNEL_TYPE)) {
                logger.warn("Receivers can only receive infrared commands, not send them");
            }
        }
    }
}
Also used : Configuration(org.openhab.core.config.core.Configuration) StringType(org.openhab.core.library.types.StringType) SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) Channel(org.openhab.core.thing.Channel) IrCommand(org.openhab.binding.irtrans.internal.IrCommand) RefreshType(org.openhab.core.types.RefreshType)

Example 20 with Configuration

use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.

the class IppPrinterHandler method initialize.

@Override
public void initialize() {
    Configuration config = getThing().getConfiguration();
    String name = (String) config.get(PRINTER_PARAMETER_NAME);
    try {
        Object obj = config.get(PRINTER_PARAMETER_URL);
        if (obj instanceof URL) {
            url = (URL) obj;
        } else if (obj instanceof String) {
            url = new URL((String) obj);
        }
        printer = new CupsPrinter(url, name, false);
    } catch (MalformedURLException e) {
        logger.error("malformed url {}, printer thing creation failed", config.get(PRINTER_PARAMETER_URL));
    }
    int refresh = DEFAULT_REFRESH_INTERVAL_IN_SECONDS;
    Object obj = config.get(PRINTER_PARAMETER_REFRESH_INTERVAL);
    if (obj != null) {
        BigDecimal ref = (BigDecimal) obj;
        refresh = ref.intValue();
    }
    updateStatus(ThingStatus.UNKNOWN);
    deviceOnlineWatchdog(refresh);
    discoveryServiceRegistry.addDiscoveryListener(this);
}
Also used : MalformedURLException(java.net.MalformedURLException) Configuration(org.openhab.core.config.core.Configuration) CupsPrinter(org.cups4j.CupsPrinter) URL(java.net.URL) BigDecimal(java.math.BigDecimal)

Aggregations

Configuration (org.openhab.core.config.core.Configuration)498 Test (org.junit.jupiter.api.Test)193 Thing (org.openhab.core.thing.Thing)97 Channel (org.openhab.core.thing.Channel)62 HashMap (java.util.HashMap)60 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)59 ChannelUID (org.openhab.core.thing.ChannelUID)50 ThingUID (org.openhab.core.thing.ThingUID)50 Bridge (org.openhab.core.thing.Bridge)49 Nullable (org.eclipse.jdt.annotation.Nullable)39 BeforeEach (org.junit.jupiter.api.BeforeEach)39 BigDecimal (java.math.BigDecimal)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 IOException (java.io.IOException)31 ArrayList (java.util.ArrayList)26 Rule (org.openhab.core.automation.Rule)24 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)24 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)22 Action (org.openhab.core.automation.Action)19 Condition (org.openhab.core.automation.Condition)19