]> git.basschouten.com Git - openhab-addons.git/blob
64714f5b035c0d2add8e9382539b60dacd70d63c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.transform.map.internal.profiles;
14
15 import java.util.Collection;
16 import java.util.List;
17 import java.util.Locale;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.thing.profiles.Profile;
22 import org.openhab.core.thing.profiles.ProfileCallback;
23 import org.openhab.core.thing.profiles.ProfileContext;
24 import org.openhab.core.thing.profiles.ProfileFactory;
25 import org.openhab.core.thing.profiles.ProfileType;
26 import org.openhab.core.thing.profiles.ProfileTypeBuilder;
27 import org.openhab.core.thing.profiles.ProfileTypeProvider;
28 import org.openhab.core.thing.profiles.ProfileTypeUID;
29 import org.openhab.core.transform.TransformationService;
30 import org.openhab.transform.map.internal.MapTransformationService;
31 import org.osgi.service.component.annotations.Component;
32 import org.osgi.service.component.annotations.Reference;
33
34 /**
35  * {@link ProfileFactory} that creates the transformation profile for the {@link MapTransformationService}.
36  *
37  * @author Stefan Triller - Initial contribution
38  */
39 @NonNullByDefault
40 @Component(service = { ProfileFactory.class, ProfileTypeProvider.class })
41 public class MapTransformationProfileFactory implements ProfileFactory, ProfileTypeProvider {
42
43     @NonNullByDefault({})
44     private TransformationService service;
45
46     @Override
47     public Collection<ProfileType> getProfileTypes(@Nullable Locale locale) {
48         return List.of(ProfileTypeBuilder
49                 .newState(MapTransformationProfile.PROFILE_TYPE_UID, MapTransformationProfile.PROFILE_TYPE_UID.getId())
50                 .build());
51     }
52
53     @Override
54     public @Nullable Profile createProfile(ProfileTypeUID profileTypeUID, ProfileCallback callback,
55             ProfileContext profileContext) {
56         return new MapTransformationProfile(callback, profileContext, service);
57     }
58
59     @Override
60     public Collection<ProfileTypeUID> getSupportedProfileTypeUIDs() {
61         return List.of(MapTransformationProfile.PROFILE_TYPE_UID);
62     }
63
64     @Reference(target = "(openhab.transform=MAP)")
65     public void addTransformationService(TransformationService service) {
66         this.service = service;
67     }
68
69     public void removeTransformationService(TransformationService service) {
70         this.service = null;
71     }
72 }