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.guntamatic.internal;
15 import java.util.Collection;
16 import java.util.Locale;
18 import java.util.concurrent.ConcurrentHashMap;
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;
31 * Provide channelTypes for Guntamatic Heating Systems
33 * @author Weger Michael - Initial contribution
35 @Component(service = { ChannelTypeProvider.class, GuntamaticChannelTypeProvider.class })
37 public class GuntamaticChannelTypeProvider implements ChannelTypeProvider {
38 private final Map<String, ChannelType> channelTypes = new ConcurrentHashMap<>();
41 public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
42 return channelTypes.values();
46 public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
47 return channelTypes.get(channelTypeUID.getAsString()); // returns null if not found
50 public void addChannelType(ChannelTypeUID channelTypeUID, String label, String itemType, String description,
51 boolean advanced, String pattern) {
52 StateDescriptionFragmentBuilder stateDescriptionFragmentBuilder = StateDescriptionFragmentBuilder.create()
54 if (!pattern.isEmpty()) {
55 stateDescriptionFragmentBuilder.withPattern(pattern);
57 StateChannelTypeBuilder stateChannelTypeBuilder = ChannelTypeBuilder.state(channelTypeUID, label, itemType)
58 .withDescription(description).isAdvanced(advanced)
59 .withStateDescriptionFragment(stateDescriptionFragmentBuilder.build());
60 channelTypes.put(channelTypeUID.getAsString(), stateChannelTypeBuilder.build());