Skip to content

Commit

Permalink
Allow profiles to access the entire context of the link they're appli…
Browse files Browse the repository at this point in the history
…ed to

So that they can vary their processing based on the item or channeluid itself,
instead of (or in addition to) solely on the prior states passing through it.

Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer committed Nov 7, 2022
1 parent 2bceba6 commit e8f3d3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ private String normalizeProfileName(String profileName) {
if (item != null && thing != null) {
Channel channel = thing.getChannel(link.getLinkedUID());
if (channel != null) {
context = new ProfileContextImpl(link.getConfiguration(), item.getAcceptedDataTypes(),
item.getAcceptedCommandTypes(), acceptedCommandTypeMap.getOrDefault(
context = new ProfileContextImpl(link, item.getAcceptedDataTypes(), item.getAcceptedCommandTypes(),
acceptedCommandTypeMap.getOrDefault(
Objects.requireNonNullElse(channel.getAcceptedItemType(), ""), List.of()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.link.ItemChannelLink;
import org.openhab.core.thing.profiles.ProfileContext;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
Expand All @@ -32,28 +32,24 @@
public class ProfileContextImpl implements ProfileContext {

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

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

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

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

@Override
public Configuration getConfiguration() {
return configuration;
public ItemChannelLink getLink() {
return link;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

Expand All @@ -30,13 +31,21 @@
*/
@NonNullByDefault
public interface ProfileContext {
/**
* Get the link between the item and the thing that this profile is applied to.
*
* @return the link
*/
ItemChannelLink getLink();

/**
* Get the profile's configuration object
* Get the profile's configuration object.
*
* @return the configuration
*/
Configuration getConfiguration();
default Configuration getConfiguration() {
return getLink().getConfiguration();
}

/**
* Get a scheduler to be used within profiles (if needed at all)
Expand Down

0 comments on commit e8f3d3b

Please sign in to comment.