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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.gpstracker.internal.config.ConfigHelper;
17 import org.openhab.core.library.types.OnOffType;
18 import org.openhab.core.thing.profiles.ProfileCallback;
19 import org.openhab.core.thing.profiles.ProfileContext;
20 import org.openhab.core.thing.profiles.ProfileTypeUID;
21 import org.openhab.core.thing.profiles.TriggerProfile;
22 import org.openhab.core.types.State;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * The {@link GPSTrackerTriggerSwitchProfile} class implements the behavior when being linked to a Switch item.
29 * @author Gabor Bicskei - Initial contribution
32 public class GPSTrackerTriggerSwitchProfile implements TriggerProfile {
36 private final Logger logger = LoggerFactory.getLogger(GPSTrackerTriggerSwitchProfile.class);
41 private ProfileCallback callback;
46 private String regionName;
51 * @param callback Callback
52 * @param context Context
54 GPSTrackerTriggerSwitchProfile(ProfileCallback callback, ProfileContext context) {
55 this.callback = callback;
56 this.regionName = ConfigHelper.getRegionName(context.getConfiguration());
57 logger.debug("Trigger switch profile created for region {}", regionName);
61 public ProfileTypeUID getProfileTypeUID() {
62 return GPSTrackerProfileFactory.UID_TRIGGER_SWITCH;
66 public void onStateUpdateFromItem(State state) {
70 public void onTriggerFromHandler(String payload) {
71 if (payload.startsWith(regionName)) {
72 OnOffType state = OnOffType.from(payload.endsWith("enter"));
73 callback.sendCommand(state);
74 logger.debug("Transition trigger {} handled for region {} by profile: {}", payload, regionName, state);