]> git.basschouten.com Git - openhab-addons.git/blob
d519c18d650acc69b02ffe3af34538c7a54b62dc
[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.binding.lcn.internal;
14
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Locale;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
22 import org.openhab.core.library.CoreItemFactory;
23 import org.openhab.core.thing.profiles.Profile;
24 import org.openhab.core.thing.profiles.ProfileCallback;
25 import org.openhab.core.thing.profiles.ProfileContext;
26 import org.openhab.core.thing.profiles.ProfileFactory;
27 import org.openhab.core.thing.profiles.ProfileType;
28 import org.openhab.core.thing.profiles.ProfileTypeBuilder;
29 import org.openhab.core.thing.profiles.ProfileTypeProvider;
30 import org.openhab.core.thing.profiles.ProfileTypeUID;
31 import org.openhab.core.thing.type.ChannelTypeUID;
32 import org.osgi.service.component.annotations.Component;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * Factory to create Profile instances. Also provides the available ProfileTypes and gives advise which profile to use
38  * by a given link.
39  *
40  * @author Fabian Wolter - Initial Contribution
41  */
42 @NonNullByDefault
43 @Component(service = { ProfileFactory.class, ProfileTypeProvider.class })
44 public class LcnProfileFactory implements ProfileFactory, ProfileTypeProvider {
45     private final Logger logger = LoggerFactory.getLogger(LcnProfileFactory.class);
46
47     @Override
48     public Collection<ProfileTypeUID> getSupportedProfileTypeUIDs() {
49         return Collections.singleton(DimmerOutputProfile.UID);
50     }
51
52     @Override
53     public Collection<ProfileType> getProfileTypes(@Nullable Locale locale) {
54         return Collections.singleton(ProfileTypeBuilder.newState(DimmerOutputProfile.UID, "Dimmer Output (%)")
55                 .withSupportedItemTypes(CoreItemFactory.DIMMER, CoreItemFactory.COLOR)
56                 .withSupportedChannelTypeUIDs(
57                         new ChannelTypeUID(LcnBindingConstants.BINDING_ID, LcnChannelGroup.OUTPUT.name().toLowerCase()))
58                 .build());
59     }
60
61     @Override
62     public @Nullable Profile createProfile(ProfileTypeUID profileTypeUID, ProfileCallback callback,
63             ProfileContext profileContext) {
64         if (profileTypeUID.equals(DimmerOutputProfile.UID)) {
65             return new DimmerOutputProfile(callback, profileContext);
66         } else {
67             logger.warn("Could not create {}", profileTypeUID);
68             return null;
69         }
70     }
71 }