Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accepted types to ProfileContext #2814

Merged
merged 2 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,40 @@
*/
package org.openhab.core.thing.internal;

import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.profiles.ProfileContext;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;

/**
* {@link ProfileContext} implementation.
*
* @author Simon Kaufmann - Initial contribution
* @author Jan N. Klug - Add accepted type methods
*/
@NonNullByDefault
public class ProfileContextImpl implements ProfileContext {

private static final String THREAD_POOL_NAME = "profiles";
private final Configuration configuration;

private final List<Class<? extends State>> acceptedDataTypes;
private final List<Class<? extends Command>> acceptedCommandTypes;

public ProfileContextImpl(Configuration configuration) {
this(configuration, List.of(), List.of());
}

public ProfileContextImpl(Configuration configuration, List<Class<? extends State>> acceptedDataTypes,
List<Class<? extends Command>> acceptedCommandTypes) {
this.configuration = configuration;
this.acceptedDataTypes = acceptedDataTypes;
this.acceptedCommandTypes = acceptedCommandTypes;
}

@Override
Expand All @@ -43,4 +57,14 @@ public Configuration getConfiguration() {
public ScheduledExecutorService getExecutorService() {
return ThreadPoolManager.getScheduledPool(THREAD_POOL_NAME);
}

@Override
public List<Class<? extends State>> getAcceptedDataTypes() {
return acceptedDataTypes;
}

@Override
public List<Class<? extends Command>> getAcceptedCommandTypes() {
return acceptedCommandTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
*/
package org.openhab.core.thing.profiles;

import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;

/**
* The profile's context
*
* It gives access to related information like the profile's configuration or a scheduler.
*
* @author Simon Kaufmann - Initial contribution
* @author Jan N. Klug - Add accepted type methods
*/
@NonNullByDefault
public interface ProfileContext {
Expand All @@ -40,4 +44,26 @@ public interface ProfileContext {
* @return the scheduler
*/
ScheduledExecutorService getExecutorService();

/**
* Get the list of accepted data types for state updates to the linked item
*
* This is an optional method and will return an empty list if not implemented.
*
* @return A list of all accepted data types
*/
default List<Class<? extends State>> getAcceptedDataTypes() {
return List.of();
}

/**
* Get the list of accepted command types for commands send to the linked item
*
* This is an optional method and will return an empty list if not implemented.
*
* @return A list of all accepted command types
*/
default List<Class<? extends Command>> getAcceptedCommandTypes() {
return List.of();
}
}