use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class HomeConnectBridgeHandler method handleConfigurationUpdate.
@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) {
if (isModifyingCurrentConfig(configurationParameters)) {
List<String> parameters = configurationParameters.entrySet().stream().map((entry) -> {
if (CLIENT_ID.equals(entry.getKey()) || CLIENT_SECRET.equals(entry.getKey())) {
return entry.getKey() + ": ***";
}
return entry.getKey() + ": " + entry.getValue();
}).collect(Collectors.toList());
logger.debug("Update bridge configuration. bridge={}, parameters={}", getThing().getLabel(), parameters);
validateConfigurationParameters(configurationParameters);
Configuration configuration = editConfiguration();
for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
configuration.put(configurationParameter.getKey(), configurationParameter.getValue());
}
// invalidate oAuth credentials
try {
logger.debug("Clear oAuth credential store. bridge={}", getThing().getLabel());
var oAuthClientService = this.oAuthClientService;
if (oAuthClientService != null) {
oAuthClientService.remove();
}
} catch (OAuthException e) {
logger.error("Could not clear oAuth credentials. bridge={}", getThing().getLabel(), e);
}
if (isInitialized()) {
// persist new configuration and reinitialize handler
dispose();
updateConfiguration(configuration);
initialize();
} else {
// persist new configuration and notify Thing Manager
updateConfiguration(configuration);
@Nullable ThingHandlerCallback callback = getCallback();
if (callback != null) {
callback.configurationUpdated(this.getThing());
} else {
logger.warn("Handler {} tried updating its configuration although the handler was already disposed.", this.getClass().getSimpleName());
}
}
}
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class LGWebOSHandler method findMacAddress.
/**
* Make a best effort to automatically detect the MAC address of the TV.
* If this does not work automatically, users can still set it manually in the Thing config.
*/
private void findMacAddress() {
LGWebOSConfiguration c = getLGWebOSConfig();
String host = c.getHost();
if (!host.isEmpty()) {
try {
// validate host, so that no command can be injected
String macAddress = WakeOnLanUtility.getMACAddress(InetAddress.getByName(host).getHostAddress());
if (macAddress != null && !macAddress.equals(c.macAddress)) {
c.macAddress = macAddress;
// persist the configuration change
Configuration configuration = editConfiguration();
configuration.put(LGWebOSBindingConstants.CONFIG_MAC_ADDRESS, macAddress);
updateConfiguration(configuration);
}
} catch (UnknownHostException e) {
logger.debug("Unable to determine MAC address: {}", e.getMessage());
}
}
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class LGWebOSHandler method storeKey.
@Override
public void storeKey(@Nullable String key) {
if (!getKey().equals(key)) {
logger.debug("Store new access Key in the thing configuration");
// store it current configuration and avoiding complete re-initialization via handleConfigurationUpdate
getLGWebOSConfig().key = key;
// persist the configuration change
Configuration configuration = editConfiguration();
configuration.put(LGWebOSBindingConstants.CONFIG_KEY, key);
updateConfiguration(configuration);
}
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class FSInternetRadioHandlerJavaTest method offlineIfEmptyPIN.
/**
* Verify OFFLINE Thing status when the PIN is empty String.
*/
@Test
public void offlineIfEmptyPIN() {
Configuration config = createConfiguration(DEFAULT_CONFIG_PROPERTY_IP, "", String.valueOf(DEFAULT_CONFIG_PROPERTY_PORT), DEFAULT_CONFIG_PROPERTY_REFRESH);
Thing radioThingWithEmptyPIN = initializeRadioThing(config);
testRadioThingConsideringConfiguration(radioThingWithEmptyPIN);
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class Ipx800v3Handler method dataReceived.
@Override
public void dataReceived(String port, double value) {
updateStatus(ThingStatus.ONLINE);
Channel channel = thing.getChannel(PortDefinition.asChannelId(port));
if (channel != null) {
String channelId = channel.getUID().getId();
String groupId = channel.getUID().getGroupId();
PortData portData = portDatas.get(channelId);
if (portData != null && groupId != null) {
ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault());
long sinceLastChange = Duration.between(portData.getTimestamp(), now).toMillis();
Configuration configuration = channel.getConfiguration();
PortDefinition portDefinition = PortDefinition.fromGroupId(groupId);
if (ignoreCondition(value, portData, configuration, portDefinition, now)) {
logger.debug("Ignore condition met for port '{}' with data '{}'", port, value);
return;
}
logger.debug("About to update port '{}' with data '{}'", port, value);
State state = UnDefType.UNDEF;
switch(portDefinition) {
case COUNTER:
state = new DecimalType(value);
break;
case RELAY:
state = value == 1 ? OnOffType.ON : OnOffType.OFF;
break;
case ANALOG:
state = new DecimalType(value);
updateState(channelId + PROPERTY_SEPARATOR + CHANNEL_VOLTAGE, new QuantityType<>(value * ANALOG_SAMPLING, Units.VOLT));
break;
case CONTACT:
DigitalInputConfiguration config = configuration.as(DigitalInputConfiguration.class);
portData.cancelPulsing();
state = value == 1 ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
switch((OpenClosedType) state) {
case CLOSED:
if (config.longPressTime != 0 && !portData.isInitializing()) {
scheduler.schedule(new LongPressEvaluator(channel, port, portData), config.longPressTime, TimeUnit.MILLISECONDS);
} else if (config.pulsePeriod != 0) {
portData.setPulsing(scheduler.scheduleWithFixedDelay(() -> {
triggerPushButtonChannel(channel, EVENT_PULSE);
}, config.pulsePeriod, config.pulsePeriod, TimeUnit.MILLISECONDS));
if (config.pulseTimeout != 0) {
scheduler.schedule(portData::cancelPulsing, config.pulseTimeout, TimeUnit.MILLISECONDS);
}
}
break;
case OPEN:
if (!portData.isInitializing() && config.longPressTime != 0 && sinceLastChange < config.longPressTime) {
triggerPushButtonChannel(channel, EVENT_SHORT_PRESS);
}
break;
}
if (!portData.isInitializing()) {
triggerPushButtonChannel(channel, value == 1 ? EVENT_PRESSED : EVENT_RELEASED);
}
break;
}
updateState(channelId, state);
if (!portData.isInitializing()) {
updateState(channelId + PROPERTY_SEPARATOR + CHANNEL_LAST_STATE_DURATION, new QuantityType<>(sinceLastChange / 1000, Units.SECOND));
}
portData.setData(value, now);
} else {
logger.debug("Received data '{}' for not configured port '{}'", value, port);
}
} else {
logger.debug("Received data '{}' for not configured channel '{}'", value, port);
}
}
Aggregations