2 * Copyright (c) 2010-2022 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.netatmo.internal.providers;
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.BINDING_ID;
17 import java.util.Collection;
18 import java.util.Collections;
19 import java.util.HashSet;
20 import java.util.Locale;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
25 import org.openhab.core.thing.type.ChannelType;
26 import org.openhab.core.thing.type.ChannelTypeBuilder;
27 import org.openhab.core.thing.type.ChannelTypeProvider;
28 import org.openhab.core.thing.type.ChannelTypeUID;
29 import org.openhab.core.thing.type.StateChannelTypeBuilder;
30 import org.osgi.service.component.annotations.Component;
33 * Extends the ChannelTypeProvider generating Channel Types based on {@link MeasureClass} enum.
35 * @author Gaƫl L'hopital - Initial contribution
39 @Component(service = { NetatmoChannelTypeProvider.class, ChannelTypeProvider.class })
40 public class NetatmoChannelTypeProvider implements ChannelTypeProvider {
41 private final Collection<ChannelType> channelTypes = new HashSet<>();
43 public NetatmoChannelTypeProvider() {
44 MeasureClass.AS_SET.forEach(mc -> mc.channels.forEach((measureChannel, channelDetails) -> {
45 StateChannelTypeBuilder channelTypeBuilder = ChannelTypeBuilder
46 .state(new ChannelTypeUID(BINDING_ID, measureChannel), measureChannel.replace("-", " "),
47 channelDetails.itemType)
48 .withStateDescriptionFragment(channelDetails.stateDescriptionFragment)
49 .withConfigDescriptionURI(channelDetails.configURI);
51 channelTypes.add(channelTypeBuilder.build());
56 public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
57 return Collections.unmodifiableCollection(channelTypes);
61 public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) {
62 return channelTypes.stream().filter(ct -> ct.getUID().equals(channelTypeUID)).findFirst().orElse(null);