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.gpstracker.internal.profile;
15 import static org.openhab.binding.gpstracker.internal.GPSTrackerBindingConstants.CHANNEL_TYPE_REGION;
17 import java.util.Collection;
18 import java.util.Locale;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.binding.gpstracker.internal.GPSTrackerBindingConstants;
25 import org.openhab.core.library.CoreItemFactory;
26 import org.openhab.core.thing.Channel;
27 import org.openhab.core.thing.profiles.Profile;
28 import org.openhab.core.thing.profiles.ProfileAdvisor;
29 import org.openhab.core.thing.profiles.ProfileCallback;
30 import org.openhab.core.thing.profiles.ProfileContext;
31 import org.openhab.core.thing.profiles.ProfileFactory;
32 import org.openhab.core.thing.profiles.ProfileType;
33 import org.openhab.core.thing.profiles.ProfileTypeBuilder;
34 import org.openhab.core.thing.profiles.ProfileTypeProvider;
35 import org.openhab.core.thing.profiles.ProfileTypeUID;
36 import org.openhab.core.thing.profiles.TriggerProfileType;
37 import org.openhab.core.thing.type.ChannelType;
38 import org.openhab.core.thing.type.ChannelTypeUID;
39 import org.osgi.service.component.annotations.Component;
42 * The {@link GPSTrackerProfileFactory} class defines and provides switch profile and its type of this binding.
44 * @author Gabor Bicskei - Initial contribution
48 public class GPSTrackerProfileFactory implements ProfileFactory, ProfileAdvisor, ProfileTypeProvider {
50 * Profile UID for trigger events
52 static final ProfileTypeUID UID_TRIGGER_SWITCH = new ProfileTypeUID(GPSTrackerBindingConstants.BINDING_ID,
56 * Profile type for trigger events
58 private static final TriggerProfileType TRIGGER_SWITCH_TYPE = ProfileTypeBuilder
59 .newTrigger(UID_TRIGGER_SWITCH, "Geofence").withSupportedItemTypes(CoreItemFactory.SWITCH)
60 .withSupportedChannelTypeUIDs(CHANNEL_TYPE_REGION).build();
63 public Collection<ProfileTypeUID> getSupportedProfileTypeUIDs() {
64 return Stream.of(UID_TRIGGER_SWITCH).collect(Collectors.toSet());
68 public Collection<ProfileType> getProfileTypes(@Nullable Locale locale) {
69 return Stream.of(TRIGGER_SWITCH_TYPE).collect(Collectors.toSet());
73 public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(Channel channel, @Nullable String itemType) {
74 return getSuggestedProfileTypeUID(channel.getChannelTypeUID(), itemType);
78 public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) {
79 return getSuggestedProfileTypeUID(channelType.getUID(), itemType);
82 private @Nullable ProfileTypeUID getSuggestedProfileTypeUID(@Nullable ChannelTypeUID channelTypeUID,
83 @Nullable String itemType) {
84 if (CoreItemFactory.SWITCH.equals(itemType) && CHANNEL_TYPE_REGION.equals(channelTypeUID)) {
85 return UID_TRIGGER_SWITCH;
91 public @Nullable Profile createProfile(ProfileTypeUID profileTypeUID, ProfileCallback callback,
92 ProfileContext profileContext) {
93 if (UID_TRIGGER_SWITCH.equals(profileTypeUID)) {
94 return new GPSTrackerTriggerSwitchProfile(callback, profileContext);