2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.enocean.internal.profiles;
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
16 import static org.openhab.binding.enocean.internal.profiles.EnOceanProfiles.*;
18 import java.util.Collection;
19 import java.util.Collections;
20 import java.util.Locale;
22 import java.util.stream.Collectors;
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.openhab.core.library.CoreItemFactory;
27 import org.openhab.core.thing.Channel;
28 import org.openhab.core.thing.profiles.Profile;
29 import org.openhab.core.thing.profiles.ProfileAdvisor;
30 import org.openhab.core.thing.profiles.ProfileCallback;
31 import org.openhab.core.thing.profiles.ProfileContext;
32 import org.openhab.core.thing.profiles.ProfileFactory;
33 import org.openhab.core.thing.profiles.ProfileType;
34 import org.openhab.core.thing.profiles.ProfileTypeProvider;
35 import org.openhab.core.thing.profiles.ProfileTypeUID;
36 import org.openhab.core.thing.type.ChannelType;
37 import org.openhab.core.thing.type.ChannelTypeRegistry;
38 import org.osgi.service.component.annotations.Activate;
39 import org.osgi.service.component.annotations.Component;
40 import org.osgi.service.component.annotations.Reference;
43 * The {@link EnOceanProfileFactory} class creates EnOceanProfiles
45 * @author Daniel Weber - Initial contribution
49 public class EnOceanProfileFactory implements ProfileFactory, ProfileAdvisor, ProfileTypeProvider {
51 private static final Set<ProfileType> SUPPORTED_PROFILE_TYPES = Set.of(ROCKERSWITCHACTION_TOGGLE_SWITCH_TYPE,
52 ROCKERSWITCHACTION_TOGGLE_PLAYER_TYPE);
54 private static final Set<ProfileTypeUID> SUPPORTED_PROFILE_TYPE_UIDS = Set.of(ROCKERSWITCHACTION_TOGGLE_SWITCH,
55 ROCKERSWITCHACTION_TOGGLE_PLAYER);
57 private final ChannelTypeRegistry channelTypeRegistry;
60 public EnOceanProfileFactory(final @Reference ChannelTypeRegistry channelTypeRegistry) {
61 this.channelTypeRegistry = channelTypeRegistry;
65 public Collection<ProfileType> getProfileTypes(@Nullable Locale locale) {
66 return Collections.unmodifiableList(SUPPORTED_PROFILE_TYPES.stream().collect(Collectors.toList()));
70 public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(Channel channel, @Nullable String itemType) {
71 ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
72 if (channelType == null) {
76 return getSuggestedProfileTypeUID(channelType, itemType);
80 public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) {
82 if (CHANNELTYPE_ROCKERSWITCH_ACTION_UID.equals(channelType.getUID())) {
83 if (CoreItemFactory.PLAYER.equalsIgnoreCase(itemType)) {
84 return ROCKERSWITCHACTION_TOGGLE_PLAYER;
85 } else if (CoreItemFactory.SWITCH.equalsIgnoreCase(itemType)) {
86 return ROCKERSWITCHACTION_TOGGLE_SWITCH;
94 public @Nullable Profile createProfile(ProfileTypeUID profileTypeUID, ProfileCallback callback,
95 ProfileContext profileContext) {
96 if (ROCKERSWITCHACTION_TOGGLE_PLAYER.equals(profileTypeUID)) {
97 return new RockerSwitchActionTogglePlayerProfile(callback, profileContext);
98 } else if (ROCKERSWITCHACTION_TOGGLE_SWITCH.equals(profileTypeUID)) {
99 return new RockerSwitchActionToggleSwitchProfile(callback, profileContext);
106 public Collection<ProfileTypeUID> getSupportedProfileTypeUIDs() {
107 return Collections.unmodifiableList(SUPPORTED_PROFILE_TYPE_UIDS.stream().collect(Collectors.toList()));