Search in sources :

Example 21 with Configuration

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;
}
Also used : Configuration(org.openhab.core.config.core.Configuration)

Example 22 with Configuration

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.");
    }
}
Also used : OAuthResponseException(org.openhab.core.auth.client.oauth2.OAuthResponseException) Configuration(org.openhab.core.config.core.Configuration) HydrawiseAccountConfiguration(org.openhab.binding.hydrawise.internal.config.HydrawiseAccountConfiguration) OAuthException(org.openhab.core.auth.client.oauth2.OAuthException) IOException(java.io.IOException) HydrawiseAccountConfiguration(org.openhab.binding.hydrawise.internal.config.HydrawiseAccountConfiguration)

Example 23 with Configuration

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);
    }
}
Also used : Color(java.awt.Color) CommandUnsuccessfulException(org.openhab.binding.hyperion.internal.protocol.CommandUnsuccessfulException) ScheduledFuture(java.util.concurrent.ScheduledFuture) StringType(org.openhab.core.library.types.StringType) LoggerFactory(org.slf4j.LoggerFactory) OnOffType(org.openhab.core.library.types.OnOffType) ComponentStateCommand(org.openhab.binding.hyperion.internal.protocol.ng.ComponentStateCommand) BigDecimal(java.math.BigDecimal) Configuration(org.openhab.core.config.core.Configuration) Gson(com.google.gson.Gson) Priority(org.openhab.binding.hyperion.internal.protocol.ng.Priority) AdjustmentCommand(org.openhab.binding.hyperion.internal.protocol.ng.AdjustmentCommand) Effect(org.openhab.binding.hyperion.internal.protocol.v1.Effect) UnDefType(org.openhab.core.types.UnDefType) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) StateOption(org.openhab.core.types.StateOption) HyperionStateDescriptionProvider(org.openhab.binding.hyperion.internal.HyperionStateDescriptionProvider) JsonTcpConnection(org.openhab.binding.hyperion.internal.connection.JsonTcpConnection) HyperionCommand(org.openhab.binding.hyperion.internal.protocol.HyperionCommand) List(java.util.List) ServerInfoCommand(org.openhab.binding.hyperion.internal.protocol.ServerInfoCommand) ColorCommand(org.openhab.binding.hyperion.internal.protocol.ColorCommand) Optional(java.util.Optional) HSBType(org.openhab.core.library.types.HSBType) Value(org.openhab.binding.hyperion.internal.protocol.ng.Value) Component(org.openhab.binding.hyperion.internal.protocol.ng.Component) ClearCommand(org.openhab.binding.hyperion.internal.protocol.v1.ClearCommand) JsonParseException(com.google.gson.JsonParseException) ComponentState(org.openhab.binding.hyperion.internal.protocol.ng.ComponentState) Adjustment(org.openhab.binding.hyperion.internal.protocol.ng.Adjustment) HyperionBindingConstants(org.openhab.binding.hyperion.internal.HyperionBindingConstants) ArrayList(java.util.ArrayList) Thing(org.openhab.core.thing.Thing) EffectCommand(org.openhab.binding.hyperion.internal.protocol.EffectCommand) ChannelUID(org.openhab.core.thing.ChannelUID) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) NgResponse(org.openhab.binding.hyperion.internal.protocol.ng.NgResponse) NgInfo(org.openhab.binding.hyperion.internal.protocol.ng.NgInfo) ThingStatus(org.openhab.core.thing.ThingStatus) Command(org.openhab.core.types.Command) Logger(org.slf4j.Logger) RefreshType(org.openhab.core.types.RefreshType) IOException(java.io.IOException) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) UnknownHostException(java.net.UnknownHostException) ClearAllCommand(org.openhab.binding.hyperion.internal.protocol.v1.ClearAllCommand) TimeUnit(java.util.concurrent.TimeUnit) PercentType(org.openhab.core.library.types.PercentType) Hyperion(org.openhab.binding.hyperion.internal.protocol.ng.Hyperion) StringType(org.openhab.core.library.types.StringType) Priority(org.openhab.binding.hyperion.internal.protocol.ng.Priority) Value(org.openhab.binding.hyperion.internal.protocol.ng.Value) HSBType(org.openhab.core.library.types.HSBType)

Example 24 with Configuration

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);
                }
            }
        }
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) SmartherGatewayException(org.openhab.binding.bticinosmarther.internal.api.exception.SmartherGatewayException) LoggerFactory(org.slf4j.LoggerFactory) OnOffType(org.openhab.core.library.types.OnOffType) Plant(org.openhab.binding.bticinosmarther.internal.api.dto.Plant) Program(org.openhab.binding.bticinosmarther.internal.api.dto.Program) StringUtil(org.openhab.binding.bticinosmarther.internal.util.StringUtil) InetAddress(java.net.InetAddress) HttpClient(org.eclipse.jetty.client.HttpClient) Location(org.openhab.binding.bticinosmarther.internal.api.dto.Location) Future(java.util.concurrent.Future) AccessTokenRefreshListener(org.openhab.core.auth.client.oauth2.AccessTokenRefreshListener) Nullable(org.eclipse.jdt.annotation.Nullable) Configuration(org.openhab.core.config.core.Configuration) Duration(java.time.Duration) Subscription(org.openhab.binding.bticinosmarther.internal.api.dto.Subscription) URI(java.net.URI) Notification(org.openhab.binding.bticinosmarther.internal.api.dto.Notification) SmartherNotificationHandler(org.openhab.binding.bticinosmarther.internal.account.SmartherNotificationHandler) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) SmartherBindingConstants(org.openhab.binding.bticinosmarther.internal.SmartherBindingConstants) ModuleStatus(org.openhab.binding.bticinosmarther.internal.api.dto.ModuleStatus) OAuthResponseException(org.openhab.core.auth.client.oauth2.OAuthResponseException) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Channel(org.openhab.core.thing.Channel) List(java.util.List) SmartherAuthorizationException(org.openhab.binding.bticinosmarther.internal.api.exception.SmartherAuthorizationException) SmartherBridgeConfiguration(org.openhab.binding.bticinosmarther.internal.config.SmartherBridgeConfiguration) Optional(java.util.Optional) BaseBridgeHandler(org.openhab.core.thing.binding.BaseBridgeHandler) ExpiringCache(org.openhab.core.cache.ExpiringCache) BridgeStatus(org.openhab.binding.bticinosmarther.internal.model.BridgeStatus) OAuthException(org.openhab.core.auth.client.oauth2.OAuthException) ThingHandlerService(org.openhab.core.thing.binding.ThingHandlerService) SmartherAccountHandler(org.openhab.binding.bticinosmarther.internal.account.SmartherAccountHandler) ArrayList(java.util.ArrayList) SmartherApi(org.openhab.binding.bticinosmarther.internal.api.SmartherApi) ModuleSettings(org.openhab.binding.bticinosmarther.internal.model.ModuleSettings) ChannelUID(org.openhab.core.thing.ChannelUID) DecimalType(org.openhab.core.library.types.DecimalType) ThingStatus(org.openhab.core.thing.ThingStatus) Command(org.openhab.core.types.Command) Logger(org.slf4j.Logger) ThingUID(org.openhab.core.thing.ThingUID) State(org.openhab.core.types.State) RefreshType(org.openhab.core.types.RefreshType) IOException(java.io.IOException) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) UnknownHostException(java.net.UnknownHostException) TimeUnit(java.util.concurrent.TimeUnit) SmartherModuleDiscoveryService(org.openhab.binding.bticinosmarther.internal.discovery.SmartherModuleDiscoveryService) Sender(org.openhab.binding.bticinosmarther.internal.api.dto.Sender) AccessTokenResponse(org.openhab.core.auth.client.oauth2.AccessTokenResponse) OAuthClientService(org.openhab.core.auth.client.oauth2.OAuthClientService) Module(org.openhab.binding.bticinosmarther.internal.api.dto.Module) OAuthFactory(org.openhab.core.auth.client.oauth2.OAuthFactory) Collections(java.util.Collections) Bridge(org.openhab.core.thing.Bridge) Configuration(org.openhab.core.config.core.Configuration) SmartherBridgeConfiguration(org.openhab.binding.bticinosmarther.internal.config.SmartherBridgeConfiguration) List(java.util.List) ArrayList(java.util.ArrayList) Location(org.openhab.binding.bticinosmarther.internal.api.dto.Location)

Example 25 with Configuration

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);
        }
    }
}
Also used : Configuration(org.openhab.core.config.core.Configuration) SmartherBridgeConfiguration(org.openhab.binding.bticinosmarther.internal.config.SmartherBridgeConfiguration) Subscription(org.openhab.binding.bticinosmarther.internal.api.dto.Subscription)

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