2 * Copyright (c) 2010-2024 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.networkupstools.internal;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.Locale;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.thing.binding.ThingHandler;
24 import org.openhab.core.thing.binding.ThingHandlerService;
25 import org.openhab.core.thing.type.ChannelType;
26 import org.openhab.core.thing.type.ChannelTypeProvider;
27 import org.openhab.core.thing.type.ChannelTypeUID;
30 * Provider class to provide channel types for user configured channels.
32 * @author Hilbrand Bouwkamp - Initial contribution
35 public class NUTChannelTypeProvider implements ChannelTypeProvider, ThingHandlerService {
37 private final Map<ChannelTypeUID, ChannelType> map = new HashMap<>();
38 private @Nullable ThingHandler handler;
41 public Collection<ChannelType> getChannelTypes(@Nullable final Locale locale) {
42 return Collections.unmodifiableCollection(map.values());
46 public @Nullable ChannelType getChannelType(final ChannelTypeUID channelTypeUID, @Nullable final Locale locale) {
47 return map.get(channelTypeUID);
51 * Add a channel type for a user configured channel.
53 * @param channelType channelType
55 public void addChannelType(final ChannelType channelType) {
56 map.put(channelType.getUID(), channelType);
60 public void setThingHandler(@Nullable final ThingHandler handler) {
61 if (handler instanceof NUTHandler nutHandler) {
62 this.handler = handler;
63 nutHandler.setChannelTypeProvider(this);
68 public @Nullable ThingHandler getThingHandler() {