]> git.basschouten.com Git - openhab-addons.git/blob
4d67ec3f55e06e072bcd0511fc5c2cac0d727a74
[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.automation.pwm.internal.type;
14
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Locale;
18 import java.util.Map;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.automation.pwm.internal.handler.PWMTriggerHandler;
23 import org.openhab.core.automation.type.ModuleType;
24 import org.openhab.core.automation.type.ModuleTypeProvider;
25 import org.openhab.core.common.registry.ProviderChangeListener;
26 import org.osgi.service.component.annotations.Component;
27
28 /**
29  * Provides the module types for the rules engine.
30  *
31  * @author Fabian Wolter - Initial Contribution
32  */
33 @Component
34 @NonNullByDefault
35 public class PWMModuleTypeProvider implements ModuleTypeProvider {
36     private static final Map<String, ModuleType> PROVIDED_MODULE_TYPES = Map.of(PWMTriggerHandler.MODULE_TYPE_ID,
37             PWMTriggerType.initialize());
38
39     @SuppressWarnings("unchecked")
40     @Override
41     public <T extends ModuleType> T getModuleType(@Nullable String UID, @Nullable Locale locale) {
42         return (T) PROVIDED_MODULE_TYPES.get(UID);
43     }
44
45     @SuppressWarnings("unchecked")
46     @Override
47     public <T extends ModuleType> Collection<T> getModuleTypes(@Nullable Locale locale) {
48         return (Collection<T>) PROVIDED_MODULE_TYPES.values();
49     }
50
51     @Override
52     public void addProviderChangeListener(ProviderChangeListener<ModuleType> listener) {
53         // does nothing because this provider does not change
54     }
55
56     @Override
57     public Collection<ModuleType> getAll() {
58         return Collections.unmodifiableCollection(PROVIDED_MODULE_TYPES.values());
59     }
60
61     @Override
62     public void removeProviderChangeListener(ProviderChangeListener<ModuleType> listener) {
63         // does nothing because this provider does not change
64     }
65 }