]> git.basschouten.com Git - openhab-addons.git/blob
9bdf9abb5b45119ae0374880a9af1efae2cd5d74
[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.harmonyhub.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.storage.StorageService;
17 import org.openhab.core.thing.ThingUID;
18 import org.openhab.core.thing.binding.AbstractStorageBasedTypeProvider;
19 import org.openhab.core.thing.type.ChannelType;
20 import org.openhab.core.thing.type.ChannelTypeProvider;
21 import org.osgi.service.component.annotations.Activate;
22 import org.osgi.service.component.annotations.Component;
23 import org.osgi.service.component.annotations.Reference;
24
25 /**
26  * The {@link HarmonyHubDynamicTypeProvider} is an instance of a {@link AbstractStorageBasedTypeProvider} for the
27  * HarmonyHub
28  * binding
29  *
30  * @author Jan N. Klug - Initial contribution
31  */
32 @Component(service = { HarmonyHubDynamicTypeProvider.class, ChannelTypeProvider.class })
33 @NonNullByDefault
34 public class HarmonyHubDynamicTypeProvider extends AbstractStorageBasedTypeProvider {
35
36     @Activate
37     public HarmonyHubDynamicTypeProvider(@Reference StorageService storageService) {
38         super(storageService);
39     }
40
41     public void removeChannelTypesForThing(ThingUID uid) {
42         String thingUid = uid.getAsString() + ":";
43         getChannelTypes(null).stream().map(ChannelType::getUID).filter(c -> c.getAsString().startsWith(thingUid))
44                 .forEach(this::removeChannelType);
45     }
46 }