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);
}
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);
});
}
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;
}
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");
}
}
}
}
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);
}
Aggregations