2 * Copyright (c) 2010-2020 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.*;
28 import org.openhab.core.thing.type.ChannelType;
29 import org.openhab.core.thing.type.ChannelTypeUID;
30 import org.osgi.service.component.annotations.Component;
33 * The {@link GPSTrackerProfileFactory} class defines and provides switch profile and its type of this binding.
35 * @author Gabor Bicskei - Initial contribution
39 public class GPSTrackerProfileFactory implements ProfileFactory, ProfileAdvisor, ProfileTypeProvider {
41 * Profile UID for trigger events
43 static final ProfileTypeUID UID_TRIGGER_SWITCH = new ProfileTypeUID(GPSTrackerBindingConstants.BINDING_ID,
47 * Profile type for trigger events
49 private static final TriggerProfileType TRIGGER_SWITCH_TYPE = ProfileTypeBuilder
50 .newTrigger(UID_TRIGGER_SWITCH, "Geofence").withSupportedItemTypes(CoreItemFactory.SWITCH)
51 .withSupportedChannelTypeUIDs(CHANNEL_TYPE_REGION).build();
54 public Collection<ProfileTypeUID> getSupportedProfileTypeUIDs() {
55 return Stream.of(UID_TRIGGER_SWITCH).collect(Collectors.toSet());
59 public Collection<ProfileType> getProfileTypes(@Nullable Locale locale) {
60 return Stream.of(TRIGGER_SWITCH_TYPE).collect(Collectors.toSet());
64 public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(Channel channel, @Nullable String itemType) {
65 return getSuggestedProfileTypeUID(channel.getChannelTypeUID(), itemType);
69 public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) {
70 return getSuggestedProfileTypeUID(channelType.getUID(), itemType);
73 private @Nullable ProfileTypeUID getSuggestedProfileTypeUID(@Nullable ChannelTypeUID channelTypeUID,
74 @Nullable String itemType) {
75 if (CoreItemFactory.SWITCH.equals(itemType) && CHANNEL_TYPE_REGION.equals(channelTypeUID)) {
76 return UID_TRIGGER_SWITCH;
82 public @Nullable Profile createProfile(ProfileTypeUID profileTypeUID, ProfileCallback callback,
83 ProfileContext profileContext) {
84 if (UID_TRIGGER_SWITCH.equals(profileTypeUID)) {
85 return new GPSTrackerTriggerSwitchProfile(callback, profileContext);