use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class DeutscheBahnTrainHandlerTest method createConfig.
private static Configuration createConfig(int position) {
final Configuration config = new Configuration();
config.put("position", String.valueOf(position));
return config;
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class HydrawiseAccountHandler method configure.
private void configure() {
HydrawiseAccountConfiguration config = getConfig().as(HydrawiseAccountConfiguration.class);
try {
if (!config.userName.isEmpty() && !config.password.isEmpty()) {
if (!config.savePassword) {
Configuration editedConfig = editConfiguration();
editedConfig.remove("password");
updateConfiguration(editedConfig);
}
oAuthService.getAccessTokenByResourceOwnerPasswordCredentials(config.userName, config.password, SCOPE);
} else if (oAuthService.getAccessTokenResponse() == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Login credentials required.");
return;
}
this.refresh = Math.max(config.refreshInterval, MIN_REFRESH_SECONDS);
initPolling(0, refresh);
} catch (OAuthException | IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} catch (OAuthResponseException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Login credentials required.");
}
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class HyperionNgHandler method updatePriorities.
private void updatePriorities(List<Priority> priorities) {
populateClearPriorities(priorities);
String regex = origin + ".*";
// update color
// find the color priority that has the same origin specified in the Thing configuration
Optional<Priority> colorPriority = // convert list to stream
priorities.stream().filter(priority -> COLOR_PRIORITY.equals(priority.getComponentId()) && priority.getOrigin().matches(regex)).findFirst();
// if there is no color priority for the openHAB origin then set channel to NULL
if (colorPriority.isPresent()) {
Value value = colorPriority.get().getValue();
List<Integer> rgbVals = value.getRGB();
int r = rgbVals.get(0);
int g = rgbVals.get(1);
int b = rgbVals.get(2);
HSBType hsbType = HSBType.fromRGB(r, g, b);
updateState(CHANNEL_COLOR, hsbType);
} else {
updateState(CHANNEL_COLOR, UnDefType.NULL);
}
// update effect
// find the color priority that has the same origin specified in the Thing configuration
Optional<Priority> effectPriority = // convert list to stream
priorities.stream().filter(priority -> EFFECT_PRIORITY.equals(priority.getComponentId()) && priority.getOrigin().matches(regex)).findFirst();
// if there is no effect priority for the openHAB origin then set channel to NULL
if (effectPriority.isPresent()) {
String effectString = effectPriority.get().getOwner();
StringType effect = new StringType(effectString);
updateState(CHANNEL_EFFECT, effect);
} else {
updateState(CHANNEL_EFFECT, UnDefType.NULL);
}
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class SmartherBridgeHandler method unregisterNotification.
@Override
public synchronized void unregisterNotification(String plantId) throws SmartherGatewayException {
if (!config.isUseNotifications()) {
return;
}
final ExpiringCache<List<Location>> localLocationCache = this.locationCache;
if (localLocationCache != null) {
List<Location> locations = localLocationCache.getValue();
final long remainingModules = getThing().getThings().stream().map(t -> (SmartherModuleHandler) t.getHandler()).filter(h -> h.getPlantId().equals(plantId)).count();
if (locations != null && remainingModules == 0) {
final Optional<Location> maybeLocation = locations.stream().filter(l -> l.getPlantId().equals(plantId)).findFirst();
if (maybeLocation.isPresent()) {
Location location = maybeLocation.get();
final String subscriptionId = location.getSubscriptionId();
if (location.hasSubscription() && (subscriptionId != null)) {
// Call gateway to unregister plant subscription
unsubscribePlant(plantId, subscriptionId);
logger.debug("Bridge[{}] Notification unregistered: [plantId={}, subscriptionId={}]", thing.getUID(), plantId, subscriptionId);
// Remove the subscription from notifications list
List<String> notifications = config.removeNotification(subscriptionId);
// Save the updated notifications list back to bridge config
Configuration configuration = editConfiguration();
configuration.put(PROPERTY_NOTIFICATIONS, notifications);
updateConfiguration(configuration);
// Update the local locationCache with the removed data
locations.stream().forEach(l -> {
if (l.getPlantId().equals(plantId)) {
l.unsetSubscription();
}
});
localLocationCache.putValue(locations);
}
}
}
}
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class SmartherBridgeHandler method updateNotifications.
/**
* Updates this Bridge local notifications list with externally registered subscriptions.
*
* @param subscriptions
* the externally registered subscriptions to be added to the local notifications list
*/
private void updateNotifications(List<Subscription> subscriptions) {
// Get the notifications list from bridge config
List<String> notifications = config.getNotifications();
for (Subscription s : subscriptions) {
if (s.getEndpointUrl().equalsIgnoreCase(config.getNotificationUrl()) && !notifications.contains(s.getSubscriptionId())) {
// Add the external subscription to notifications list
notifications = config.addNotification(s.getSubscriptionId());
// Save the updated notifications list back to bridge config
Configuration configuration = editConfiguration();
configuration.put(PROPERTY_NOTIFICATIONS, notifications);
updateConfiguration(configuration);
}
}
}
Aggregations