]> git.basschouten.com Git - openhab-addons.git/blob
c1c2eb330191e479288e151572eac3e24d45cc7a
[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.guntamatic.internal;
14
15 import java.util.Collection;
16 import java.util.Locale;
17 import java.util.Map;
18 import java.util.concurrent.ConcurrentHashMap;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.core.thing.type.ChannelType;
23 import org.openhab.core.thing.type.ChannelTypeBuilder;
24 import org.openhab.core.thing.type.ChannelTypeProvider;
25 import org.openhab.core.thing.type.ChannelTypeUID;
26 import org.openhab.core.thing.type.StateChannelTypeBuilder;
27 import org.openhab.core.types.StateDescriptionFragmentBuilder;
28 import org.osgi.service.component.annotations.Component;
29
30 /**
31  * Provide channelTypes for Guntamatic Heating Systems
32  *
33  * @author Weger Michael - Initial contribution
34  */
35 @Component(service = { ChannelTypeProvider.class, GuntamaticChannelTypeProvider.class })
36 @NonNullByDefault
37 public class GuntamaticChannelTypeProvider implements ChannelTypeProvider {
38     private final Map<String, ChannelType> channelTypes = new ConcurrentHashMap<>();
39
40     @Override
41     public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
42         return channelTypes.values();
43     }
44
45     @Override
46     public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
47         return channelTypes.get(channelTypeUID.getAsString()); // returns null if not found
48     }
49
50     public void addChannelType(ChannelTypeUID channelTypeUID, String label, String itemType, String description,
51             boolean advanced, String pattern) {
52         StateDescriptionFragmentBuilder stateDescriptionFragmentBuilder = StateDescriptionFragmentBuilder.create()
53                 .withReadOnly(true);
54         if (!pattern.isEmpty()) {
55             stateDescriptionFragmentBuilder.withPattern(pattern);
56         }
57         StateChannelTypeBuilder stateChannelTypeBuilder = ChannelTypeBuilder.state(channelTypeUID, label, itemType)
58                 .withDescription(description).isAdvanced(advanced)
59                 .withStateDescriptionFragment(stateDescriptionFragmentBuilder.build());
60         channelTypes.put(channelTypeUID.getAsString(), stateChannelTypeBuilder.build());
61     }
62 }